Skip to content

Commit f9dfffe

Browse files
authored
Merge pull request #305 from biolds/misc
Misc fixes
2 parents 0845a66 + 419c4c5 commit f9dfffe

File tree

4 files changed

+56
-52
lines changed

4 files changed

+56
-52
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Generated by Django 3.2.15 on 2022-12-28 20:33
2+
3+
import django.core.files.storage
4+
from django.conf import settings
5+
from django.db import migrations, models
6+
import sync.models
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('sync', '0013_fix_elative_media_file'),
13+
]
14+
15+
operations = [
16+
migrations.AlterField(
17+
model_name='media',
18+
name='media_file',
19+
field=models.FileField(blank=True, help_text='Media file', max_length=255, null=True, storage=django.core.files.storage.FileSystemStorage(base_url='/media-data/', location=str(settings.DOWNLOAD_ROOT)), upload_to=sync.models.get_media_file_path, verbose_name='media file'),
20+
),
21+
]

tubesync/sync/models.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,11 @@ def index_media(self):
477477
response = indexer(self.index_url)
478478
if not isinstance(response, dict):
479479
return []
480-
return response.get('entries', [])
480+
entries = response.get('entries', [])
481+
482+
if settings.MAX_ENTRIES_PROCESSING:
483+
entries = entries[:settings.MAX_ENTRIES_PROCESSING]
484+
return entries
481485

482486

483487
def get_media_thumb_path(instance, filename):
@@ -866,7 +870,7 @@ def get_display_format(self, format_str):
866870
# Otherwise, calculate from matched format codes
867871
vformat = None
868872
aformat = None
869-
if '+' in format_str:
873+
if format_str and '+' in format_str:
870874
# Seperate audio and video streams
871875
vformat_code, aformat_code = format_str.split('+')
872876
vformat = self.get_format_by_code(vformat_code)
@@ -875,7 +879,7 @@ def get_display_format(self, format_str):
875879
# Combined stream or audio only
876880
cformat = self.get_format_by_code(format_str)
877881
aformat = cformat
878-
if cformat['vcodec']:
882+
if cformat and cformat['vcodec']:
879883
# Combined
880884
vformat = cformat
881885
if vformat:
@@ -1266,7 +1270,7 @@ def index_metadata(self):
12661270
'''
12671271
indexer = self.INDEXERS.get(self.source.source_type, None)
12681272
if not callable(indexer):
1269-
raise Exception(f'Meida with source type f"{self.source.source_type}" '
1273+
raise Exception(f'Media with source type f"{self.source.source_type}" '
12701274
f'has no indexer')
12711275
return indexer(self.url)
12721276

tubesync/sync/views.py

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,7 @@ def get_success_url(self):
269269
return append_uri_params(url, fields)
270270

271271

272-
class AddSourceView(CreateView):
273-
'''
274-
Adds a new source, optionally takes some initial data querystring values to
275-
prepopulate some of the more unclear values.
276-
'''
277-
278-
template_name = 'sync/source-add.html'
272+
class EditSourceMixin:
279273
model = Source
280274
fields = ('source_type', 'key', 'name', 'directory', 'media_format',
281275
'index_schedule', 'download_media', 'download_cap', 'delete_old_media',
@@ -287,6 +281,29 @@ class AddSourceView(CreateView):
287281
'this page for valid media name variables'),
288282
}
289283

284+
def form_valid(self, form):
285+
# Perform extra validation to make sure the media_format is valid
286+
obj = form.save(commit=False)
287+
source_type = form.cleaned_data['media_format']
288+
example_media_file = obj.get_example_media_format()
289+
if example_media_file == '':
290+
form.add_error(
291+
'media_format',
292+
ValidationError(self.errors['invalid_media_format'])
293+
)
294+
if form.errors:
295+
return super().form_invalid(form)
296+
return super().form_valid(form)
297+
298+
299+
class AddSourceView(EditSourceMixin, CreateView):
300+
'''
301+
Adds a new source, optionally takes some initial data querystring values to
302+
prepopulate some of the more unclear values.
303+
'''
304+
305+
template_name = 'sync/source-add.html'
306+
290307
def __init__(self, *args, **kwargs):
291308
self.prepopulated_data = {}
292309
super().__init__(*args, **kwargs)
@@ -312,20 +329,6 @@ def get_initial(self):
312329
initial[k] = v
313330
return initial
314331

315-
def form_valid(self, form):
316-
# Perform extra validation to make sure the media_format is valid
317-
obj = form.save(commit=False)
318-
source_type = form.cleaned_data['media_format']
319-
example_media_file = obj.get_example_media_format()
320-
if example_media_file == '':
321-
form.add_error(
322-
'media_format',
323-
ValidationError(self.errors['invalid_media_format'])
324-
)
325-
if form.errors:
326-
return super().form_invalid(form)
327-
return super().form_valid(form)
328-
329332
def get_success_url(self):
330333
url = reverse_lazy('sync:source', kwargs={'pk': self.object.pk})
331334
return append_uri_params(url, {'message': 'source-created'})
@@ -364,33 +367,9 @@ def get_context_data(self, *args, **kwargs):
364367
return data
365368

366369

367-
class UpdateSourceView(UpdateView):
370+
class UpdateSourceView(EditSourceMixin, UpdateView):
368371

369372
template_name = 'sync/source-update.html'
370-
model = Source
371-
fields = ('source_type', 'key', 'name', 'directory', 'media_format',
372-
'index_schedule', 'download_media', 'download_cap', 'delete_old_media',
373-
'days_to_keep', 'source_resolution', 'source_vcodec', 'source_acodec',
374-
'prefer_60fps', 'prefer_hdr', 'fallback', 'copy_thumbnails', 'write_nfo', 'write_json')
375-
errors = {
376-
'invalid_media_format': _('Invalid media format, the media format contains '
377-
'errors or is empty. Check the table at the end of '
378-
'this page for valid media name variables'),
379-
}
380-
381-
def form_valid(self, form):
382-
# Perform extra validation to make sure the media_format is valid
383-
obj = form.save(commit=False)
384-
source_type = form.cleaned_data['media_format']
385-
example_media_file = obj.get_example_media_format()
386-
if example_media_file == '':
387-
form.add_error(
388-
'media_format',
389-
ValidationError(self.errors['invalid_media_format'])
390-
)
391-
if form.errors:
392-
return super().form_invalid(form)
393-
return super().form_valid(form)
394373

395374
def get_success_url(self):
396375
url = reverse_lazy('sync:source', kwargs={'pk': self.object.pk})
@@ -416,7 +395,7 @@ def post(self, request, *args, **kwargs):
416395
for media in Media.objects.filter(source=source):
417396
if media.media_file:
418397
# Delete the media file
419-
delete_file(media.media_file.name)
398+
delete_file(media.media_file.path)
420399
# Delete thumbnail copy if it exists
421400
delete_file(media.thumbpath)
422401
# Delete NFO file if it exists

tubesync/tubesync/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
MAX_BACKGROUND_TASK_ASYNC_THREADS = 8 # For sanity reasons
139139
BACKGROUND_TASK_PRIORITY_ORDERING = 'ASC' # Use 'niceness' task priority ordering
140140
COMPLETED_TASKS_DAYS_TO_KEEP = 7 # Number of days to keep completed tasks
141-
141+
MAX_ENTRIES_PROCESSING = 0 # Number of videos to process on source refresh (0 for no limit)
142142

143143
SOURCES_PER_PAGE = 100
144144
MEDIA_PER_PAGE = 144

0 commit comments

Comments
 (0)