refactoring, test suite for sync app
This commit is contained in:
parent
195a1bef4d
commit
60a726bb7c
|
@ -51,7 +51,7 @@ def get_best_audio_format(media):
|
|||
audio_formats = []
|
||||
for fmt in media.iter_formats():
|
||||
# If the format has a video stream, skip it
|
||||
if fmt['vcodec']:
|
||||
if fmt['vcodec'] is not None:
|
||||
continue
|
||||
audio_formats.append(fmt)
|
||||
audio_formats = list(reversed(sorted(audio_formats, key=lambda k: k['abr'])))
|
||||
|
@ -86,7 +86,7 @@ def get_best_video_format(media):
|
|||
video_formats = []
|
||||
for fmt in media.iter_formats():
|
||||
# If the format has an audio stream, skip it
|
||||
if fmt['acodec']:
|
||||
if fmt['acodec'] is not None:
|
||||
continue
|
||||
if media.source.source_resolution.strip().upper() == fmt['format']:
|
||||
video_formats.append(fmt)
|
||||
|
@ -97,7 +97,7 @@ def get_best_video_format(media):
|
|||
# Find the next-best format matches by height
|
||||
for fmt in media.iter_formats():
|
||||
# If the format has an audio stream, skip it
|
||||
if fmt['acodec']:
|
||||
if fmt['acodec'] is not None:
|
||||
continue
|
||||
if (fmt['height'] <= media.source.source_resolution_height and
|
||||
fmt['height'] >= min_height):
|
||||
|
@ -106,8 +106,6 @@ def get_best_video_format(media):
|
|||
# Can't fallback
|
||||
return False, False
|
||||
video_formats = list(reversed(sorted(video_formats, key=lambda k: k['height'])))
|
||||
print('height', media.source.source_resolution_height)
|
||||
print('video_formats', video_formats)
|
||||
if not video_formats:
|
||||
# Still no matches
|
||||
return False, False
|
||||
|
|
|
@ -6,8 +6,8 @@ from background_task.signals import task_failed
|
|||
from background_task.models import Task
|
||||
from common.logger import log
|
||||
from .models import Source, Media
|
||||
from .tasks import (delete_index_source_task, index_source_task,
|
||||
download_media_thumbnail, map_task_to_instance)
|
||||
from .tasks import (delete_task, index_source_task, download_media_thumbnail,
|
||||
map_task_to_instance)
|
||||
from .utils import delete_file
|
||||
|
||||
|
||||
|
@ -22,7 +22,7 @@ def source_pre_save(sender, instance, **kwargs):
|
|||
return
|
||||
if existing_source.index_schedule != instance.index_schedule:
|
||||
# Indexing schedule has changed, recreate the indexing task
|
||||
delete_index_source_task(str(instance.pk))
|
||||
delete_task('sync.tasks.index_source_task', instance.pk)
|
||||
verbose_name = _('Index media from source "{}"')
|
||||
index_source_task(
|
||||
str(instance.pk),
|
||||
|
@ -37,7 +37,7 @@ def source_post_save(sender, instance, created, **kwargs):
|
|||
# Triggered after a source is saved
|
||||
if created:
|
||||
# Create a new indexing task for newly created sources
|
||||
delete_index_source_task(str(instance.pk))
|
||||
delete_task('sync.tasks.index_source_task', instance.pk)
|
||||
log.info(f'Scheduling media indexing for source: {instance.name}')
|
||||
verbose_name = _('Index media from source "{}"')
|
||||
index_source_task(
|
||||
|
@ -61,7 +61,7 @@ def source_pre_delete(sender, instance, **kwargs):
|
|||
def source_post_delete(sender, instance, **kwargs):
|
||||
# Triggered after a source is deleted
|
||||
log.info(f'Deleting tasks for source: {instance.name}')
|
||||
delete_index_source_task(str(instance.pk))
|
||||
delete_task('sync.tasks.index_source_task', instance.pk)
|
||||
|
||||
|
||||
@receiver(task_failed, sender=Task)
|
||||
|
@ -93,9 +93,12 @@ def media_post_save(sender, instance, created, **kwargs):
|
|||
)
|
||||
|
||||
|
||||
@receiver(post_delete, sender=Media)
|
||||
def media_post_delete(sender, instance, **kwargs):
|
||||
# Triggered after media is deleted, delete media thumbnail
|
||||
@receiver(pre_delete, sender=Media)
|
||||
def media_pre_delete(sender, instance, **kwargs):
|
||||
# Triggered before media is deleted, delete any scheduled tasks
|
||||
log.info(f'Deleting tasks for media: {instance.name}')
|
||||
delete_task('sync.tasks.download_media_thumbnail', instance.source.pk)
|
||||
# Delete media thumbnail if it exists
|
||||
if instance.thumb:
|
||||
log.info(f'Deleting thumbnail for: {instance} path: {instance.thumb.path}')
|
||||
delete_file(instance.thumb.path)
|
||||
|
|
|
@ -110,8 +110,8 @@ def get_source_completed_tasks(source_id, only_errors=False):
|
|||
return CompletedTask.objects.filter(**q).order_by('-failed_at')
|
||||
|
||||
|
||||
def delete_index_source_task(source_id):
|
||||
Task.objects.drop_task('sync.tasks.index_source_task', args=(source_id,))
|
||||
def delete_task(task_name, source_id):
|
||||
return Task.objects.filter(task_name=task_name, queue=str(source_id)).delete()
|
||||
|
||||
|
||||
def cleanup_completed_tasks():
|
||||
|
|
1735
app/sync/tests.py
1735
app/sync/tests.py
File diff suppressed because it is too large
Load Diff
|
@ -51,7 +51,7 @@ urlpatterns = [
|
|||
MediaThumbView.as_view(),
|
||||
name='media-thumb'),
|
||||
|
||||
path('media-item/<uuid:pk>',
|
||||
path('media/<uuid:pk>',
|
||||
MediaItemView.as_view(),
|
||||
name='media-item'),
|
||||
|
||||
|
|
|
@ -153,6 +153,11 @@ def parse_media_format(format_dict):
|
|||
fps = 0
|
||||
format_full = format_dict.get('format_note', '').strip().upper()
|
||||
format_str = format_full[:-2] if format_full.endswith('60') else format_full
|
||||
format_str = format_str.strip()
|
||||
format_str = format_full[:-3] if format_full.endswith('HDR') else format_full
|
||||
format_str = format_str.strip()
|
||||
format_str = format_full[:-2] if format_full.endswith('60') else format_full
|
||||
format_str = format_str.strip()
|
||||
return {
|
||||
'id': format_dict.get('format_id', ''),
|
||||
'format': format_str,
|
||||
|
|
|
@ -109,7 +109,7 @@ class ValidateSourceView(FormView):
|
|||
'scheme': 'https',
|
||||
'domain': 'www.youtube.com',
|
||||
'path_regex': '^\/(c\/)?([^\/]+)$',
|
||||
'path_must_not_match': ('/playlist',),
|
||||
'path_must_not_match': ('/playlist', '/c/playlist'),
|
||||
'qs_args': [],
|
||||
'extract_key': ('path_regex', 1),
|
||||
'example': 'https://www.youtube.com/SOMECHANNEL'
|
||||
|
|
Loading…
Reference in New Issue