forked from allu77/TVScraper
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TVShowScraperTXT.php
112 lines (79 loc) · 3.35 KB
/
TVShowScraperTXT.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
require_once('Logger.php');
require_once('SimpleBrowser.php');
require_once('TVShowScraper.php');
require_once('TVShowUtils.php');
class TVShowScraperTXT extends TVShowScraper {
public function runScraperTVShow($scraper, $showOnlyNew = false, $saveResults = false) {
$res = array();
$uri = $scraper['uri'];
$this->log("Parsing TXT $uri");
$browser = new SimpleBrowser();
$browser->setLogger($this->logger);
$page = $browser->get($uri);
$showData = $this->tvdb->getTVShow($scraper['tvshow']);
$showTitle = strtolower($showData['title']);
$showTitle = preg_replace('/\s+/', '\s+', $showTitle);
$showTitle = preg_replace('/[!\?\.\']/', '', $showTitle);
$showAlt = isset($showData['alternateTitle']) ? strtolower($showData['alternateTitle']) : '';
$showAlt = preg_replace('/\s+/', '\s+', $showAlt);
$showAlt = preg_replace('/[!\?\.\']/', '', $showAlt);
$this->log("Looking for $showTitle or $showAlt");
$rows = preg_split('/\n\r?/', $page, -1, PREG_SPLIT_NO_EMPTY);
foreach ($rows as $r) {
$this->log("Evaluating $r");
$uriData = parseED2KURI($r);
if ($uriData === FALSE) {
$this->log("Can't guess episode filename, skipping...");
} else {
$fileData = parseEpisodeFileName($uriData['fileName']);
$fileNameClean = preg_replace('/([\.\-_]|%20)/', ' ', $uriData['fileName']);
if ($fileData === FALSE) {
$this->log("Can't guess episode season, skipping...");
} else if (preg_match("/$showTitle/i", $fileNameClean) || (strlen($showAlt) > 0 && preg_match("/$showAlt/i", $fileNameClean))) {
$n = $fileData['season'];
$this->log("Adding as candidate for season $n...");
$res[] = array(
'n' => $n,
'uri' => $uri
);
}
}
}
return $this->submitSeasonCandidates($scraper, $res, $showOnlyNew, $saveResults);
}
public function runScraperSeason($scraper, $showOnlyNew = false, $saveResults = false) {
$seasonData = $this->tvdb->getSeason($scraper['season']);
$showData = $this->tvdb->getTVShow($seasonData['tvshow']);
$uri = $scraper['uri'];
$this->log("Parsing TXT $uri");
$browser = new SimpleBrowser();
$browser->setLogger($this->logger);
$page = $browser->get($uri);
$showTitle = strtolower($showData['title']);
$showTitle = preg_replace('/\s+/', '\s+', $showTitle);
$showTitle = preg_replace('/[!\?\.\']/', '', $showTitle);
$showAlt = isset($showData['alternateTitle']) ? strtolower($showData['alternateTitle']) : '';
$showAlt = preg_replace('/\s+/', '\s+', $showAlt);
$showAlt = preg_replace('/[!\?\.\']/', '', $showAlt);
$this->log("Looking for $showTitle or $showAlt");
$candidates = array();
$rows = preg_split('/\n\r?/', $page, -1, PREG_SPLIT_NO_EMPTY);
$candidates = array();
$t = time();
for ($j = 0; $j < sizeof($rows); $j++) {
$uriData = parseED2KURI($rows[$j]);
if ($uriData === FALSE) {
$this->log("Can't guess episode filename, skipping...");
} else {
$fileData = parseEpisodeFileName($uriData['fileName']);
$fileNameClean = preg_replace('/([\.\-_]|%20)/', ' ', $uriData['fileName']);
if (preg_match("/$showTitle/i", $fileNameClean) || (strlen($showAlt) > 0 && preg_match("/$showAlt/i", $fileNameClean))) {
$candidates[] = array('link' => $rows[$j], 'pubDate' => $t);
}
}
}
return $this->submitEpisodeCandidates($scraper, $candidates, $showOnlyNew, $saveResults);
}
}
?>