From b46dc1feb11695224f301d5c7807ba8a0732fb15 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 20 Aug 2023 16:08:38 -0700 Subject: [PATCH] Use mark_state instead of direct sql so that object state updates. --- frontends/ycdl_flask/backend/common.py | 5 +---- frontends/ycdl_flask/templates/channel.html | 1 + ycdl/objects.py | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/frontends/ycdl_flask/backend/common.py b/frontends/ycdl_flask/backend/common.py index a837c4f..e85da64 100644 --- a/frontends/ycdl_flask/backend/common.py +++ b/frontends/ycdl_flask/backend/common.py @@ -151,10 +151,7 @@ def ignore_shorts_thread(rate): is_shorts = ycdl.ytapi.video_is_shorts(video.id) except Exception as exc: log.warning(traceback.format_exc()) - pairs = {'id': video.id, 'is_shorts': int(is_shorts)} - if is_shorts: - pairs['state'] = 'ignored' - ycdldb.update(table=ycdl.objects.Video, pairs=pairs, where_key='id') + video.mark_state('ignored') time.sleep(rate) def start_refresher_thread(rate): diff --git a/frontends/ycdl_flask/templates/channel.html b/frontends/ycdl_flask/templates/channel.html index a84943c..ac937be 100644 --- a/frontends/ycdl_flask/templates/channel.html +++ b/frontends/ycdl_flask/templates/channel.html @@ -195,6 +195,7 @@ https://stackoverflow.com/a/35153397 {{video.published_string}} - {{video.title}} ({{video.duration | seconds_to_hms}}) ({{video.views}}) + {% if video.is_shorts %}(shorts){% endif %} {% if channel is none %} ({{video.author.name if video.author else video.author_id}}) (p) {% endif %} diff --git a/ycdl/objects.py b/ycdl/objects.py index 2785a88..16fe3aa 100644 --- a/ycdl/objects.py +++ b/ycdl/objects.py @@ -357,6 +357,7 @@ class Video(ObjectBase): self.thumbnail = db_row['thumbnail'] self.live_broadcast = db_row['live_broadcast'] self.state = db_row['state'] + self.is_shorts = None if db_row['is_shorts'] is None else bool(db_row['is_shorts']) def __repr__(self): return f'Video:{self.id}'