2022-12-07 19:09:05 -05:00
|
|
|
from catalog.common import *
|
2022-12-08 05:53:00 +00:00
|
|
|
from .tmdb import search_tmdb_by_imdb_id
|
2022-12-07 19:09:05 -05:00
|
|
|
from catalog.movie.models import *
|
|
|
|
from catalog.tv.models import *
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
2022-12-08 16:59:03 +00:00
|
|
|
_logger = logging.getLogger(__name__)
|
2022-12-07 19:09:05 -05:00
|
|
|
|
|
|
|
|
2022-12-15 17:29:35 -05:00
|
|
|
@SiteManager.register
|
2022-12-07 19:09:05 -05:00
|
|
|
class IMDB(AbstractSite):
|
2022-12-16 01:08:10 -05:00
|
|
|
SITE_NAME = SiteName.IMDB
|
2022-12-07 19:09:05 -05:00
|
|
|
ID_TYPE = IdType.IMDB
|
2023-05-13 16:33:51 -04:00
|
|
|
URL_PATTERNS = [
|
|
|
|
r"\w+://www.imdb.com/title/(tt\d+)",
|
|
|
|
r"\w+://m.imdb.com/title/(tt\d+)",
|
|
|
|
]
|
2022-12-29 23:57:02 -05:00
|
|
|
WIKI_PROPERTY_ID = "?"
|
2022-12-07 19:09:05 -05:00
|
|
|
|
|
|
|
@classmethod
|
2023-01-08 16:26:05 -05:00
|
|
|
def id_to_url(cls, id_value):
|
2022-12-07 19:09:05 -05:00
|
|
|
return "https://www.imdb.com/title/" + id_value + "/"
|
|
|
|
|
|
|
|
def scrape(self):
|
|
|
|
self.scraped = False
|
2022-12-08 05:53:00 +00:00
|
|
|
res_data = search_tmdb_by_imdb_id(self.id_value)
|
2023-01-08 16:26:05 -05:00
|
|
|
if (
|
|
|
|
"movie_results" in res_data
|
|
|
|
and len(res_data["movie_results"]) > 0
|
|
|
|
and self.DEFAULT_MODEL in [None, Movie]
|
|
|
|
):
|
2022-12-29 23:57:02 -05:00
|
|
|
url = (
|
|
|
|
f"https://www.themoviedb.org/movie/{res_data['movie_results'][0]['id']}"
|
|
|
|
)
|
|
|
|
elif "tv_results" in res_data and len(res_data["tv_results"]) > 0:
|
2022-12-07 19:09:05 -05:00
|
|
|
url = f"https://www.themoviedb.org/tv/{res_data['tv_results'][0]['id']}"
|
2022-12-29 23:57:02 -05:00
|
|
|
elif "tv_season_results" in res_data and len(res_data["tv_season_results"]) > 0:
|
2022-12-07 19:09:05 -05:00
|
|
|
# this should not happen given IMDB only has ids for either show or episode
|
2022-12-29 23:57:02 -05:00
|
|
|
tv_id = res_data["tv_season_results"][0]["show_id"]
|
|
|
|
season_number = res_data["tv_season_results"][0]["season_number"]
|
2023-01-08 16:26:05 -05:00
|
|
|
url = f"https://www.themoviedb.org/tv/{tv_id}/season/{season_number}"
|
2022-12-29 23:57:02 -05:00
|
|
|
elif (
|
|
|
|
"tv_episode_results" in res_data and len(res_data["tv_episode_results"]) > 0
|
|
|
|
):
|
|
|
|
tv_id = res_data["tv_episode_results"][0]["show_id"]
|
|
|
|
season_number = res_data["tv_episode_results"][0]["season_number"]
|
|
|
|
episode_number = res_data["tv_episode_results"][0]["episode_number"]
|
2022-12-07 19:09:05 -05:00
|
|
|
if season_number == 0:
|
|
|
|
url = f"https://www.themoviedb.org/tv/{tv_id}/season/{season_number}/episode/{episode_number}"
|
|
|
|
elif episode_number == 1:
|
|
|
|
url = f"https://www.themoviedb.org/tv/{tv_id}/season/{season_number}"
|
|
|
|
else:
|
2022-12-29 23:57:02 -05:00
|
|
|
raise ParseError(
|
|
|
|
self,
|
|
|
|
"IMDB id matching TMDB but not first episode, this is not supported",
|
|
|
|
)
|
2022-12-07 19:09:05 -05:00
|
|
|
else:
|
|
|
|
raise ParseError(self, "IMDB id not found in TMDB")
|
2022-12-15 17:29:35 -05:00
|
|
|
tmdb = SiteManager.get_site_by_url(url)
|
2022-12-07 19:09:05 -05:00
|
|
|
pd = tmdb.scrape()
|
2022-12-29 23:57:02 -05:00
|
|
|
pd.metadata["preferred_model"] = tmdb.DEFAULT_MODEL.__name__
|
2022-12-07 19:09:05 -05:00
|
|
|
return pd
|