From 8d9497b104924f75bcef1231ba70198c5d4fd9bf Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Sat, 6 Mar 2021 23:26:19 +1000 Subject: [PATCH] Fix handling for videos with no duration from youtubedl --- downloader.py | 3 ++- main.py | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/downloader.py b/downloader.py index e0e2c55..a00cfdb 100644 --- a/downloader.py +++ b/downloader.py @@ -23,7 +23,8 @@ def download(videoUrl): # Just a video video = result - response['duration'] = video['duration'] + if('duration' in video): + response['duration'] = video['duration'] response['fileName'] = video['id'] + ".mp4" return response diff --git a/main.py b/main.py index d91a1cb..8fdb5ef 100644 --- a/main.py +++ b/main.py @@ -60,8 +60,12 @@ async def on_message(message): await message.channel.send(compressionMessage) print("Duration = " + str(duration)) # Give us 7MB files with VBR encoding to allow for some overhead - bitrateKilobits = (7000 * 8)/duration - bitrateKilobits = round(bitrateKilobits) + bitrateKilobits = 0 + if(duration != 0): + bitrateKilobits = (7000 * 8)/duration + bitrateKilobits = round(bitrateKilobits) + else: + bitrateKilobits = 800 print("Calced bitrate = " + str(bitrateKilobits)) ffmpeg.input(fileName).output("small_" + fileName, **{'b:v': str(bitrateKilobits) + 'k', 'threads': '4'}).run() with open("small_" + fileName, 'rb') as fp: