Skip to content

Commit 9e0d530

Browse files
authored
Merge pull request #1156 from tcely/patch-5
Better handling of missing tabs
2 parents 75088d3 + 7bbb5ba commit 9e0d530

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

tubesync/sync/models/source.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from django.utils import timezone
1111
from django.utils.text import slugify
1212
from django.utils.translation import gettext_lazy as _
13+
from yt_dlp import DownloadError
1314
from ..choices import (Val,
1415
SponsorBlock_Category, YouTube_SourceType, IndexSchedule,
1516
CapChoices, Fallback, FileExtension, FilterSeconds,
@@ -436,21 +437,21 @@ def extension(self):
436437
return Val(FileExtension.MKV)
437438

438439
@classmethod
439-
def create_url(cls, source_type, key):
440+
def create_url(cls, source_type, url_key):
440441
url = cls.URLS.get(source_type)
441-
return url.format(key=key)
442+
return url.format(key=url_key)
442443

443444
@classmethod
444-
def create_index_url(cls, source_type, key, type):
445+
def create_index_url(cls, source_type, url_key, url_type):
445446
url = cls.INDEX_URLS.get(source_type)
446-
return url.format(key=key, type=type)
447+
return url.format(key=url_key, type=url_type)
447448

448449
@property
449450
def url(self):
450451
return self.__class__.create_url(self.source_type, self.key)
451452

452-
def get_index_url(self, type):
453-
return self.__class__.create_index_url(self.source_type, self.key, type)
453+
def get_index_url(self, url_type, /):
454+
return self.__class__.create_index_url(self.source_type, url_key=self.key, url_type=url_type)
454455

455456
@property
456457
def format_summary(self):
@@ -560,17 +561,24 @@ def is_regex_match(self, media_item_title):
560561
return True
561562
return bool(re.search(self.filter_text, media_item_title))
562563

563-
def get_index(self, type):
564+
def get_index(self, url_type, /):
564565
indexer = self.INDEXERS.get(self.source_type, None)
565566
if not callable(indexer):
566567
raise Exception(f'Source type f"{self.source_type}" has no indexer')
567568
days = None
568569
if self.download_cap_date:
569570
days = timezone.timedelta(seconds=self.download_cap).days
570-
response = indexer(self.get_index_url(type=type), days=days)
571-
if not isinstance(response, dict):
572-
return list()
573-
entries = response.get('entries', list())
571+
entries = list()
572+
try:
573+
response = indexer(self.get_index_url(url_type), days=days)
574+
except DownloadError as e:
575+
if str(e).endswith(f': This channel does not have a {url_type} tab'):
576+
return entries
577+
raise
578+
else:
579+
if not isinstance(response, dict):
580+
return entries
581+
entries = response.get('entries', list())
574582
return entries
575583

576584
def index_media(self):
@@ -579,7 +587,8 @@ def index_media(self):
579587
'''
580588
entries = queue(list(), getattr(settings, 'MAX_ENTRIES_PROCESSING', 0) or None)
581589
if self.index_videos:
582-
entries.extend(reversed(self.get_index('videos')))
590+
videos = self.get_index('videos')
591+
entries.extend(reversed(videos))
583592

584593
# Playlists do something different that I have yet to figure out
585594
if not self.is_playlist:

0 commit comments

Comments
 (0)