}
}
if (DEBUG) {
    print_r($downloadList);
}
// Download all files inthat download list
$messages = $files = array();
$lines = file($config['history_file'], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if ($downloadList) {
    foreach ($downloadList as $d) {
        $entry = $d[0] == $d[2] ? $d[0] : $d[0] . " " . $d[2];
        // Check if we already have this file on our download list
        // Also if proper is found, bypass the check and still download it
        $download = isNewestFile($d[0], $d[2], $lines) || in_array($entry, $lines) || in_array($entry, $files) || preg_match("/proper/is", $d[1]) ? false : true;
        if ($download && !DEBUG) {
            if (downloadTorrent($d[1])) {
                $history = fopen($config['history_file'], 'a');
                $messages[$entry] = "[" . $d[3] . "] {$entry}";
                $files[] = $entry;
                fwrite($history, $entry . "\n");
                fclose($history);
            }
        }
    }
}
if (count($messages) > 0) {
    $subject = 'Auto Downloads';
    if (isset($config['mail_method']) && $config['mail_method'] == 'phpmail') {
        mail($config['email'], $subject, implode("\n", $messages));
    } else {
        system('echo "' . implode("\n", $messages) . '" | nail -s "' . $subject . '" ' . $config['email']);
예제 #2
0
/**
 * Process feeds
 *
 * @param array $feeds List of feeds to process
 * @param array $config Configuration array
 * @return array Processing stats
 */
function processFeeds($feeds, $config)
{
    $result = array();
    $shows = getShows($config);
    $excludes = getExcludes($config);
    foreach ($feeds as $feed) {
        $feedItems = getFeedItems($feed);
        $cleanItems = cleanFeedItems($feedItems, $shows, $excludes);
        $history = getHistory($config);
        foreach ($cleanItems as $d) {
            $entry = $d['show'] . " " . $d['episode'];
            if (!in_array($entry, $history)) {
                downloadTorrent($d['url'], $config);
                $history[] = $entry;
                $result[$feed][] = $entry;
            }
        }
        saveHistory($history, $config);
    }
    return $result;
}