From 5f5d8141f11e9b75a0e0fb446f048c7a290d6586 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 15 Sep 2021 18:55:52 -0700 Subject: [PATCH] Move logic to separate function normalize_autorefresh. --- ycdl/objects.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ycdl/objects.py b/ycdl/objects.py index 7eaa9e3..be2a99d 100644 --- a/ycdl/objects.py +++ b/ycdl/objects.py @@ -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,