[videos] Add management command and fix lookup of series
This commit is contained in:
0
vrobbler/apps/videos/management/__init__.py
Normal file
0
vrobbler/apps/videos/management/__init__.py
Normal file
27
vrobbler/apps/videos/management/commands/find_video.py
Normal file
27
vrobbler/apps/videos/management/commands/find_video.py
Normal file
@ -0,0 +1,27 @@
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.core import serializers
|
||||
from videos.models import Video, Series, Channel
|
||||
import json
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Find or create a Video by ID and output it as JSON"
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument("video_id", type=str, help="The video ID to find or create")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
instance = Video.find_or_create(options.get("video_id", ""), overwrite=True)
|
||||
data = json.loads(serializers.serialize("json", [instance]))[0]
|
||||
|
||||
# --- Enrich with series model ---
|
||||
if instance.tv_series_id:
|
||||
series_instance = instance.tv_series
|
||||
series_json = json.loads(serializers.serialize("json", [series_instance]))[0]
|
||||
data["series"] = series_json # new nested field
|
||||
|
||||
if instance.channel_id:
|
||||
channel_instance = instance.channel
|
||||
channel_json = json.loads(serializers.serialize("json", [channel_instance]))[0]
|
||||
data["channel"] = channel_json # new nested field
|
||||
|
||||
self.stdout.write(json.dumps(data, indent=2))
|
||||
@ -348,8 +348,10 @@ class Video(ScrobblableMixin):
|
||||
setattr(video, k, v)
|
||||
video.save()
|
||||
|
||||
video.save_image_from_url(cover)
|
||||
video.genre.add(*genres)
|
||||
if cover:
|
||||
video.save_image_from_url(cover)
|
||||
if genres:
|
||||
video.genre.add(*genres)
|
||||
return video
|
||||
|
||||
@classmethod
|
||||
@ -369,7 +371,7 @@ class Video(ScrobblableMixin):
|
||||
setattr(video, k, v)
|
||||
|
||||
if series_id:
|
||||
video.tv_series = Series.find_or_create(imdb_id=series_id)
|
||||
video.tv_series = Series.find_or_create(imdb_id=series_id, overwrite=overwrite)
|
||||
|
||||
video.save()
|
||||
|
||||
|
||||
@ -24,11 +24,12 @@ def lookup_video_from_imdb(imdb_id: str) -> VideoMetadata:
|
||||
)
|
||||
return None
|
||||
|
||||
if imdb_result.type_id.lower() in ["movie", "tvepisode"]:
|
||||
video_metadata.base_run_time_seconds = (
|
||||
imdb_result.runtime * 60
|
||||
)
|
||||
video_metadata.imdb_id = imdb_id
|
||||
video_metadata.title = imdb_result.title
|
||||
video_metadata.base_run_time_seconds = (
|
||||
imdb_result.runtime * 60
|
||||
)
|
||||
video_metadata.year = imdb_result.year
|
||||
video_metadata.plot = imdb_result.plot.get("en-US", "")
|
||||
video_metadata.imdb_rating = imdb_result.rating
|
||||
|
||||
Reference in New Issue
Block a user