From f9ae63bdbde14740a25ad53bbdbcb6c72b18c61a Mon Sep 17 00:00:00 2001 From: girst Date: Fri, 26 Jan 2024 14:48:45 +0000 Subject: [PATCH] fix inserting NULLs into videos table * we set premiere to NULL instead of FALSE every time it was not a livestream * ytshorts can't be livestreams of premiering videos (turns NULL->FALSE) --- app/common/common.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/common/common.py b/app/common/common.py index 65171dd..17cad11 100644 --- a/app/common/common.py +++ b/app/common/common.py @@ -361,6 +361,8 @@ def video_metadata(metadata): # different rounding strategy, meta2 is sometimes (incorrectly) 1s longer. length = int(meta1.get('lengthSeconds',0)) or int(meta2.get('lengthSeconds',0)) or None + views = int(meta1['viewCount']) if 'viewCount' in meta1 else None + scheduled_time = metadata.get('playabilityStatus',{}) \ .get('liveStreamability',{}).get('liveStreamabilityRenderer',{}) \ .get('offlineSlate',{}).get('liveStreamOfflineSlateRenderer',{}) \ @@ -384,12 +386,14 @@ def video_metadata(metadata): except: aspect_ratio = None - # shorts are <= 60 seconds and vertical or square. if we were unable to - # determine it, we set it to None. + is_livestream = meta1['isLiveContent'] + is_premiere = meta1.get('isUpcoming', False) and not is_livestream + # shorts are <= 60 seconds and vertical or square. they can't be premiere + # or livestreams. if we were unable to determine it, we set it to None. is_short = ( True if (length or 61) <= 60 and (aspect_ratio or 2) <= 1 else False if (length or 0) > 60 or (aspect_ratio or 0) > 1 else - None + None if not is_premiere and not is_livestream else False ) # Note: 'premiere' videos have livestream=False and published= will be the @@ -399,11 +403,11 @@ def video_metadata(metadata): 'author': meta1['author'], 'channel_id': meta1['channelId'], 'published': published_at, - 'views': int(meta1['viewCount']) if 'viewCount' in meta1 else None, + 'views': views, 'length': length, 'aspect': aspect_ratio or 16/9, - 'livestream': meta1['isLiveContent'], - 'premiere': meta1.get('isUpcoming') and not meta1['isLiveContent'], + 'livestream': is_livestream, + 'premiere': is_premiere, 'shorts': is_short, } -- 2.39.3