Пример #1
0
function show_torrent_html($item, $feed, $feedName, $alt, $torHash, $matched, $id)
{
    global $html_out, $test_run, $config_values;
    $guess = guess_match($item['title']);
    if ($config_values['Settings']['Episodes Only'] == 1 && ($guess['episode'] == 'noShow' || !$guess)) {
        return;
    }
    if (!$config_values['Settings']['Disable Hide List']) {
        if (isset($config_values['Hidden'][strtolower(trim(strtr($guess['key'], array(":" => "", "," => "", "'" => "", "." => " ", "_" => " "))))])) {
            return;
        }
    }
    if (($matched == "cachehit" || $matched == "downloaded" || $matched == "match") && $config_values['Settings']['Client'] != 'folder') {
        $torInfo['dlStatus'] = 'to_check';
        $torInfo['stats'] = 'Waiting for client data...';
        $torInfo['clientID'] = $torHash;
        if (isset($torInfo['dlStatus'])) {
            $matched = $torInfo['dlStatus'];
        }
    }
    // add word-breaking flags after each period
    $title = preg_replace('/\\./', '.­', $item['title']);
    // Copy feed cookies to item
    $ulink = get_torrent_link($item);
    if (($pos = strpos($feed, ':COOKIE:')) !== False) {
        $ulink .= substr($feed, $pos);
    }
    ob_start();
    require 'templates/feed_item.tpl';
    $html_out .= ob_get_contents();
    ob_end_clean();
}
Пример #2
0
function check_cache_episode($title)
{
    global $config_values, $matched;
    $guess = guess_match($title, TRUE);
    if ($guess == False) {
        _debug("Unable to guess for {$title}\n");
        return 1;
    }
    if ($handle = opendir($config_values['Settings']['Cache Dir'])) {
        while (false !== ($file = readdir($handle))) {
            if (!(substr($file, 0, 7) == "rss_dl_")) {
                continue;
            }
            if (!(preg_replace('/[. ]/', '_', substr($file, 7, strlen($guess['key']))) == preg_replace('/[. ]/', '_', $guess['key']))) {
                continue;
            }
            $cacheguess = guess_match(substr($file, 7), TRUE);
            if ($cacheguess != false && $guess['episode'] == $cacheguess['episode']) {
                _debug("Full Episode Match, ignoring " . $guess['episode'] . "\n", 2);
                $matched = "duplicate";
                return 0;
            }
        }
    } else {
        _debug("Unable to open Cache Directory: " . $config_values['Settings']['Cache Dir'] . "\n", -1);
    }
    return 1;
}
Пример #3
0
function check_for_torrent(&$item, $key, $opts)
{
    global $matched, $test_run, $config_values;
    if (!(strtolower($item['Feed']) == 'all' || $item['Feed'] === '' || $item['Feed'] == $opts['URL'])) {
        return;
    }
    $rs = $opts['Obj'];
    $title = strtolower($rs['title']);
    switch (_isset($config_values['Settings'], 'MatchStyle')) {
        case 'simple':
            $hit = $item['Filter'] != '' && strpos(strtr($title, " .", "__"), strtr(strtolower($item['Filter']), " .", "__")) === 0 && ($item['Not'] == '' or my_strpos($title, strtolower($item['Not'])) === FALSE) && ($item['Quality'] == 'All' or $item['Quality'] == '' or my_strpos($title, strtolower($item['Quality'])) !== FALSE);
            break;
        case 'glob':
            $hit = $item['Filter'] != '' && fnmatch(strtolower($item['Filter']), $title) && ($item['Not'] == '' or !fnmatch(strtolower($item['Not']), $title)) && ($item['Quality'] == 'All' or $item['Quality'] == '' or strpos($title, strtolower($item['Quality'])) !== FALSE);
            break;
        case 'regexp':
        default:
            $hit = $item['Filter'] != '' && preg_match('/\\b' . strtolower(str_replace(' ', '[\\s._]', $item['Filter'])) . '\\b/', $title) && ($item['Not'] == '' or !preg_match('/' . strtolower($item['Not']) . '/', $title)) && ($item['Quality'] == 'All' or $item['Quality'] == '' or preg_match('/' . strtolower($item['Quality']) . '/', $title));
            break;
    }
    if (strtolower($item['Filter']) == "any") {
        $hit = 1;
        $any = 1;
    }
    if ($hit) {
        $guess = guess_match($title, TRUE);
    }
    if ($hit && episode_filter($guess, $item['Episodes']) == true) {
        $matched = 'match';
        if (preg_match('/^\\d+p$/', $item['Episode'])) {
            $item['Episode'] = preg_replace('/^(\\d+)p/', '\\1', $item['Episode']);
            $PROPER = 1;
        }
        if (check_cache($rs['title'])) {
            if (!$any && _isset($config_values['Settings'], 'Only Newer') == 1) {
                if (!empty($guess['episode']) && preg_match('/^(\\d+)x(\\d+)p?$|^(\\d{8})p?$/i', $guess['episode'], $regs)) {
                    if (isset($regs[3]) && preg_match('/^(\\d{8})$/', $regs[3]) && $item['Episode'] >= $regs[3]) {
                        _debug($item['Name'] . ": " . $item['Episode'] . ' >= ' . $regs[3] . "\r\n", 1);
                        $matched = "old";
                        return FALSE;
                    } else {
                        if (isset($regs[1]) && preg_match('/^(\\d{1,3})$/', $regs[1]) && $item['Season'] > $regs[1]) {
                            _debug($item['Name'] . ": " . $item['Season'] . ' > ' . $regs[1] . "\r\n", 1);
                            $matched = "old";
                            return FALSE;
                        } else {
                            if (isset($regs[2]) && preg_match('/^(\\d{1,3})$/', $regs[1]) && $item['Season'] == $regs[1] && $item['Episode'] >= $regs[2]) {
                                if (!preg_match('/proper|repack|rerip/i', $rs['title'])) {
                                    _debug($item['Name'] . ": " . $item['Episode'] . ' >= ' . $regs[2] . "\r\n", 1);
                                    $matched = "old";
                                    return FALSE;
                                } else {
                                    if ($PROPER == 1) {
                                        _debug("Allready downloaded this Proper, Repack or Rerip of " . $item['Name'] . " {$regs['1']}x{$regs['2']}{$regs['3']}\r\n");
                                        $matched = "old";
                                        return FALSE;
                                    }
                                }
                            }
                        }
                    }
                } else {
                    if ($guess['episode'] == 'fullSeason') {
                        $matched = "season";
                        return FALSE;
                    } else {
                        if ($guess['episode'] != 'noShow' && !preg_match('/^(\\d{1,2} \\d{1,2} \\d{2,4})$/', $guess['episode']) || $config_values['Settings']['Require Episode Info'] == 1) {
                            _debug("{$item} is not in a workable format.");
                            $matched = "nomatch";
                            return FALSE;
                        }
                    }
                }
            }
            _debug('Match found for ' . $rs['title'] . "\n");
            if ($test_run) {
                $matched = 'test';
                return;
            }
            if ($link = get_torrent_link($rs)) {
                $response = client_add_torrent($link, NULL, $rs['title'], $opts['URL'], $item);
                if (preg_match('/^Error:/', $response)) {
                    _debug("Failed adding torrent {$link}\n", -1);
                    return FALSE;
                } else {
                    add_cache($rs['title']);
                }
            } else {
                _debug("Unable to find URL for " . $rs['title'] . "\n", -1);
                $matched = "nourl";
            }
        }
    }
}
Пример #4
0
function updateFavoriteEpisode(&$fav, $title)
{
    global $config_values;
    if (!($guess = guess_match($title, TRUE))) {
        return;
    }
    if (preg_match('/^((\\d+x)?\\d+)p$/', $guess['episode'])) {
        $guess['episode'] = preg_replace('/^((?:\\d+x)?\\d+)p$/', '\\1', $guess['episode']);
        $PROPER = "p";
    } else {
        $PROPER = '';
    }
    if (preg_match('/(^)(\\d{8})$/', $guess['episode'], $regs)) {
        $curEpisode = $regs[2];
        $expectedEpisode = $regs[2] + 1;
    } else {
        if (preg_match('/^(\\d+)x(\\d+)$/i', $guess['episode'], $regs)) {
            $curEpisode = preg_replace('/(\\d+)x/i', "", $guess['episode']);
            $curSeason = preg_replace('/x(\\d+)/i', "", $guess['episode']);
            $expectedEpisode = sprintf('%02d', $fav['Episode'] + 1);
        } else {
            return;
        }
    }
    if ($fav['Episode'] && $curEpisode > $expectedEpisode) {
        $show = $guess['key'];
        $episode = $guess['episode'];
        $expected = $curSeason . "x" . $expectedEpisode;
        $oldEpisode = $fav['Episode'];
        $oldSeason = $fav['Season'];
        $newEpisode = $curEpisode + 1;
        $newSeason = $curSeason + 1;
        $msg = "Matched \"{$show} {$episode}\" but expected \"{$expected}\".\n";
        $msg .= "This usualy means that a double episode is downloaded before this one.\n";
        $msg .= "But it could mean that you missed an episode or that \"{$episode}\" is a special episode.\n";
        $msg .= "If this is the case you need to reset the \"Last Downloaded Episode\" setting to \"{$oldSeason} x {$oldEpisode}\" in the Favorites menu.\n";
        $msg .= "If you don't, the next match wil be \"Season: {$curSeason} Episode: {$newEpisode}\" or \"Season {$newSeason} Episode: 1\".\n";
        $subject = "TorrentWatch-X: got {$show} {$episode}, expected {$expected}";
        MailNotify($msg, $subject);
        $msg = escapeshellarg($msg);
        run_script('error', $title, $msg);
    }
    if (!isset($fav['Season'], $fav['Episode']) || $regs[1] > $fav['Season']) {
        $fav['Season'] = $regs[1];
        $fav['Episode'] = $regs[2] . $PROPER;
    } else {
        if ($regs[1] == $fav['Season'] && $regs[2] > $fav['Episode']) {
            $fav['Episode'] = $regs[2] . $PROPER;
        } else {
            $fav['Episode'] .= $PROPER;
        }
    }
    write_config_file();
}
Пример #5
0
function show_info($title)
{
    //Remove soft hyphens
    $title = str_replace("­", "", $title);
    $episode_data = guess_match($title, true);
    if ($episode_data === false) {
        $isShow = false;
        $name = $title;
        $data = '';
    } else {
        if (preg_match('/\\d+x\\d+/', $episode_data['episode'])) {
            $epiInfo = 1;
        } else {
            $epiInfo = 0;
        }
        $isShow = $episode_data['episode'] == 'noShow' ? false : true;
        $name = $episode_data['key'];
        $data = $episode_data['data'];
    }
    $episode_num = $episode_data['episode'];
    $shows = TV_Shows::search($name);
    if (count($shows) == 1) {
        episode_info($shows[0], $episode_num, $isShow, $epiInfo);
    } else {
        if (count($shows) > 1) {
            episode_info($shows[0], $episode_num, $isShow, $epiInfo);
        } else {
            episode_info($shows[0], $episode_num, 0, 0);
        }
    }
}
Пример #6
0
function get_deep_dir($dest, $tor_name)
{
    global $config_values;
    switch ($config_values['Settings']['Deep Directories']) {
        case '0':
            break;
        case 'Title_Season':
            $guess = guess_match($tor_name, TRUE);
            if (isset($guess['key']) && isset($guess['episode'])) {
                if (preg_match('/^(\\d{1,3})x\\d+p?$/', $guess['episode'], $Season)) {
                    $dest = $dest . "/" . ucwords(strtolower($guess['key'])) . "/Season " . $Season[1];
                } else {
                    if (preg_match('/^(\\d{4})\\d{4}$/', $guess['episode'], $Year)) {
                        $dest = $dest . "/" . ucwords(strtolower($guess['key'])) . "/" . $Year[1];
                    } else {
                        $dest = $dest . "/" . ucwords(strtolower($guess['key']));
                    }
                }
                break;
            }
            _debug("Deep Directories: Couldn't match {$tor_name} Reverting to Full\n", 1);
        case 'Title':
            $guess = guess_match($tor_name, TRUE);
            if (isset($guess['key'])) {
                $dest = $dest . "/" . ucwords(strtolower($guess['key']));
                break;
            }
            _debug("Deep Directories: Couldn't match {$tor_name} Reverting to Full\n", 1);
        case 'Full':
        default:
            $dest = $dest . "/" . ucwords(strtolower($tor_name));
            break;
    }
    return $dest;
}
Пример #7
0
    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");
}