cleanup Videoparser and add support for release years in filenames

This commit is contained in:
2020-09-23 18:43:50 +00:00
parent b3555efa57
commit 444ef3f074
4 changed files with 356 additions and 259 deletions

View File

@ -15,12 +15,25 @@ class TMDBMovie {
* @param string $moviename moviename
* @return object movie object or null if not found
*/
public function searchMovie(string $moviename) {
public function searchMovie(string $moviename, string $year = null) {
$reply = json_decode(file_get_contents($this->baseurl . "search/movie?api_key=" . $this->apikey . "&query=" . urlencode($moviename)));
if ($reply->total_results == 0) {
// no results found
// todo maybe parse first pictures somehow
return null;
} elseif ($year != null) {
// if year is defined check year
$regex = '/[0-9]{4}?/'; // matches year of string
for ($i = 0; $i < count($reply->results); $i++) {
$releasedate = $reply->results[$i]->release_date;
preg_match($regex, $releasedate, $matches);
if (count($matches) > 0) {
$curryear = $matches[0];
if ($curryear == $year)
return $reply->results[$i];
}
}
} else {
return $reply->results[0];
}