forked from allu77/TVScraper
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TVScraper.php
66 lines (50 loc) · 1.71 KB
/
TVScraper.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
<?php
require_once('config.php');
require_once('TVShowScraperDB.php');
function sortByPubDate($a, $b) { return $b['pubDate'] - $a['pubDate']; }
$log_file = LOG_DIR . '/index.log';
$log_level = LOGGER_DEBUG;
$logger = new Logger($log_file, $log_level);
$logger->log("------ START -----");
ob_start();
var_dump($_POST);
$d = ob_get_clean();
$logger->log($d);
$fp = fopen(LIB_FILE, 'r');
flock($fp, LOCK_EX);
$tv = new TVShowScraperDB(LIB_FILE);
$tv->setLogger($logger);
$shows = array();
if (isset($_GET['action']) && $_GET['action'] == 'latest') {
/*
$res = Array();
$seasons = $tv->getAllWatchedSeasons();
foreach ($seasons as $season) {
$files = $tv->getBestFilesForSeason($season['id']);
foreach ($files as $file) {
if (isset($_GET['laterthan']) && $file['pubDate'] <= $_GET['laterthan']) continue;
if (!(isset($_GET['torrent']) && $_GET['torrent'] == 1) && isset($file['type']) && $file['type'] == 'torrent') continue;
if (!(isset($_GET['ed2k']) && $_GET['ed2k'] == 1) && (!isset($file['type']) || $file['type'] == 'ed2k')) continue;
$res[] = $file;
}
}
*/
$res = Array();
$files = $tv->getAllWatchedBestFiles();
foreach ($files as $file) {
if (isset($_GET['laterthan']) && $file['pubDate'] <= $_GET['laterthan']) continue;
if (!(isset($_GET['torrent']) && $_GET['torrent'] == 1) && isset($file['type']) && $file['type'] == 'torrent') continue;
if (!(isset($_GET['ed2k']) && $_GET['ed2k'] == 1) && (!isset($file['type']) || $file['type'] == 'ed2k')) continue;
$res[] = $file;
}
usort($res, sortByPubDate);
$resCount = 0;
foreach ($res as $r) {
if (isset($_GET['max']) && ++$resCount > $_GET['max']) break;
echo $r['uri'] . "\n";
}
}
$tv->save(LIB_FILE);
flock($fp, LOCK_UN);
fclose($fp);
?>