Esempio n. 1
0
         //create a SimpleXML object
         $xml = simplexml_load_file($config['xml_tv']);
         //find index to remove
         $i = 0;
         foreach ($xml->show as $show) {
             if ($show->attributes()->id == $_POST['id']) {
                 $remove = $i;
             }
             $i++;
         }
         //remove it
         if (isset($remove)) {
             unset($xml->show[$remove]);
         }
         //write updated xml file
         print saveXML($xml) ? 1 : 0;
     }
     exit;
     //get posters
 //get posters
 case 'get_posters':
     $show_xml = file_get_contents($config['thetvdb']['show_info'] . urlencode($_REQUEST['show_name']));
     $xml = simplexml_load_string($show_xml);
     if ($xml) {
         $series = $xml->xpath('/Data/Series');
         if (sizeof($series) > 0) {
             //1 match found
             if (sizeof($series) == 1) {
                 $series_id = $series[0]->seriesid;
             } else {
                 foreach ($series as $show) {
Esempio n. 2
0
function process_tv()
{
    global $config, $twitter;
    $shows_added = 0;
    $mail_string = '';
    print date($config['logging']['date_format']) . 'hellaVCR/' . $config['version'] . "\n";
    print date($config['logging']['date_format']) . "processing tv...\n";
    //check to make sure the file exists
    if (file_exists($config['xml_tv'])) {
        //create a SimpleXML object
        $xml = simplexml_load_file($config['xml_tv']) or die("Can't read XML");
        //loop over each show
        $shows = $xml->xpath('/tv/show');
        foreach ($shows as $show) {
            //extra show name info
            $nameExtra = array();
            if (array_key_exists(strval($show->format), $GLOBALS['formats'])) {
                $nameExtra[] = $GLOBALS['formats'][strval($show->format)];
            }
            if (array_key_exists(strval($show->language), $GLOBALS['languages'])) {
                $nameExtra[] = $GLOBALS['languages'][strval($show->language)];
            }
            if (array_key_exists(strval($show->source), $GLOBALS['sources'])) {
                $nameExtra[] = $GLOBALS['sources'][strval($show->source)];
            }
            $nameExtra = implode(', ', $nameExtra);
            if (strlen($nameExtra) > 0) {
                $nameExtra = ' (' . $nameExtra . ')';
            }
            //full show name
            $name = htmlspecialchars_decode($show->name) . $nameExtra;
            print date($config['logging']['date_format']) . $name . "\n";
            //add timestamp
            if (empty($show['updated'])) {
                $show->addAttribute('updated', 0);
            }
            //get info from tv scraper if past the refresh time
            $show_info = get_show_info($show);
            //no show info (skip)
            if (empty($show_info)) {
                print date($config['logging']['date_format']) . '	get show info FAILED! (' . $config['info_scraper'] . " likely down)\n";
                continue;
            }
            //update timestamp
            if (!$show_info['cached']) {
                $show['updated'] = time();
            }
            //make sure it has an ID
            if (empty($show['id'])) {
                print "adding ID";
                $show->addAttribute('id', generate_id());
            }
            //make sure it has a downloads node
            if (!$show->downloads) {
                $show->addChild('downloads', '');
            } else {
                $remove = 0;
                foreach ($show->downloads->download as $download) {
                    if (!empty($download->episode)) {
                        $ep_parts = explode('x', $download->episode);
                        $double_parts = explode('-', $ep_parts[1]);
                        //add new nodes
                        foreach ($double_parts as $ep) {
                            $d = $show->downloads->addChild('download');
                            $d->addAttribute('season', intval($ep_parts[0]));
                            $d->addAttribute('episode', intval($ep));
                            $d->addAttribute('timestamp', $download->timestamp);
                        }
                        $remove++;
                    }
                }
                //remove old nodes
                while ($remove-- > 0) {
                    unset($show->downloads->download[0]);
                }
            }
            if (!$show_info['cached']) {
                //auto update show name to match info scraper
                if ($config['update_show_name'] && strlen(trim($show_info['name'])) > 0 && trim($show->name) != $show_info['name']) {
                    $show->name = $show_info['name'];
                    print date($config['logging']['date_format']) . '	name updated to match ' . $config['info_scraper'] . ': ' . $show->name . "\n";
                }
                //update tvrage series id
                if (!$show->tvrageid) {
                    $show->addChild('tvrageid', $show_info['tvrageid']);
                } else {
                    $show->tvrageid = trim($show_info['tvrageid']);
                }
                //update thetvdb series id
                if (!$show->thetvdbid) {
                    $show->addChild('thetvdbid', $show_info['thetvdbid']);
                } else {
                    $show->thetvdbid = trim($show_info['thetvdbid']);
                }
                //episode list (seasons, eps)
                if (!$show->episodelist) {
                    $show->addChild('episodelist', '');
                }
                if (!empty($show_info['episodelist'])) {
                    foreach ($show_info['episodelist'] as $season => $episodes) {
                        $s_existing = $show->episodelist->xpath('season[@num=' . $season . ']');
                        //exists, so just update
                        if (!empty($s_existing)) {
                            $s_existing[0]['episodes'] = sizeof($episodes);
                        } else {
                            $s = $show->episodelist->addChild('season');
                            $s->addAttribute('num', $season);
                            $s->addAttribute('episodes', sizeof($episodes));
                        }
                        /*
                        //full episode details
                        foreach($episodes as $episode) {
                        	$e = $s->addChild('episode');
                        	$e->addAttribute('num', $episode['num']);
                        	$e->addAttribute('aired', $episode['aired']);
                        	$e->addAttribute('title', htmlentities($episode['title']));
                        }
                        */
                    }
                }
                //update episode URL
                if (!$show->url) {
                    $show->addChild('url', $show_info['Show URL']);
                } else {
                    $show->url = trim($show_info['Show URL']);
                }
                //update status
                if (!$show->status) {
                    $show->addChild('status', $show_info['Status']);
                } else {
                    $show->status = htmlspecialchars(trim($show_info['Status']));
                }
                //update airtime
                if (!$show->airtime) {
                    $show->addChild('airtime', $show_info['Airtime']);
                } else {
                    $show->airtime = htmlspecialchars(trim($show_info['Airtime']));
                }
                //update network
                if (!$show->network) {
                    $show->addChild('network', $show_info['Network']);
                } else {
                    $show->network = htmlspecialchars(trim($show_info['Network']));
                }
                //update year the show started
                if (!$show->year) {
                    $show->addChild('year', $show_info['Premiered']);
                } else {
                    $show->year = htmlspecialchars(trim($show_info['Premiered']));
                }
                //update next ep
                $air_date = $show_info['Next Episode']['airdate'];
                if (substr_count($air_date, '/') == 2) {
                    $date_parts = explode('/', $air_date);
                    $air_date = date('(l) F j, Y', strtotime($date_parts[1] . ' ' . $date_parts[0] . ' ' . $date_parts[2]));
                }
                $next_info = strlen(trim($show_info['Next Episode']['episode'])) > 0 ? $show_info['Next Episode']['episode'] . ' - "' . $show_info['Next Episode']['title'] . '" airs ' . $air_date : '';
                if (!$show->next) {
                    $show->addChild('next', htmlspecialchars(trim($next_info)));
                } else {
                    $show->next = htmlspecialchars(trim($next_info));
                }
                //print date($config['logging']['date_format']) . '	next episode: ' . $show_info['Next Episode']['episode'] . "\n";
                //update next timestamp (includes date and time)
                if (strpos($show_info['RFC3339'], 'T:00-') !== false) {
                    $time_prefix = '00:00';
                    if (strlen($show_info['Airtime']) > 0) {
                        $time_parts = explode('at', $show_info['Airtime']);
                        $time_prefix = date('H:i', strtotime('today ' . $time_parts[1]));
                    }
                    $show_info['next_timestamp'] = strtotime(str_replace('T:00-', 'T' . $time_prefix . ':00-', $show_info['RFC3339']));
                }
                if (!$show->next_timestamp) {
                    $show->addChild('next_timestamp', $show_info['next_timestamp']);
                } else {
                    $show->next_timestamp = trim($show_info['next_timestamp']);
                }
                //update latest episode
                if (!$show->latest) {
                    $show->addChild('latest', trim($show_info['Latest Episode']['episode']));
                } else {
                    $show->latest = trim($show_info['Latest Episode']['episode']);
                }
            }
            //queue up any episodes prior to the last episode (there must be at least 1 aired episode)
            if ($show->latest) {
                $latest = explode('x', $show->latest);
                $latest_season = intval($latest[0]);
                $latest_episode = intval($latest[1]);
                //if season or episode are blank, default to the last episode so shows are downloded moving forward
                if ($show->season == '' && $show->episode == '') {
                    $show->season = $latest_season;
                    $show->episode = $latest_episode;
                    //special case for a brand new series
                    if ($latest_season == '1' && strpos($latest_episode, '01') !== false) {
                        $show->episode = 0;
                    }
                }
                //check on the day of air since tvrage doesn't update 'Latest Episode' until midnight
                if (strval($show->next_timestamp) != '' && date('m/d/Y') == date('m/d/Y', strval($show->next_timestamp)) && $show->episode == $latest_episode) {
                    $pre_midnight_check = true;
                    $latest_episode = intval($latest_episode) + 1;
                }
                print date($config['logging']['date_format']) . '	last episode: ' . $show->season . 'x' . sprintf('%02d', $show->episode) . "\n";
                $one_ep_behind = $show->season == $latest_season && $show->episode == $latest_episode - 1;
                $skipped_episodes = 0;
                //loop over all mising episodes
                $current_season = intval($show->season);
                while ($current_season <= $latest_season && $current_season <= sizeof($show->episodelist->xpath('season'))) {
                    $current_episode = $current_season > intval($show->season) ? 0 : intval($show->episode + 1);
                    while ($current_episode <= $latest_episode || $current_season < $latest_season) {
                        $episode_string = $current_season . 'x' . sprintf('%02d', $current_episode);
                        $episode_info = $show->episodelist->xpath('season[@num=' . $current_season . ']');
                        //episode found, attempt to queue
                        if (sizeof($episode_info) > 0 && $episode_info[0]['episodes'] >= $current_episode) {
                            // Fetch TVrage airtime
                            $airdate = $show_info['episodelist'][$current_season][$current_episode]['aired'];
                            if ($airdate) {
                                $airdate = date("Y-m-d", $airdate);
                            }
                            $nzb_info = false;
                            $nzb_info = search_nzb(array('show' => $show->name, 'year' => $show->year, 'season' => $current_season, 'episode' => $current_episode, 'language' => $show->language, 'format' => $show->format, 'source' => $show->source, 'airdate' => $airdate));
                            $nzb_downloaded = false;
                            $double_ep = false;
                            if (!$nzb_info) {
                                //try again without specified format
                                $nzb_info = search_nzb(array('show' => $show->name, 'year' => $show->year, 'season' => $current_season, 'episode' => $current_episode, 'language' => $show->language, 'format' => '', 'source' => $show->source, 'airdate' => $airdate));
                            }
                            //id found
                            if ($nzb_info) {
                                //nzbmatrix double ep
                                switch ($config['nzb_site']) {
                                    case 'nzbmatrix':
                                        $double_ep = strpos($nzb_info['title'], 'E' . sprintf('%02d', $current_episode) . 'E' . sprintf('%02d', $current_episode + 1));
                                        break;
                                    case 'tvnzb':
                                        //--
                                        break;
                                    case 'newzbin':
                                    default:
                                        $double_ep = strpos($nzb_info['title'], $current_season . 'x' . sprintf('%02d', $current_episode + 1)) !== false;
                                }
                                //double episode found
                                if ($double_ep) {
                                    $current_episode++;
                                    $episode_string .= '-' . sprintf('%02d', $current_episode);
                                    $double_ep = true;
                                    print 'double episode found' . $config['debug_separator'];
                                }
                                switch ($config['nzb_handler']) {
                                    //move to directory
                                    case 'nzb':
                                        $nzb_downloaded = download_nzb($nzb_info);
                                        break;
                                        //send to hellanzb
                                    //send to hellanzb
                                    case 'hellanzb':
                                        $nzb_downloaded = send_to_hellanzb($nzb_info);
                                        if ($nzb_downloaded) {
                                            $shows_added++;
                                        }
                                        break;
                                        //send to sabnzbd
                                    //send to sabnzbd
                                    case 'sabnzbd':
                                        $nzb_downloaded = send_to_sabnzbd($nzb_info, $config['nzb_site'] == 'nzbmatrix');
                                        if ($nzb_downloaded) {
                                            $shows_added++;
                                        }
                                        break;
                                    default:
                                        //seems like a die worthy event
                                        die('NZB Handler not configured properly');
                                        break;
                                }
                                //newzbin has a limit of 5 nzb's per minute
                                //rate limit not needed in nzb mode since download_nzb handles the exact time to wait
                                if ($config['nzb_handler'] != 'nzb' && $shows_added % 5 == 0) {
                                    sleep(60);
                                }
                                //send XBMC update
                                if ($nzb_downloaded && $config['xbmc'] && $config['xbmc_host']) {
                                    $xbmc_ch = curl_init('http://' . $config['xbmc_host'] . '/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=Notification(Download+Started,' . urlencode($show->name) . '+' . $episode_string . ')');
                                    curl_setopt($xbmc_ch, CURLOPT_RETURNTRANSFER, 1);
                                    curl_setopt($xbmc_ch, CURLOPT_TIMEOUT, 5);
                                    $result = curl_exec($xbmc_ch);
                                    curl_close($xbmc_ch);
                                    print $config['debug_separator'] . 'XBMC notification ' . ($result ? 'ok' : 'FAILED');
                                }
                                //send twitter update
                                if ($nzb_downloaded && $config['twitter'] && $twitter) {
                                    $prefix = $config['hollers'][@array_rand($config['hollers'])];
                                    $status = $twitter->send($prefix . $show->name . ' ' . $episode_string . $nameExtra);
                                    print $config['debug_separator'] . ($status ? 'tweeted ok' : 'twitter FAILED');
                                }
                                //build mail string
                                if ($nzb_downloaded) {
                                    $mail_string .= $show->name . ' ' . $episode_string . ' (' . $GLOBALS['formats'][strval($show->format)] . ', ' . $GLOBALS['languages'][strval($show->language)] . ")\n";
                                }
                                //save to download history
                                if ($nzb_downloaded) {
                                    $download_node = $show->downloads->addChild('download', '');
                                    $download_node->addAttribute('season', $current_season);
                                    $download_node->addAttribute('episode', $current_episode);
                                    $download_node->addAttribute('timestamp', time());
                                    if ($double_ep) {
                                        $download_node = $show->downloads->addChild('download', '');
                                        $download_node->addAttribute('season', $current_season);
                                        $download_node->addAttribute('episode', $current_episode + 1);
                                        $download_node->addAttribute('timestamp', time());
                                    }
                                }
                                print "\n";
                            } else {
                                //$skipped_episodes++;
                                print "skipping this episode\n";
                                //increment season if we're out of eps
                                $seasonInfo = $show->episodelist->xpath('season[@num=' . $current_season . ']');
                                if (sizeof($seasonInfo) > 0 && $current_episode + 1 > $seasonInfo[0]['episodes']) {
                                    break;
                                }
                            }
                            //increment last episode for the show
                            if ($nzb_downloaded) {
                                $show->season = $current_season;
                                $show->episode = $current_episode;
                            }
                            $current_episode++;
                        } else {
                            break;
                        }
                    }
                    $current_season++;
                }
            }
        }
        //send email
        if (!empty($config['mail']) && $mail_string != '') {
            $mail_sent = mail($config['mail_to'], '[hellaVCR] ' . substr_count($mail_string, "\n") . ' episodes found', "The following episodes have been queued:\n\n" . $mail_string, 'From: hellaVCR <*****@*****.**>');
            print date($config['logging']['date_format']) . 'emailing queue' . $config['debug_separator'] . ($mail_sent ? 'done' : 'FAIL') . "\n";
        }
        //send prowl
        if (!empty($config['prowl']) && $mail_string != '') {
            $prowl_sent = send_prowl(substr_count($mail_string, "\n") . ' episodes found', "The following episodes have been queued:\n\n" . $mail_string);
            print date($config['logging']['date_format']) . 'sending prowl notification' . $config['debug_separator'] . $prowl_sent . "\n";
        }
        //write new xml file
        $xml_updated = saveXML($xml);
        print date($config['logging']['date_format']) . 'saving xml file' . $config['debug_separator'] . ($xml_updated ? 'done' : 'FAIL') . "\n";
    } else {
        print date($config['logging']['date_format']) . 'tv XML (' . $config['xml_tv'] . ') file not found...make sure to use an absolute path' . "\n";
    }
}
Esempio n. 3
0
    } else {
        array_map('unlink', glob($folderName . '/*.html'));
    }
    if ($_SESSION['copiedToFolder'] == 0) {
        copy('proprietary.css', $folderName . '/proprietary.css');
        copy('proprietary.js', $folderName . '/proprietary.js');
        copy('chart.js', $folderName . '/chart.js');
        copy('upload/files/dataPHP-' . $_SESSION['fileNameInternal'], $folderName . '/dataPHP');
        unlink('upload/files/dataPHP-' . $_SESSION['fileNameInternal']);
        unlink('upload/files/' . $_SESSION['fileNameInternal'] . '.' . $_SESSION['extension']);
        $_SESSION['copiedToFolder'] = 1;
    }
    if (file_exists($folderName . '/dataPHP')) {
        $_SESSION['folder'] = 1;
        $dataString = file_get_contents($folderName . '/dataPHP');
        $data = unserialize($dataString);
        unset($dataString);
        saveXML($data, $catalogue, $folderName);
        makeCSV($data, $folderName, $catalogue->fileName);
        echo '<p>Die Metadaten wurden gespeichert.<br />';
        echo 'Weiter zur <a href="geodata.php">Geodatenanreicherung</a>.</p>';
    } else {
        echo '<p>Es ist ein Fehler aufgetreten. Bitte fangen Sie <a href="load.php">von vorne</a> an.</p>';
    }
}
?>
				
			</div>
		</body>
</html>