BinaryONe commited on
Commit ·
3e7992c
1
Parent(s): 67e5eb9
Callback Update
Browse files
FileStream/APIs/TMDB/Endpoint.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
import urllib3
|
| 3 |
from .__init__ import tmdb,search,movie,tv
|
| 4 |
from FileStream.Tools.cleanup import Get_Title_Year
|
|
@@ -50,8 +50,62 @@ def search_tmdb_tv(name):
|
|
| 50 |
print("* Error at Endpoint", e, result)
|
| 51 |
return None
|
| 52 |
return None
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
# Search for the title in TMDb
|
| 56 |
title, year = Get_Title_Year(name)
|
| 57 |
#print("*", title, year,"\n Name :", name)
|
|
|
|
| 1 |
+
import logging
|
| 2 |
import urllib3
|
| 3 |
from .__init__ import tmdb,search,movie,tv
|
| 4 |
from FileStream.Tools.cleanup import Get_Title_Year
|
|
|
|
| 50 |
print("* Error at Endpoint", e, result)
|
| 51 |
return None
|
| 52 |
return None
|
| 53 |
+
|
| 54 |
+
import logging
|
| 55 |
+
from tmdbv3api import Search # Assuming you're using tmdbv3api
|
| 56 |
+
from FileStream.TMDB.Endpoint import get_tvshows # Assuming this is your function
|
| 57 |
+
|
| 58 |
+
# Create an instance of the Search class
|
| 59 |
+
search = Search()
|
| 60 |
+
|
| 61 |
+
def search_tmdb_any(title: str, year: int):
|
| 62 |
+
"""
|
| 63 |
+
Search for a movie or TV show on TMDb based on title and release year.
|
| 64 |
+
:param title: The name of the movie or TV show.
|
| 65 |
+
:param year: The release year.
|
| 66 |
+
:return: Matched TMDb result or None if no match is found.
|
| 67 |
+
"""
|
| 68 |
+
try:
|
| 69 |
+
# Validate inputs
|
| 70 |
+
if not isinstance(title, str) or not isinstance(year, int):
|
| 71 |
+
logging.warning("Invalid input: Title must be a string, and Year must be an integer.")
|
| 72 |
+
return None
|
| 73 |
+
|
| 74 |
+
# Perform a search query
|
| 75 |
+
search_results = search.multi(title)
|
| 76 |
+
if not search_results:
|
| 77 |
+
logging.info(f"No results found for '{title}' ({year})")
|
| 78 |
+
return None
|
| 79 |
+
|
| 80 |
+
# Iterate through the results and find a match by media type and year
|
| 81 |
+
for result in search_results:
|
| 82 |
+
try:
|
| 83 |
+
media_type = getattr(result, "media_type", None)
|
| 84 |
+
release_date = (
|
| 85 |
+
getattr(result, "release_date", None) or
|
| 86 |
+
getattr(result, "first_air_date", None)
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
if release_date and release_date.split('-')[0].isdigit():
|
| 90 |
+
result_year = int(release_date.split('-')[0])
|
| 91 |
+
|
| 92 |
+
if result_year == year:
|
| 93 |
+
if media_type == "tv":
|
| 94 |
+
return get_tvshows(getattr(result, "id", None))
|
| 95 |
+
elif media_type == "movie":
|
| 96 |
+
return result
|
| 97 |
+
|
| 98 |
+
except Exception as inner_error:
|
| 99 |
+
logging.error(f"Error processing result {result}: {inner_error}")
|
| 100 |
+
|
| 101 |
+
except Exception as e:
|
| 102 |
+
logging.error(f"Error in search_tmdb_any: {e}")
|
| 103 |
+
|
| 104 |
+
return None
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def search_tmdb_any_old(name):
|
| 109 |
# Search for the title in TMDb
|
| 110 |
title, year = Get_Title_Year(name)
|
| 111 |
#print("*", title, year,"\n Name :", name)
|