Move logic to separate function normalize_autorefresh.
This commit is contained in:
parent
ec402dcd0b
commit
5f5d8141f1
1 changed files with 11 additions and 7 deletions
|
@ -48,6 +48,16 @@ class Channel(Base):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'Channel:{self.id}'
|
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
|
@staticmethod
|
||||||
def normalize_download_directory(
|
def normalize_download_directory(
|
||||||
download_directory,
|
download_directory,
|
||||||
|
@ -209,13 +219,7 @@ class Channel(Base):
|
||||||
self.ycdldb.commit()
|
self.ycdldb.commit()
|
||||||
|
|
||||||
def set_autorefresh(self, autorefresh, commit=True):
|
def set_autorefresh(self, autorefresh, commit=True):
|
||||||
if isinstance(autorefresh, int):
|
autorefresh = self.normalize_autorefresh(autorefresh)
|
||||||
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}.')
|
|
||||||
|
|
||||||
pairs = {
|
pairs = {
|
||||||
'id': self.id,
|
'id': self.id,
|
||||||
|
|
Loading…
Reference in a new issue