From d08415eaad2f1e50f524f3fe98d5e03315f114db Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 25 Oct 2021 13:20:05 -0700 Subject: [PATCH] Add assert_valid_state so I can stop copypasting this code. --- ycdl/objects.py | 6 ++---- ycdl/ycdldb.py | 9 +++++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ycdl/objects.py b/ycdl/objects.py index 035b021..a9452a9 100644 --- a/ycdl/objects.py +++ b/ycdl/objects.py @@ -215,8 +215,7 @@ class Channel(ObjectBase): @worms.transaction def set_automark(self, state): - if state not in constants.VIDEO_STATES: - raise exceptions.InvalidVideoState(state) + self.ycdldb.assert_valid_state(state) pairs = { 'id': self.id, @@ -339,8 +338,7 @@ class Video(ObjectBase): Note: Marking as downloaded will not create the queue file, this only updates the database. See yclddb.download_video. ''' - if state not in constants.VIDEO_STATES: - raise exceptions.InvalidVideoState(state) + self.ycdldb.assert_valid_state(state) log.info('Marking %s as %s.', self, state) diff --git a/ycdl/ycdldb.py b/ycdl/ycdldb.py index d186d8f..9c65617 100644 --- a/ycdl/ycdldb.py +++ b/ycdl/ycdldb.py @@ -45,8 +45,7 @@ class YCDLDBChannelMixin: except exceptions.NoSuchChannel: pass - if automark not in constants.VIDEO_STATES: - raise exceptions.InvalidVideoState(automark) + self.assert_valid_state(automark) name = objects.Channel.normalize_name(name) if name is None: @@ -223,6 +222,7 @@ class YCDLDBVideoMixin: bindings.append(channel_id) if state is not None: + self.assert_valid_state(state) wheres.append('state') bindings.append(state) @@ -471,6 +471,11 @@ class YCDLDB( log.debug('Found closest YCDLDB at %s.', path) return ycdldb + @staticmethod + def assert_valid_state(state): + if state not in constants.VIDEO_STATES: + raise exceptions.InvalidVideoState(state) + def get_all_states(self): ''' Get a list of all the different states that are currently in use in