Created
February 18, 2012 16:18
-
-
Save maximevalette/1860016 to your computer and use it in GitHub Desktop.
Récupérer facilement ses épisodes non-vus de BetaSeries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php5 | |
<?php | |
/* Configuration */ | |
$BS_LOGIN = ''; # Votre login BetaSeries | |
$BS_API_KEY = ''; # Votre clé API | |
$DL_FILE = dirname(__FILE__).'/torrents.list'; # Le nom du fichier où sont recensées les URL déjà téléchargées | |
$TMP_FILE = dirname(__FILE__).'/episode.torrent'; # Le nom du fichier temporaire où est stocké le torrent | |
/* Fonction pour télécharger un torrent */ | |
function downloadTorrent($url) { | |
global $TMP_FILE, $DL_FILE; | |
$done = file_get_contents($DL_FILE); | |
$done = explode("\n",$done); | |
// Si le fichier n'est pas dans la liste, on s'en occupe ! | |
if (!in_array($url,$done)) { | |
$torrent = file_get_contents($url); | |
file_put_contents($TMP_FILE,$torrent); | |
// La ligne ci-dessous dépend de votre installation. | |
// Ici on ajoute le fichier torrent dans transmission : | |
system('/usr/bin/transmission-remote -a '.$TMP_FILE); | |
// Et on met l'URL dans la liste pour éviter de la traiter à nouveau | |
file_put_contents($DL_FILE,$url."\n",FILE_APPEND); | |
unlink($TMP_FILE); | |
} | |
} | |
/* Récupération des séries du planning sur BetaSeries */ | |
$shows = array(); | |
$data = file_get_contents('http://api.betaseries.com/planning/member/'.$BS_LOGIN.'.xml?view=unseen&key='.$BS_API_KEY); | |
$xml = simplexml_load_string($data); | |
foreach ($xml->planning->item as $item) { | |
// On remplit un tableau pour simplifier la recherche d'épisodes non vus | |
$shows[(string)$item->show][(int)$item->season][(int)$item->episode] = true; | |
} | |
/* Récupération des épisodes sortis sur EZTV */ | |
$data = file_get_contents('http://www.ezrss.it/feed/'); | |
$xml = simplexml_load_string($data); | |
foreach ($xml->channel->item as $item) { | |
// Les séries ont toujours la même description dans le RSS, le parsing est simple | |
preg_match('/^Show Name: (.+); Episode Title: (.+); Season: ([0-9]+); Episode: ([0-9]+)$/i',(string)$item->description,$r); | |
// Si on trouve l'épisode dans les épisodes non-vus, on traite le torrent | |
if (isset($shows[$r[1]][$r[3]][$r[4]])) { | |
downloadTorrent($item->link); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment