From a0b867e20a34487ed76a48a76eb6c17215114aaa Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Wed, 18 Mar 2026 10:48:14 -0400 Subject: [PATCH] [videos] Clean up metadata enrichment --- vrobbler/apps/videos/metadata.py | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/vrobbler/apps/videos/metadata.py b/vrobbler/apps/videos/metadata.py index 709b95f..6f78f86 100644 --- a/vrobbler/apps/videos/metadata.py +++ b/vrobbler/apps/videos/metadata.py @@ -1,6 +1,9 @@ from enum import Enum from typing import Optional +from cinemagoerng import web as imdb +import logging +logger = logging.getLogger(__name__) YOUTUBE_VIDEO_URL = "https://www.youtube.com/watch?v=" IMDB_VIDEO_URL = "https://www.imdb.com/title" @@ -19,6 +22,16 @@ class VideoType(Enum): 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 = ( @@ -57,6 +70,39 @@ class VideoMetadata: self.youtube_id = youtube_id self.base_run_time_seconds = base_run_time_seconds + def enrich_from_imdb(self): + self.imdb_result: dict = {} + + self.imdb_result = imdb.get_title(self.imdb_id) + logger.debug(f"Found result from IMDB: {self.imdb_result.title}") + + if not self.imdb_result: + logger.info( + f"[enrich] no video found on imdb", + extra={"name_or_id": name_or_id}, + ) + return None + + self.base_run_time_seconds = self.imdb_result.runtime * 60 + self.imdb_id = self.imdb_id + self.title = self.imdb_result.title + self.year = self.imdb_result.year + self.plot = self.imdb_result.plot.get("en-US", "") + self.imdb_rating = self.imdb_result.rating + self.genres = self.imdb_result.genres + self.cover_url = self.imdb_result.primary_image + + self.video_type = VideoType.MOVIE.value + if self.imdb_result.type_id == "tvEpisode": + self.video_type = VideoType.TV_EPISODE.value + + series = self.imdb_result.series + self.tv_series_imdb_id = series.imdb_id + self.tv_series_title = series.title + self.episode_number = self.imdb_result.episode + self.season_number = self.imdb_result.season + self.next_imdb_id = self.imdb_result.next_episode_id + def as_dict_with_cover_and_genres(self) -> tuple: video_dict = vars(self) series_id = ""