/
rss_dl.php
executable file
·121 lines (106 loc) · 3.69 KB
/
rss_dl.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
113
114
115
116
117
118
119
120
121
#!/usr/bin/php-cgi -q
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// rss_dl.php
// This program is a command line interface to torrentwatch
//
ini_set('include_path', '.:'.dirname(__FILE__).'/web/php');
ini_set("precision", 4);
// These are our extra functions
require_once('rss_dl_utils.php');
$config_values;
$test_run = 0;
$verbosity = 0;
$func_timer = 0;
function usage() {
_debug( __FILE__ . "<options> - CLI Interface to Torrent Watch\n",0);
_debug( " -c <dir> : Enable Cache\n",0);
_debug( " -C : Disable Cache\n",0);
_debug( " -d : skip watch folder\n",0);
_debug( " -D : Start torrents in watch folder\n",0);
_debug( " -h : show this help\n",0);
_debug( " -nv: not verbose (default)\n",0);
_debug( " -q : quiet (no output)\n",0);
_debug( " -v : verbose output\n",0);
_debug( " -vv: verbose output(even more)\n",0);
_debug( " Note: This interface only writes to the config file when using the -i option\n",0);
}
function parse_args() {
global $config_values, $argc, $argv, $test_run, $verbosity;
for($i=1;$i<$argc;$i++) {
switch( $_SERVER['argv'][$i]) {
case '-c':
$i++;
$config_values['Settings']['Cache Dir'] = $_SERVER['argv'][$i];
break;
case '-C':
unset($config_values['Settings']['Cache Dir']);
break;
case '-d':
$config_values['Settings']['Run Torrentwatch'] = 0;
break;
case '-D':
$config_values['Settings']['Run Torrentwatch'] = 1;
break;
case '-h':
usage();
exit(1);
case '-nv':
$verbosity = 0;
break;
case '-q':
$verbosity = -1;
break;
case '-t':
$test_run = 1;
break;
case '-v':
$verbosity = 1;
break;
case '-vv':
$verbosity = 2;
break;
default:
_debug("Unknown command line argument: " . $_SERVER['argv'][$i] . "\n",0);
break;
}
}
}
//
// Begin Main Function
//
//
$main_timer = timer_init();
if(file_exists(platform_getConfigFile()))
read_config_file();
else
setup_default_config();
if(isset($config_values['Settings']['Verbose']))
$verbosity = $config_values['Settings']['Verbose'];
parse_args();
_debug(date("F j, Y, g:i a")."\n",0);
if(isset($config_values['Feeds'])) {
load_feeds($config_values['Feeds'], 1);
feeds_perform_matching($config_values['Feeds']);
}
if(_isset($config_values['Settings'], 'Run Torrentwatch', FALSE) and !$test_run and $config_values['Settings']['Watch Dir']) {
global $hit;
$hit = 0;
foreach($config_values['Favorites'] as $fav) {
$guess = guess_match(html_entity_decode($_GET['title']));
$name = trim(strtr($guess['key'], "._", " "));
if($name == $fav['Name']) {
$downloadDir = $fav['Save In'];
}
}
if(!$downloadDir || $downloadDir == "Default" ) $downloadDir = $config_values['Settings']['Download Dir'];
check_for_torrents($config_values['Settings']['Watch Dir'], $downloadDir);
if(!$hit)
_debug("No New Torrents to add from watch folder\n", 0);
} else {
_debug("Skipping Watch Folder\n");
}
unlink_temp_files();
_debug($func_timer."s\n",0);
_debug(timer_get_time($main_timer)."s\n",0);
?>