metadata.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from enum import Enum
  2. from typing import Optional
  3. YOUTUBE_VIDEO_URL = "https://www.youtube.com/watch?v="
  4. IMDB_VIDEO_URL = "https://www.imdb.com/title/tt"
  5. class VideoType(Enum):
  6. UNKNOWN = "U"
  7. TV_EPISODE = "E"
  8. MOVIE = "M"
  9. SKATE_VIDEO = "S"
  10. YOUTUBE = "Y"
  11. @classmethod
  12. def as_choices(cls) -> tuple:
  13. return tuple((i.name, i.value) for i in cls)
  14. class VideoMetadata:
  15. title: str
  16. video_type: VideoType = VideoType.UNKNOWN
  17. base_run_time_seconds: int = (
  18. 60 # Silly default, but things break if this is 0 or null
  19. )
  20. imdb_id: Optional[str]
  21. tmdb_id: Optional[str]
  22. youtube_id: Optional[str]
  23. # IMDB specific
  24. episode_number: Optional[str]
  25. season_number: Optional[str]
  26. next_imdb_id: Optional[str]
  27. year: Optional[int]
  28. tv_series_id: Optional[int]
  29. plot: Optional[str]
  30. imdb_rating: Optional[str]
  31. tmdb_rating: Optional[str]
  32. cover_url: Optional[str]
  33. overview: Optional[str]
  34. # YouTube specific
  35. channel_id: Optional[int]
  36. # General
  37. cover_url: Optional[str]
  38. genres: list[str]
  39. def __init__(
  40. self,
  41. imdb_id: Optional[str] = "",
  42. youtube_id: Optional[str] = "",
  43. base_run_time_seconds: int = 900,
  44. ):
  45. self.imdb_id = imdb_id
  46. self.youtube_id = youtube_id
  47. self.base_run_time_seconds = base_run_time_seconds
  48. def as_dict_with_cover_and_genres(self) -> tuple:
  49. video_dict = vars(self)
  50. series_id = ""
  51. cover = None
  52. if "cover_url" in video_dict.keys():
  53. cover = video_dict.pop("cover_url", "")
  54. genres = video_dict.pop("genres", [])
  55. if "tv_series_imdb_id" in video_dict.keys():
  56. series_id = video_dict.pop("tv_series_imdb_id")
  57. return video_dict, series_id, cover, genres