aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2020-02-27 11:21:42 -0800
committerJames Taylor <user234683@users.noreply.github.com>2020-02-27 11:21:42 -0800
commitaf334a8ac711cf8dd2c36cd770a51506979ae528 (patch)
tree6882627982d2e0dcb2b6a17951462b7f5f2ed9cf
parentc6fe9b8fc749a520f0157d62ff9dc471cb8883d0 (diff)
downloadyt-local-af334a8ac711cf8dd2c36cd770a51506979ae528.tar.lz
yt-local-af334a8ac711cf8dd2c36cd770a51506979ae528.tar.xz
yt-local-af334a8ac711cf8dd2c36cd770a51506979ae528.zip
Fix subscriptions new video count when there are deleted videos
It would be 30 since the old method looked to see where the latest video in the database is in the new batch of videos. New method finds the first video in the new batch which is in the database.
-rw-r--r--youtube/subscriptions.py29
1 files changed, 13 insertions, 16 deletions
diff --git a/youtube/subscriptions.py b/youtube/subscriptions.py
index 9298963..66490de 100644
--- a/youtube/subscriptions.py
+++ b/youtube/subscriptions.py
@@ -531,22 +531,19 @@ def _get_upstream_videos(channel_id):
with connection as cursor:
# calculate how many new videos there are
- row = cursor.execute('''SELECT video_id
- FROM videos
- INNER JOIN subscribed_channels ON videos.sql_channel_id = subscribed_channels.id
- WHERE yt_channel_id=?
- ORDER BY time_published DESC
- LIMIT 1''', [channel_id]).fetchone()
- if row is None:
- number_of_new_videos = len(videos)
- else:
- latest_video_id = row[0]
- index = 0
- for video in videos:
- if video['id'] == latest_video_id:
- break
- index += 1
- number_of_new_videos = index
+ existing_vids = set(row[0] for row in cursor.execute(
+ '''SELECT video_id
+ FROM videos
+ INNER JOIN subscribed_channels
+ ON videos.sql_channel_id = subscribed_channels.id
+ WHERE yt_channel_id=?
+ ORDER BY time_published DESC
+ LIMIT 30''', [channel_id]).fetchall())
+ number_of_new_videos = 0
+ for video in videos:
+ if video['id'] in existing_vids:
+ break
+ number_of_new_videos += 1
is_first_check = cursor.execute('''SELECT time_last_checked FROM subscribed_channels WHERE yt_channel_id=?''', [channel_id]).fetchone()[0] in (None, 0)
time_videos_retrieved = int(time.time())