Add Channel.normalize_queuefile_extension.

This commit is contained in:
voussoir 2021-09-01 23:36:28 -07:00
parent 8c2aea06f3
commit 38299db102
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB
2 changed files with 24 additions and 9 deletions

View file

@ -1,4 +1,6 @@
import datetime import datetime
import typing
from . import constants from . import constants
from . import exceptions from . import exceptions
@ -34,12 +36,26 @@ class Channel(Base):
self.name = db_row['name'] self.name = db_row['name']
self.uploads_playlist = db_row['uploads_playlist'] self.uploads_playlist = db_row['uploads_playlist']
self.download_directory = db_row['download_directory'] self.download_directory = db_row['download_directory']
self.queuefile_extension = db_row['queuefile_extension'] self.queuefile_extension = self.normalize_queuefile_extension(db_row['queuefile_extension'])
self.automark = db_row['automark'] or "pending" self.automark = db_row['automark'] or 'pending'
def __repr__(self): def __repr__(self):
return f'Channel:{self.id}' return f'Channel:{self.id}'
@staticmethod
def normalize_queuefile_extension(queuefile_extension) -> typing.Optional[str]:
if queuefile_extension is None:
return None
if not isinstance(queuefile_extension, str):
raise TypeError(f'queuefile_extension should be {str}, not {type(queuefile_extension)}.')
queuefile_extension = queuefile_extension.strip()
if not queuefile_extension:
return None
return queuefile_extension
def _rss_assisted_videos(self): def _rss_assisted_videos(self):
''' '''
RSS-assisted refresh will use the channel's RSS feed to find videos RSS-assisted refresh will use the channel's RSS feed to find videos
@ -162,19 +178,16 @@ class Channel(Base):
if commit: if commit:
self.ycdldb.commit() self.ycdldb.commit()
def set_queuefile_extension(self, extension, commit=True):
if not extension:
extension = None
if extension is not None: def set_queuefile_extension(self, queuefile_extension, commit=True):
extension = extension.strip() queuefile_extension = self.normalize_queuefile_extension(queuefile_extension)
pairs = { pairs = {
'id': self.id, 'id': self.id,
'queuefile_extension': extension, 'queuefile_extension': queuefile_extension,
} }
self.ycdldb.sql_update(table='channels', pairs=pairs, where_key='id') self.ycdldb.sql_update(table='channels', pairs=pairs, where_key='id')
self.queuefile_extension = extension self.queuefile_extension = queuefile_extension
if commit: if commit:
self.ycdldb.commit() self.ycdldb.commit()

View file

@ -138,6 +138,8 @@ class YCDLDBChannelMixin:
if download_directory is not None: if download_directory is not None:
download_directory = pathclass.Path(download_directory).absolute_path download_directory = pathclass.Path(download_directory).absolute_path
queuefile_extension = objects.Channel.normalize_queuefile_extension(queuefile_extension)
self.log.info('Adding channel %s %s', channel_id, name) self.log.info('Adding channel %s %s', channel_id, name)
data = { data = {