Skip to content

Commit

Permalink
Fix subscriptions new video count when there are deleted videos
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
user234683 committed Feb 27, 2020
1 parent c6fe9b8 commit af334a8
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions youtube/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,22 +531,19 @@ def find_element(base, tag_name):
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())
Expand Down

0 comments on commit af334a8

Please sign in to comment.