forked from allu77/TVScraper
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TVShowUtils.php
47 lines (41 loc) · 1.19 KB
/
TVShowUtils.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
function parseED2KURI($uri) {
$m = Array();
if (preg_match('/^ed2k:\/\/\|file\|([^\|]+)\|(\d+)\|([^\|]+)\|([^\|]*\|)*\/(.*\/)?$/', $uri, $m)) {
return Array(
'fileName' => $m[1],
'fileSize' => $m[2],
'hash' => $m[3]
);
} else {
return false;
}
}
function parseEpisodeFileName($fileName) {
$fileName = preg_replace('/%20/', ' ', $fileName);
$m = Array();
if (preg_match('/\b(\d+)x(\d+)\b/i', $fileName, $m) || preg_match('/\bs(\d+)e(\d+)\b/i', $fileName, $m)) {
$m[1] = preg_replace('/^0+/', '', $m[1]);
$m[2] = preg_replace('/^0+/', '', $m[2]);
return Array('season' => $m[1], 'episode' => $m[2]);
} else {
return false;
}
}
function checkResolution($requiredRes, $candidateRes) {
if ($requiredRes == 'any') return true;
$res = 0;
if (preg_match('/720p/', $candidateRes)) $res = 1;
else if (preg_match('/1080i/', $candidateRes)) $res = 2;
else if (preg_match('/1080p/', $candidateRes)) $res = 3;
switch ($requiredRes) {
case 'sd': return ($res == 0);
case '720p': return ($res == 1);
case '720p+': return ($res > 0);
case '1080i': return ($res == 2);
case '1080i+': return ($res > 1);
case '1080p': return ($res == 3);
default: return false;
}
}
?>