Files
vrobbler/vrobbler/apps/videos/metadata.py
Colin Powell 5ca22efeaa [videos] Fix full metadata from OMDB
We were missing the series and episode number info.
2026-06-07 09:58:28 -04:00

90 lines
2.4 KiB
Python

import logging
from enum import Enum
from typing import Optional
logger = logging.getLogger(__name__)
YOUTUBE_VIDEO_URL = "https://www.youtube.com/watch?v="
IMDB_VIDEO_URL = "https://www.imdb.com/title"
class VideoType(Enum):
UNKNOWN = "U"
TV_EPISODE = "E"
MOVIE = "M"
SKATE_VIDEO = "S"
YOUTUBE = "Y"
TWITCH = "T"
@classmethod
def as_choices(cls) -> tuple:
return tuple((i.name, i.value) for i in cls)
class VideoMetadata:
"""
A metadata model for our Video model.
VideoMetadata is a bridge model between our various sources and
our database model. Because there are some fields that are not easily
represented on database-backed models (covers, channels, series, etc)
this model allows us to temporarly store and do rational things with
those fields around our base Video model.
"""
title: str
video_type: VideoType = VideoType.UNKNOWN
base_run_time_seconds: int = (
60 # Silly default, but things break if this is 0 or null
)
imdb_id: Optional[str]
tmdb_id: Optional[str]
youtube_id: Optional[str]
twitch_id: Optional[str]
# IMDB specific
episode_number: Optional[str]
season_number: Optional[str]
next_imdb_id: Optional[str]
year: Optional[int]
tv_series_id: Optional[int]
plot: Optional[str]
imdb_rating: Optional[str]
tmdb_rating: Optional[str]
cover_url: Optional[str]
overview: Optional[str]
# YouTube specific
channel_id: Optional[int]
# Twitch specific
upload_date: Optional[str]
# General
cover_url: Optional[str]
genres: list[str]
def __init__(
self,
imdb_id: Optional[str] = "",
youtube_id: Optional[str] = "",
twitch_id: Optional[str] = "",
base_run_time_seconds: int = 900,
):
self.title = ""
self.imdb_id = imdb_id
self.youtube_id = youtube_id
self.twitch_id = twitch_id
self.base_run_time_seconds = base_run_time_seconds
def as_dict_with_cover_and_genres(self) -> tuple:
video_dict = vars(self)
series_id = ""
cover = None
if "cover_url" in video_dict.keys():
cover = video_dict.pop("cover_url", "")
genres = video_dict.pop("genres", [])
if "tv_series_imdb_id" in video_dict.keys():
series_id = video_dict.pop("tv_series_imdb_id")
return video_dict, series_id, cover, genres