outputText;
}
public static function getMovieNameFromFilename($filename) {
preg_match("/([a-zA-Z0-9äöüÄÖÜ.]+).([0-9][0-9][0-9][0-9]).([a-z0-9]+)/", $filename, $output);
return str_replace(".", " ", $output[1]);
}
public static function sortByPopularity($movieA, $movieB) {
if($movieA['popularity'] == $movieB['popularity']) {
return 0;
}
return ($movieA['popularity'] < $movieB['popularity']) ? 1 : -1;
}
public static function remove($movieID) {
$movie = $GLOBALS['db']->getAllAssoc("movies", "id", $movieID);
unlink("img/posters/" . $movie[0]['poster']);
unlink("img/posters/" . $movie[0]['backdrop']);
$GLOBALS['db']->deleteRows("movies", "id", $movieID);
header("Location: " . $GLOBALS['conf']['baseURL'] . "?view=admin");
}
public static function update($movieID) {
$movie = $GLOBALS['db']->getAllAssoc("movies", "id", $movieID);
self::remove($movieID);
$this->downloadMovieByID($movie['moviedb-id'], $movie['path'], $movie['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);
$fileList = scandir($source[0]['path']);
$fileList = array_diff($fileList, array('.', '..', 'formatting.txt', '.Trash-1000'));
foreach($fileList as $file) {
$this->outputText .= "" . self::getMovieNameFromFilename($file) . "
" . PHP_EOL;
if($GLOBALS['db']->countRows("movies", "path", $file) > 0) {
$this->outputText .= "Exists, skipping..
" . PHP_EOL;
continue;
}
$movie = json_decode(curl_download($this->apiURL . urlencode(self::getMovieNameFromFilename($file)) . "&language=de&include_image_language=de"), true);
if($movie['total_results'] == 1) {
$this->outputText .= "Found 1 movie, downloading...
" . PHP_EOL;
$this->downloadMovieByID($movie['results'][0]['id'], $file, $sourceID);
} else if($movie['total_results'] < 1) {
$this->outputText .= "Not found!!
" . PHP_EOL;
} else { // multiple search results
usort($movie['results'], array("MovieScraper", "sortByPopularity")); // sort results by popularity, so that you don't have to scroll like 500000x
foreach($movie['results'] as $result) {
$this->outputText .= "
" . print_r($result, true) . "" . PHP_EOL; $this->outputText .= "Load