mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-25 22:46:34 +00:00
Try refresh_formats
for NoFormatException
This commit is contained in:
parent
3207f85e08
commit
ee00cffd76
@ -24,12 +24,13 @@ from background_task import background
|
|||||||
from background_task.exceptions import InvalidTaskError
|
from background_task.exceptions import InvalidTaskError
|
||||||
from background_task.models import Task, CompletedTask
|
from background_task.models import Task, CompletedTask
|
||||||
from common.logger import log
|
from common.logger import log
|
||||||
from common.errors import NoMediaException, NoMetadataException, DownloadFailedException
|
from common.errors import ( NoFormatException, NoMediaException,
|
||||||
|
NoMetadataException, DownloadFailedException, )
|
||||||
from common.utils import json_serial, remove_enclosed
|
from common.utils import json_serial, remove_enclosed
|
||||||
from .choices import Val, TaskQueue
|
from .choices import Val, TaskQueue
|
||||||
from .models import Source, Media, MediaServer
|
from .models import Source, Media, MediaServer
|
||||||
from .utils import (get_remote_image, resize_image_to_height, delete_file,
|
from .utils import ( get_remote_image, resize_image_to_height, delete_file,
|
||||||
write_text_file, filter_response)
|
write_text_file, filter_response, )
|
||||||
from .youtube import YouTubeError
|
from .youtube import YouTubeError
|
||||||
|
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ def map_task_to_instance(task):
|
|||||||
'sync.tasks.download_media': Media,
|
'sync.tasks.download_media': Media,
|
||||||
'sync.tasks.download_media_metadata': Media,
|
'sync.tasks.download_media_metadata': Media,
|
||||||
'sync.tasks.save_all_media_for_source': Source,
|
'sync.tasks.save_all_media_for_source': Source,
|
||||||
'sync.tasks.refesh_formats': Media,
|
'sync.tasks.refresh_formats': Media,
|
||||||
'sync.tasks.rename_media': Media,
|
'sync.tasks.rename_media': Media,
|
||||||
'sync.tasks.rename_all_media_for_source': Source,
|
'sync.tasks.rename_all_media_for_source': Source,
|
||||||
'sync.tasks.wait_for_media_premiere': Media,
|
'sync.tasks.wait_for_media_premiere': Media,
|
||||||
@ -566,9 +567,36 @@ def download_media(media_id):
|
|||||||
f'not downloading')
|
f'not downloading')
|
||||||
return
|
return
|
||||||
filepath = media.filepath
|
filepath = media.filepath
|
||||||
|
container = format_str = None
|
||||||
log.info(f'Downloading media: {media} (UUID: {media.pk}) to: "{filepath}"')
|
log.info(f'Downloading media: {media} (UUID: {media.pk}) to: "{filepath}"')
|
||||||
format_str, container = media.download_media()
|
try:
|
||||||
if os.path.exists(filepath):
|
format_str, container = media.download_media()
|
||||||
|
except NoFormatException as e:
|
||||||
|
# Try refreshing formats
|
||||||
|
if media.has_metadata:
|
||||||
|
log.debug(f'Scheduling a task to refresh metadata for: {media.key}: "{media.name}"')
|
||||||
|
refresh_formats(
|
||||||
|
str(media.pk),
|
||||||
|
verbose_name=f'Refreshing metadata formats for: {media.key}: "{media.name}"',
|
||||||
|
)
|
||||||
|
log.exception(str(e))
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
if not os.path.exists(filepath):
|
||||||
|
# Try refreshing formats
|
||||||
|
if media.has_metadata:
|
||||||
|
log.debug(f'Scheduling a task to refresh metadata for: {media.key}: "{media.name}"')
|
||||||
|
refresh_formats(
|
||||||
|
str(media.pk),
|
||||||
|
verbose_name=f'Refreshing metadata formats for: {media.key}: "{media.name}"',
|
||||||
|
)
|
||||||
|
# Expected file doesn't exist on disk
|
||||||
|
err = (f'Failed to download media: {media} (UUID: {media.pk}) to disk, '
|
||||||
|
f'expected outfile does not exist: {filepath}')
|
||||||
|
log.error(err)
|
||||||
|
# Raising an error here triggers the task to be re-attempted (or fail)
|
||||||
|
raise DownloadFailedException(err)
|
||||||
|
|
||||||
# Media has been downloaded successfully
|
# Media has been downloaded successfully
|
||||||
log.info(f'Successfully downloaded media: {media} (UUID: {media.pk}) to: '
|
log.info(f'Successfully downloaded media: {media} (UUID: {media.pk}) to: '
|
||||||
f'"{filepath}"')
|
f'"{filepath}"')
|
||||||
@ -630,16 +658,6 @@ def download_media(media_id):
|
|||||||
pass
|
pass
|
||||||
# Schedule a task to update media servers
|
# Schedule a task to update media servers
|
||||||
schedule_media_servers_update()
|
schedule_media_servers_update()
|
||||||
else:
|
|
||||||
# Expected file doesn't exist on disk
|
|
||||||
err = (f'Failed to download media: {media} (UUID: {media.pk}) to disk, '
|
|
||||||
f'expected outfile does not exist: {filepath}')
|
|
||||||
log.error(err)
|
|
||||||
# Try refreshing formats
|
|
||||||
if media.has_metadata:
|
|
||||||
media.refresh_formats
|
|
||||||
# Raising an error here triggers the task to be re-attempted (or fail)
|
|
||||||
raise DownloadFailedException(err)
|
|
||||||
|
|
||||||
|
|
||||||
@background(schedule=dict(priority=0, run_at=30), queue=Val(TaskQueue.NET), remove_existing_tasks=True)
|
@background(schedule=dict(priority=0, run_at=30), queue=Val(TaskQueue.NET), remove_existing_tasks=True)
|
||||||
@ -692,7 +710,7 @@ def save_all_media_for_source(source_id):
|
|||||||
tvn_format = '1/{:,}' + f'/{refresh_qs.count():,}'
|
tvn_format = '1/{:,}' + f'/{refresh_qs.count():,}'
|
||||||
for mn, media in enumerate(refresh_qs, start=1):
|
for mn, media in enumerate(refresh_qs, start=1):
|
||||||
update_task_status(task, tvn_format.format(mn))
|
update_task_status(task, tvn_format.format(mn))
|
||||||
refesh_formats(
|
refresh_formats(
|
||||||
str(media.pk),
|
str(media.pk),
|
||||||
verbose_name=f'Refreshing metadata formats for: {media.key}: "{media.name}"',
|
verbose_name=f'Refreshing metadata formats for: {media.key}: "{media.name}"',
|
||||||
)
|
)
|
||||||
@ -711,7 +729,7 @@ def save_all_media_for_source(source_id):
|
|||||||
|
|
||||||
|
|
||||||
@background(schedule=dict(priority=10, run_at=0), queue=Val(TaskQueue.NET), remove_existing_tasks=True)
|
@background(schedule=dict(priority=10, run_at=0), queue=Val(TaskQueue.NET), remove_existing_tasks=True)
|
||||||
def refesh_formats(media_id):
|
def refresh_formats(media_id):
|
||||||
try:
|
try:
|
||||||
media = Media.objects.get(pk=media_id)
|
media = Media.objects.get(pk=media_id)
|
||||||
except Media.DoesNotExist as e:
|
except Media.DoesNotExist as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user