Skip to content

Commit

Permalink
fix import and get cover only when series/movies are newly created
Browse files Browse the repository at this point in the history
  • Loading branch information
DerouineauNicolas committed Jun 18, 2024
1 parent 283b912 commit f533403
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions backend/StreamServerApp/database_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from StreamingServer import settings

import logging
from enum import Enum

logger = logging.getLogger("root")

Expand Down Expand Up @@ -144,6 +145,10 @@ def update_db_from_local_folder(base_path, remote_url, keep_files=False, async_u
cache.set("processing_state", "finished", timeout=None)
cache.delete("processing_file")

class Add_video_return_value(Enum):
NO_SERIES_MOVIES_CREATED = 0
MOVIE_CREATED = 1
SERIES_CREATED = 2

@shared_task
def add_one_video_to_database(full_path,
Expand Down Expand Up @@ -211,18 +216,22 @@ def add_one_video_to_database(full_path,
v.episode = video_type_and_info['episode']

if created:
return_value = 2
return_value = Add_video_return_value.SERIES_CREATED

elif video_type_and_info['type'] == 'Movie':
movie, created = Movie.objects.get_or_create(
title=video_type_and_info['title'])
v.movie = movie

if created:
return_value = 1
return_value = Add_video_return_value.MOVIE_CREATED

v.save()
download_cover_async.delay(v.id, video_type_and_info['title'], True if video_type_and_info['type'] == 'Series' else False)
if os.getenv('TMBD_KEY'):
if return_value in [Add_video_return_value.SERIES_CREATED, Add_video_return_value.MOVIE_CREATED]:
download_cover_async.delay(
v.id, video_type_and_info['title'], True if video_type_and_info['type'] == 'Series' else False)

for ov_subtitle_path in video_infos["ov_subtitles"]:
ov_sub = Subtitle()
webvtt_subtitles_relative_path = os.path.relpath(
Expand Down
2 changes: 1 addition & 1 deletion backend/StreamServerApp/tasks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from celery import shared_task
from StreamServerApp.models import Video, Series, Movie, Subtitle
from django.conf import settings
from media_management.cover_downloader import download_cover
from StreamServerApp.media_management.cover_downloader import download_cover

import logging

Expand Down

0 comments on commit f533403

Please sign in to comment.