Move logic to separate function normalize_autorefresh.

This commit is contained in:
voussoir 2021-09-15 18:55:52 -07:00
parent ec402dcd0b
commit 5f5d8141f1
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -48,6 +48,16 @@ class Channel(Base):
def __repr__(self):
return f'Channel:{self.id}'
@staticmethod
def normalize_autorefresh(autorefresh):
if isinstance(autorefresh, (str, int)):
autorefresh = stringtools.truthystring(autorefresh, none_set={})
if not isinstance(autorefresh, bool):
raise TypeError(f'autorefresh should be a boolean, not {autorefresh}.')
return autorefresh
@staticmethod
def normalize_download_directory(
download_directory,
@ -209,13 +219,7 @@ class Channel(Base):
self.ycdldb.commit()
def set_autorefresh(self, autorefresh, commit=True):
if isinstance(autorefresh, int):
if autorefresh not in {0, 1}:
raise ValueError(f'autorefresh should be a boolean, not {autorefresh}.')
autorefresh = bool(autorefresh)
if not isinstance(autorefresh, bool):
raise TypeError(f'autorefresh should be a boolean, not {autorefresh}.')
autorefresh = self.normalize_autorefresh(autorefresh)
pairs = {
'id': self.id,