10
10
from django .utils import timezone
11
11
from django .utils .text import slugify
12
12
from django .utils .translation import gettext_lazy as _
13
+ from yt_dlp import DownloadError
13
14
from ..choices import (Val ,
14
15
SponsorBlock_Category , YouTube_SourceType , IndexSchedule ,
15
16
CapChoices , Fallback , FileExtension , FilterSeconds ,
@@ -436,21 +437,21 @@ def extension(self):
436
437
return Val (FileExtension .MKV )
437
438
438
439
@classmethod
439
- def create_url (cls , source_type , key ):
440
+ def create_url (cls , source_type , url_key ):
440
441
url = cls .URLS .get (source_type )
441
- return url .format (key = key )
442
+ return url .format (key = url_key )
442
443
443
444
@classmethod
444
- def create_index_url (cls , source_type , key , type ):
445
+ def create_index_url (cls , source_type , url_key , url_type ):
445
446
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 )
447
448
448
449
@property
449
450
def url (self ):
450
451
return self .__class__ .create_url (self .source_type , self .key )
451
452
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 )
454
455
455
456
@property
456
457
def format_summary (self ):
@@ -560,17 +561,24 @@ def is_regex_match(self, media_item_title):
560
561
return True
561
562
return bool (re .search (self .filter_text , media_item_title ))
562
563
563
- def get_index (self , type ):
564
+ def get_index (self , url_type , / ):
564
565
indexer = self .INDEXERS .get (self .source_type , None )
565
566
if not callable (indexer ):
566
567
raise Exception (f'Source type f"{ self .source_type } " has no indexer' )
567
568
days = None
568
569
if self .download_cap_date :
569
570
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 ())
574
582
return entries
575
583
576
584
def index_media (self ):
@@ -579,7 +587,8 @@ def index_media(self):
579
587
'''
580
588
entries = queue (list (), getattr (settings , 'MAX_ENTRIES_PROCESSING' , 0 ) or None )
581
589
if self .index_videos :
582
- entries .extend (reversed (self .get_index ('videos' )))
590
+ videos = self .get_index ('videos' )
591
+ entries .extend (reversed (videos ))
583
592
584
593
# Playlists do something different that I have yet to figure out
585
594
if not self .is_playlist :
0 commit comments