From bf63059df380acc56e228540086ccc6e00da1ed7 Mon Sep 17 00:00:00 2001 From: girst Date: Sun, 6 Dec 2020 18:56:54 +0100 Subject: [PATCH] add comment explaning 0:00 length subscription videos --- app/common/common.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/common/common.py b/app/common/common.py index 0b61886..00182f9 100644 --- a/app/common/common.py +++ b/app/common/common.py @@ -21,7 +21,8 @@ if not 'global' in cf: # todo: full config check # Note: currently expiring after 10 minutes. googlevideo-urls are valid for 5h59m, but this makes reddit very stale and premiere videos won't start. TODO: exipre when video is livestream/premiere/etc requests_cache.install_cache(backend='memory', expire_after=10*60, allowable_codes=(200,)) -# Note: this should only be required for the 'memory' backed cache. +# Note: requests-cache doesn't use redis expiry, so we need this in all backends: +# https://github.com/reclosedev/requests-cache/issues/58#issuecomment-164537971 # TODO: only run for long-running processes, i.e. the frontend from threading import Timer def purge_cache(sec): @@ -284,6 +285,10 @@ def video_metadata(metadata): meta1 = metadata['videoDetails'] meta2 = metadata['microformat']['playerMicroformatRenderer'] + # sometimes, we receive the notification so early that the length is not + # yet populated. Nothing we can do about it. + length = int(meta2['lengthSeconds']) or int(meta1['lengthSeconds']) or None + published_at = meta2.get('liveBroadcastDetails',{}) \ .get('startTimestamp', f"{meta2['publishDate']}T00:00:00Z") @@ -295,7 +300,7 @@ def video_metadata(metadata): 'channel_id': meta1['channelId'], 'published': published_at, 'views': int(meta1['viewCount']), - 'length': int(meta2['lengthSeconds']) or int(meta1['lengthSeconds']), + 'length': length, 'livestream': meta1['isLiveContent'], } -- 2.39.3