Example #1
0
 */
function readln()
{
    while (false !== ($line = fgets(STDIN))) {
        return $line;
    }
}
/* tratamento de argumentos
 * l, lang    language
 * f, first   baixa o primeiro link
 */
$options = getopt('l:fd', array('first', 'lang::', 'logged::'));
$search = implode(' ', array_slice($argv, sizeof($options) + 1));
/* Começa a treta :D */
try {
    $legendastv = new LegendasTv();
    if (!isset($options['logged'])) {
        $legendastv->login('samirfor', '980244');
    }
    $subtitles = $legendastv->search($search, @$options['l'] ?: (@$options['lang'] ?: 'Qualquer idioma'));
    // var_dump($subtitles);
    // exit;
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
    exit(1);
}
if (array_key_exists('d', $options)) {
    # caso flag "d" esteja ativada retorna apenas os destaques
    $subtitles = array_filter($subtitles, function ($subtitle) {
        return $subtitle->destaque;
    });
    $subtitles = $legendastv->search($termoBusca, 'Português-BR');
    // destaque tem preferência
    usort($subtitles, function ($a, $b) {
        if ($a->destaque and !$b->destaque) {
            return -1;
        }
        if ($b->destaque and !$a->destaque) {
            return 1;
        }
        return $a->downloads > $b->downloads ? -1 : 1;
    });
    return $subtitles;
}
/* Começa a treta :D */
try {
    $legendastv = new LegendasTv();
    $legendastv->login('samirfor', '980244');
    $files = scandir(TORRENTDIR);
    foreach ($files as $file) {
        if (is_dir(TORRENTDIR . '/' . $file) || preg_match("/\\.br\\..{3}\$/", $file)) {
            // echo "Ignorado $file\n";
            continue;
        }
        if (preg_match('/\\.(avi|mp4|mkv)/', $file, $s)) {
            $file = basename($file, $s[0]);
            // substitui pontos e traços por espaços
            $termoBusca = preg_replace('/[\\.|-|_]/', ' ', $file);
            preg_match('/^.+S\\d+E\\d+/i', $termoBusca, $resultadoBusca);
            if (isset($resultadoBusca[0])) {
                $termoBusca = $resultadoBusca[0];
            } else {