aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAstound <kirito@disroot.org>2024-01-22 06:03:16 +0800
committerAstound <kirito@disroot.org>2024-01-22 06:03:16 +0800
commit86bb312d6ddcea2992f7f5f6ac2b47203cd730ce (patch)
tree522c9463962511e1e4d6f7693fd1a33c1c8bc86b
parent964b99ea40c059b28c2c6166bb60514c980f9185 (diff)
downloadyt-local-86bb312d6ddcea2992f7f5f6ac2b47203cd730ce.tar.lz
yt-local-86bb312d6ddcea2992f7f5f6ac2b47203cd730ce.tar.xz
yt-local-86bb312d6ddcea2992f7f5f6ac2b47203cd730ce.zip
Subscriptions: Fix exceptions when videos are missing upload dates
E.g. line 548, AttributeError: 'NoneType' object has no attribute 'lower' When upload dates are unavailable, make ones up which give the correct video order
-rw-r--r--youtube/subscriptions.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/youtube/subscriptions.py b/youtube/subscriptions.py
index e37ac28..b5f3c83 100644
--- a/youtube/subscriptions.py
+++ b/youtube/subscriptions.py
@@ -568,13 +568,39 @@ def _get_upstream_videos(channel_id):
if video_item['id'] in times_published:
video_item['time_published'] = times_published[video_item['id']]
video_item['is_time_published_exact'] = True
- else:
+ elif video_item.get('time_published'):
video_item['is_time_published_exact'] = False
try:
video_item['time_published'] = youtube_timestamp_to_posix(video_item['time_published']) - i # subtract a few seconds off the videos so they will be in the right order
- except KeyError:
+ except Exception:
print(video_item)
+ else:
+ video_item['is_time_published_exact'] = False
+ video_item['time_published'] = None
+ video_item['channel_id'] = channel_id
+ if len(videos) > 1:
+ # Go back and fill in any videos that don't have a time published
+ # using the time published of the surrounding ones
+ for i in range(len(videos)-1):
+ if (videos[i+1]['time_published'] is None
+ and videos[i]['time_published'] is not None
+ ):
+ videos[i+1]['time_published'] = videos[i]['time_published'] - 1
+ for i in reversed(range(1,len(videos))):
+ if (videos[i-1]['time_published'] is None
+ and videos[i]['time_published'] is not None
+ ):
+ videos[i-1]['time_published'] = videos[i]['time_published'] + 1
+ # Special case: none of the videos have a time published.
+ # In this case, make something up
+ if videos and videos[0]['time_published'] is None:
+ assert all(v['time_published'] is None for v in videos)
+ now = time.time()
+ for i in range(len(videos)):
+ # 1 month between videos
+ videos[i]['time_published'] = now - i*3600*24*30
+
video_item['channel_id'] = channel_id
if len(videos) == 0: