outputText; } public static function getEpisodeNumberByFilename($filename) { preg_match("/([a-zA-Z0-9äöüÄÖÜß\-\.\,\w]+)-[S|s]([0-9]+)[E|e]([0-9]+)-([a-zA-Z0-9äöüÄÖÜß\-\.\,\w\:]+)\.([a-zA-Z0-9\(\).*\w\,]+)/", $filename, $output); return ltrim($output[3], 0); } public static function remove($seriesID) { $series = Model::getSeriesBySeriesID($seriesID); $seasons = Model::getSeasonsBySeriesID($seriesID); foreach($seasons as $season) { $episodes = $GLOBALS['db']->getAllAssoc("series-episodes", "season-id", $season['id']); foreach($episodes as $episode) { unlink("img/posters/" . $episode['thumb']); } $GLOBALS['db']->deleteRows("series-episodes", "season-id", $season['id']); } $seasons = $GLOBALS['db']->getAllAssoc("series-seasons", "series-id", $seriesID); foreach($seasons as $season) { unlink("img/posters/" . $season['poster']); } $GLOBALS['db']->deleteRows("series-seasons", "series-id", $seriesID); $series = $GLOBALS['db']->getAllAssoc("series", "id", $seriesID); unlink("img/posters/" . $series[0]['poster']); unlink("img/posters/" . $series[0]['backdrop']); $GLOBALS['db']->deleteRows("series", "id", $seriesID); header("Location: " . $GLOBALS['conf']['baseURL'] . "?view=admin"); } public function update($seriesID) { $series = Model::getSeriesBySeriesID($seriesID); self::remove($seriesID); $this->downloadSeriesByID($series[0]['moviedb-id'], $series[0]['path'], $series[0]['source']); header("Location: " . $GLOBALS['conf']['baseURL'] . "?view=admin"); } public function scrapeFolder($sourceID) { if(!file_exists("img/posters")) { mkdir("img/posters"); } $source = $GLOBALS['db']->getAllAssoc("sources", "id", $sourceID); $dirList = scandir($source[0]['path']); $dirList = array_diff($dirList, array('.', '..', 'formatting.txt', '.Trash-1000', 'queue.hbq')); foreach($dirList as $dir) { $this->outputText .= "" . $dir . "
" . PHP_EOL; if($GLOBALS['db']->countRows("series", "path", $dir) > 0) { $this->outputText .= "Exists, skipping..

" . PHP_EOL; continue; } $series = json_decode(curl_download($this->apiURL . urlencode($dir) . "&language=de&include_image_language=de"), true); if($series['total_results'] == 1) { $this->outputText .= "Found 1 series, downloading...
" . PHP_EOL; $this->downloadSeriesByID($series['results'][0]['id'], $dir, $sourceID); } else if($series['total_results'] < 1) { $this->outputText .= "Not found!!
" . PHP_EOL; } else { // multiple search results usort($series['results'], array("MovieScraper", "sortByPopularity")); // sort results by popularity, so that you don't have to scroll like 500000x foreach($series['results'] as $result) { $this->outputText .= "
" . print_r($result, true) . "
" . PHP_EOL; $this->outputText .= "Load

" . PHP_EOL; // TODO: this } } $this->outputText .= "
" . PHP_EOL; /* Array ( [page] => 1 [results] => Array ( [0] => Array ( [poster_path] => /hDlezfMSw8oXIFNZ7B9fFLrV8kd.jpg [popularity] => 1.006821 [id] => 15826 [backdrop_path] => /meQN6iuOulLwOV8LNO6S9z3bJBY.jpg [vote_average] => 7 [overview] => 1000 Ways to Die is an anthology television series that [...] [first_air_date] => 2009-02-04 [origin_country] => Array ( [0] => US ) [genre_ids] => Array ( [0] => 99 ) [original_language] => en [vote_count] => 1 [name] => 1000 Ways to Die [original_name] => 1000 Ways to Die ) ) [total_results] => 1 [total_pages] => 1 ) */ } } public function downloadSeriesByID($seriesID, $path, $sourceID) { $source = $GLOBALS['db']->getAllAssoc("sources", "id", $sourceID); $series = json_decode(curl_download("http://api.themoviedb.org/3/tv/" . $seriesID . "?api_key=a39779a38e0619f8ae58b09f64522597&language=de&include_image_language=de"), true); //$this->outputText .= "
" . print_r($series, true) . "
"; // Download poster, backdrop if(!file_exists("img/posters" . $series['poster_path'])) { file_put_contents("img/posters" . $series['poster_path'], fopen($this->bannerURL . $series['poster_path'], 'r')); } if(!file_exists("img/posters" . $series['backdrop_path'])) { file_put_contents("img/posters" . $series['backdrop_path'], fopen($this->bannerURL . $series['backdrop_path'], 'r')); } $cols = array( "moviedb-id", "name", "path", "poster", "backdrop", "overview", "source" ); $vals = array( $series['id'], $series['name'], $path, ltrim($series['poster_path'], "/"), ltrim($series['backdrop_path'], "/"), $series['overview'], $sourceID ); $dbSeriesID = $GLOBALS['db']->insertRow("series", $cols, $vals); $localSeasons = scandir($source[0]['path'] . "/" . $path); $localSeasons = array_diff($localSeasons, array('.', '..', 'formatting.txt', '.Trash-1000')); foreach($localSeasons as $localSeason) { $season = array_search(ltrim(ltrim($localSeason, "S"), 0), array_column($series['seasons'], 'season_number')); $cols = array( "series-id", "number", "poster" ); $vals = array( $dbSeriesID, $series['seasons'][$season]['season_number'], ltrim($series['seasons'][$season]['poster_path'], "/") ); $dbSeasonID = $GLOBALS['db'] -> insertRow("series-seasons", $cols, $vals); if(!file_exists("img/posters" . $series['seasons'][$season]['poster_path'])) { file_put_contents("img/posters" . $series['seasons'][$season]['poster_path'], fopen($this->bannerURL . $series['seasons'][$season]['poster_path'], 'r')); } $localEpisodes = scandir($source[0]['path'] . "/" . $path . "/" . $localSeason); $localEpisodes = array_diff($localEpisodes, array('.', '..', 'formatting.txt', '.Trash-1000')); $dbEpisodes = get_object_vars(json_decode(curl_download("http://api.themoviedb.org/3/tv/" . $seriesID . "/season/" . ltrim(ltrim($localSeason, "S"), 0) . "?api_key=a39779a38e0619f8ae58b09f64522597&language=de&include_image_language=de"))); $episodes = array(); foreach($dbEpisodes['episodes'] as $episode) { $episodes[] = get_object_vars($episode); } foreach($localEpisodes as $localEpisode) { $episode = array_search($this::getEpisodeNumberByFilename($localEpisode), array_column($episodes, 'episode_number')); $cols = array( "season-id", "number", "name", "thumb", "path" ); $vals = array( $dbSeasonID, $episodes[$episode]['episode_number'], $episodes[$episode]['name'], ltrim($episodes[$episode]['still_path'], "/"), $localEpisode ); $GLOBALS['db'] -> insertRow("series-episodes", $cols, $vals); if(!file_exists("img/posters" . $episodes[$episode]['still_path'])) { file_put_contents("img/posters" . $episodes[$episode]['still_path'], fopen($this->bannerURL . $episodes[$episode]['still_path'], 'r')); } } } $this->outputText .= "Done."; } }