|
@@ -12,7 +12,6 @@ class SeriesScraper {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public function getOutputText() {
|
|
public function getOutputText() {
|
|
|
return $this->outputText;
|
|
return $this->outputText;
|
|
|
}
|
|
}
|
|
@@ -69,8 +68,9 @@ class SeriesScraper {
|
|
|
$this->outputText .= "<b>" . $dir . "</b><br>" . PHP_EOL;
|
|
$this->outputText .= "<b>" . $dir . "</b><br>" . PHP_EOL;
|
|
|
|
|
|
|
|
if($GLOBALS['db']->countRows("series", "path", $dir) > 0) {
|
|
if($GLOBALS['db']->countRows("series", "path", $dir) > 0) {
|
|
|
- $this->outputText .= "Exists, updating..<br><br>" . PHP_EOL;
|
|
|
|
|
|
|
+ $this->outputText .= "Exists, updating..<br>" . PHP_EOL;
|
|
|
self::updateByID($GLOBALS['db']->getString("id", "series", "path", $dir));
|
|
self::updateByID($GLOBALS['db']->getString("id", "series", "path", $dir));
|
|
|
|
|
+ $this->outputText .= "<br>" . PHP_EOL;
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -200,38 +200,51 @@ class SeriesScraper {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function updateByID($seriesID) {
|
|
public function updateByID($seriesID) {
|
|
|
- /*if($seriesID != 208) {
|
|
|
|
|
- return;
|
|
|
|
|
- }*/
|
|
|
|
|
-
|
|
|
|
|
- error_log($seriesID);
|
|
|
|
|
|
|
+ $seriesPath = $GLOBALS['db']->customQuery("SELECT `series`.`path` AS 'seriespath', `sources`.`path` AS 'sourcepath' FROM `series`, `sources` WHERE `series`.`id` = " . $seriesID . " AND `series`.`source` = `sources`.`id`");
|
|
|
|
|
+ $seriesPath = implode("/", array_reverse($seriesPath[0]));
|
|
|
|
|
|
|
|
$series = $GLOBALS['db']->getAllAssoc("series", "id", $seriesID);
|
|
$series = $GLOBALS['db']->getAllAssoc("series", "id", $seriesID);
|
|
|
$seriesDB = json_decode(curl_download("http://api.themoviedb.org/3/tv/" . $series[0]['moviedb-id'] . "?api_key=a39779a38e0619f8ae58b09f64522597&language=de&include_image_language=de"), true);
|
|
$seriesDB = json_decode(curl_download("http://api.themoviedb.org/3/tv/" . $series[0]['moviedb-id'] . "?api_key=a39779a38e0619f8ae58b09f64522597&language=de&include_image_language=de"), true);
|
|
|
|
|
|
|
|
if($series[0]['poster'] != ltrim($seriesDB['poster_path'], "/")) { // poster
|
|
if($series[0]['poster'] != ltrim($seriesDB['poster_path'], "/")) { // poster
|
|
|
- error_log("New Poster, old: " . $series[0]['poster'] . " new: " . ltrim($seriesDB['poster_path'], "/"));
|
|
|
|
|
- unlink("img/posters/" . $series[0]['poster']);
|
|
|
|
|
|
|
+ //error_log("New Poster, old: " . $series[0]['poster'] . " new: " . ltrim($seriesDB['poster_path'], "/"));
|
|
|
|
|
+ if(file_exists("img/posters/" . $series[0]['poster']) && !is_dir("img/posters/" . $series[0]['poster'])) {
|
|
|
|
|
+ unlink("img/posters/" . $series[0]['poster']);
|
|
|
|
|
+ }
|
|
|
file_put_contents("img/posters" . $seriesDB['poster_path'], fopen($this->bannerURL . $seriesDB['poster_path'], 'r'));
|
|
file_put_contents("img/posters" . $seriesDB['poster_path'], fopen($this->bannerURL . $seriesDB['poster_path'], 'r'));
|
|
|
$GLOBALS['db']->updateRow("series", "poster", '"' . ltrim($seriesDB['poster_path'], "/") . '"', "id", $seriesID);
|
|
$GLOBALS['db']->updateRow("series", "poster", '"' . ltrim($seriesDB['poster_path'], "/") . '"', "id", $seriesID);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if($series[0]['backdrop'] != ltrim($seriesDB['backdrop_path'], "/")) { // backdrop
|
|
if($series[0]['backdrop'] != ltrim($seriesDB['backdrop_path'], "/")) { // backdrop
|
|
|
- error_log("New Backdrop, old: " . $series[0]['backdrop'] . " new: " . ltrim($seriesDB['backdrop_path'], "/"));
|
|
|
|
|
- unlink("img/posters/" . $series[0]['backdrop']);
|
|
|
|
|
|
|
+ //error_log("New Backdrop, old: " . $series[0]['backdrop'] . " new: " . ltrim($seriesDB['backdrop_path'], "/"));
|
|
|
|
|
+ if(file_exists("img/posters/" . $series[0]['backdrop']) && !is_dir("img/posters/" . $series[0]['backdrop'])) {
|
|
|
|
|
+ unlink("img/posters/" . $series[0]['backdrop']);
|
|
|
|
|
+ }
|
|
|
file_put_contents("img/posters" . $seriesDB['backdrop_path'], fopen($this->bannerURL . $seriesDB['backdrop_path'], 'r'));
|
|
file_put_contents("img/posters" . $seriesDB['backdrop_path'], fopen($this->bannerURL . $seriesDB['backdrop_path'], 'r'));
|
|
|
$GLOBALS['db']->updateRow("series", "backdrop", '"' . ltrim($seriesDB['backdrop_path'], "/") . '"', "id", $seriesID);
|
|
$GLOBALS['db']->updateRow("series", "backdrop", '"' . ltrim($seriesDB['backdrop_path'], "/") . '"', "id", $seriesID);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$seasons = $GLOBALS['db']->getAllAssoc("series-seasons", "series-id", $seriesID);
|
|
$seasons = $GLOBALS['db']->getAllAssoc("series-seasons", "series-id", $seriesID);
|
|
|
|
|
+ $localSeasons = scandir($seriesPath);
|
|
|
|
|
+ $localSeasons = array_diff($localSeasons, array('.', '..', 'formatting.txt', '.Trash-1000', 'queue.hbq'));
|
|
|
|
|
|
|
|
foreach($seasons as $season) { // TODO: check for new seasons
|
|
foreach($seasons as $season) { // TODO: check for new seasons
|
|
|
|
|
+ if(!in_array("S" . sprintf("%02d", $season['number']), $localSeasons)) {
|
|
|
|
|
+ //error_log("Season " . "S" . sprintf("%02d", $season['number']) . " not existing anymore");
|
|
|
|
|
+ $GLOBALS['db']->deleteRows("series-seasons", "id", $seasons['id']);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ unset($localSeasons[array_search("S" . sprintf("%02d", $season['number']), $localSeasons)]);
|
|
|
|
|
+
|
|
|
$seasonDB = array_search(ltrim($season['number'], 0), array_column($seriesDB['seasons'], 'season_number'));
|
|
$seasonDB = array_search(ltrim($season['number'], 0), array_column($seriesDB['seasons'], 'season_number'));
|
|
|
$seasonDB = $seriesDB['seasons'][$seasonDB];
|
|
$seasonDB = $seriesDB['seasons'][$seasonDB];
|
|
|
|
|
|
|
|
if($season['poster'] != ltrim($seasonDB['poster_path'], "/")) {
|
|
if($season['poster'] != ltrim($seasonDB['poster_path'], "/")) {
|
|
|
- error_log("New Season-Poster, old: " . $season['poster'] . " new: " . ltrim($seasonDB['poster_path'], "/"));
|
|
|
|
|
- unlink("img/posters/" . $season['poster']);
|
|
|
|
|
|
|
+ //error_log("New Season-Poster, old: " . $season['poster'] . " new: " . ltrim($seasonDB['poster_path'], "/"));
|
|
|
|
|
+ if(file_exists("img/posters/" . $season['poster']) && !is_dir("img/posters/" . $season['poster'])) {
|
|
|
|
|
+ unlink("img/posters/" . $season['poster']);
|
|
|
|
|
+ }
|
|
|
file_put_contents("img/posters" . $seasonDB['poster_path'], fopen($this->bannerURL . $seasonDB['poster_path'], 'r'));
|
|
file_put_contents("img/posters" . $seasonDB['poster_path'], fopen($this->bannerURL . $seasonDB['poster_path'], 'r'));
|
|
|
$GLOBALS['db']->updateRow("series-seasons", "poster", '"' . ltrim($seasonDB['poster_path'], "/") . '"', "id", $season['id']);
|
|
$GLOBALS['db']->updateRow("series-seasons", "poster", '"' . ltrim($seasonDB['poster_path'], "/") . '"', "id", $season['id']);
|
|
|
}
|
|
}
|
|
@@ -239,17 +252,78 @@ class SeriesScraper {
|
|
|
$episodesDB = json_decode(curl_download("http://api.themoviedb.org/3/tv/" . $series[0]['moviedb-id'] . "/season/" . $season['number'] . "?api_key=a39779a38e0619f8ae58b09f64522597&language=de&include_image_language=de"), true);
|
|
$episodesDB = json_decode(curl_download("http://api.themoviedb.org/3/tv/" . $series[0]['moviedb-id'] . "/season/" . $season['number'] . "?api_key=a39779a38e0619f8ae58b09f64522597&language=de&include_image_language=de"), true);
|
|
|
|
|
|
|
|
$episodes = $GLOBALS['db']->getAllAssoc("series-episodes", "season-id", $season['id']);
|
|
$episodes = $GLOBALS['db']->getAllAssoc("series-episodes", "season-id", $season['id']);
|
|
|
|
|
+ $localEpisodes = scandir($seriesPath . "/" . "S" . sprintf("%02d", $season['number']));
|
|
|
|
|
+ $localEpisodes = array_diff($localEpisodes, array('.', '..', 'formatting.txt', '.Trash-1000', 'queue.hbq'));
|
|
|
|
|
+
|
|
|
foreach($episodes as $episode) {
|
|
foreach($episodes as $episode) {
|
|
|
|
|
+ if(!in_array($episode['path'], $localEpisodes)) {
|
|
|
|
|
+ //error_log("Episode " . $episode['number'] . " not existing anymore");
|
|
|
|
|
+ $GLOBALS['db']->deleteRows("series-episodes", "id", $episode['id']);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ unset($localEpisodes[array_search($episode['path'], $localEpisodes)]);
|
|
|
|
|
+
|
|
|
$episodeDB = array_search($episode['number'], array_column($episodesDB['episodes'], 'episode_number'));
|
|
$episodeDB = array_search($episode['number'], array_column($episodesDB['episodes'], 'episode_number'));
|
|
|
$episodeDB = $episodesDB['episodes'][$episodeDB];
|
|
$episodeDB = $episodesDB['episodes'][$episodeDB];
|
|
|
|
|
|
|
|
if($episode['thumb'] != ltrim($episodeDB['still_path'], "/")) {
|
|
if($episode['thumb'] != ltrim($episodeDB['still_path'], "/")) {
|
|
|
- error_log("New Episode-Poster, old: " . $episode['thumb'] . " new: " . ltrim($episodeDB['still_path'], "/"));
|
|
|
|
|
- unlink("img/posters/" . $episode['thumb']);
|
|
|
|
|
|
|
+ //error_log("New Episode-Poster, old: " . $episode['thumb'] . " new: " . ltrim($episodeDB['still_path'], "/"));
|
|
|
|
|
+ if(file_exists("img/posters/" . $episode['thumb']) && !is_dir("img/posters/" . $episode['thumb'])) {
|
|
|
|
|
+ unlink("img/posters/" . $episode['thumb']);
|
|
|
|
|
+ }
|
|
|
file_put_contents("img/posters" . $episodeDB['still_path'], fopen($this->bannerURL . $episodeDB['still_path'], 'r'));
|
|
file_put_contents("img/posters" . $episodeDB['still_path'], fopen($this->bannerURL . $episodeDB['still_path'], 'r'));
|
|
|
$GLOBALS['db']->updateRow("series-episodes", "thumb", '"' . ltrim($episodeDB['still_path'], "/") . '"', "id", $episode['id']);
|
|
$GLOBALS['db']->updateRow("series-episodes", "thumb", '"' . ltrim($episodeDB['still_path'], "/") . '"', "id", $episode['id']);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if(sizeof($localEpisodes) > 0) {
|
|
|
|
|
+ //error_log("New Episode(s); " . print_r($localEpisodes, true));
|
|
|
|
|
+ $this->outputText .= "New Episode(s), Please update again.<br>";
|
|
|
|
|
+
|
|
|
|
|
+ $cols = array(
|
|
|
|
|
+ "season-id",
|
|
|
|
|
+ "number",
|
|
|
|
|
+ "name",
|
|
|
|
|
+ "thumb",
|
|
|
|
|
+ "path"
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ foreach($localEpisodes as $localEpisode) {
|
|
|
|
|
+ $vals = array(
|
|
|
|
|
+ $season['id'],
|
|
|
|
|
+ ltrim(ltrim(self::getEpisodeNumberByFilename($localEpisode), "S"), 0),
|
|
|
|
|
+ "",
|
|
|
|
|
+ "",
|
|
|
|
|
+ $localEpisode
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ $GLOBALS['db']->insertRow("series-episodes", $cols, $vals);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if(sizeof($localSeasons) > 0) {
|
|
|
|
|
+ //error_log("New Season(s): " . print_r($localSeasons, true));
|
|
|
|
|
+ $this->outputText .= "New Season(s), Please update again.<br>";
|
|
|
|
|
+
|
|
|
|
|
+ $cols = array(
|
|
|
|
|
+ "series-id",
|
|
|
|
|
+ "number",
|
|
|
|
|
+ "poster",
|
|
|
|
|
+ "enabled"
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ foreach($localSeasons as $localSeason) {
|
|
|
|
|
+ $vals = array(
|
|
|
|
|
+ $seriesID,
|
|
|
|
|
+ ltrim(ltrim($localSeason, "S"), 0),
|
|
|
|
|
+ "",
|
|
|
|
|
+ 1
|
|
|
|
|
+ );
|
|
|
|
|
+ $GLOBALS['db']->insertRow("series-seasons", $cols, $vals);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|