From 764eb11a43e0240565b25b1b4a69534c990a61e2 Mon Sep 17 00:00:00 2001 From: Maksym Pavlenko Date: Sun, 7 Apr 2019 21:55:56 -0700 Subject: [PATCH] Don't return zero file size from updater --- cmd/updater/updater.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/updater/updater.py b/cmd/updater/updater.py index 9c00a7c..68f04f0 100644 --- a/cmd/updater/updater.py +++ b/cmd/updater/updater.py @@ -75,21 +75,25 @@ def _get_updates(start, count, url, fmt, last_id=None): date_str = result.get('upload_date') date = datetime.strptime(date_str, '%Y%m%d') + # Duration in seconds + duration = int(result.get('duration')) + size = _get_size(result, selector, fmt, duration) + videos.append({ 'ID': video_id, 'Title': result.get('title'), 'Description': result.get('description'), 'Thumbnail': result.get('thumbnail'), - 'Duration': int(result.get('duration')), + 'Duration': duration, 'VideoURL': result.get('webpage_url'), 'PubDate': int(date.timestamp()), - 'Size': _get_size(result, selector), + 'Size': size, }) return feed, videos, new_last_id -def _get_size(video, selector): +def _get_size(video, selector, fmt, duration): try: selected = next(selector(video)) except KeyError: @@ -101,4 +105,12 @@ def _get_size(video, selector): if selected.get('filesize') is not None: return int(selected['filesize']) - return 0 + # Calculate approximate file size + + is_high = 'best' in fmt + is_audio = 'audio' in fmt + + if is_audio: + return [16000 if is_high else 6000] * duration + else: + return [350000 if is_high else 100000] * duration