Fix handling for videos with no duration from youtubedl

This commit is contained in:
Matthew Adams
2021-03-06 23:26:19 +10:00
parent 5ae2d4f4d1
commit 8d9497b104
2 changed files with 8 additions and 3 deletions

View File

@@ -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

View File

@@ -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: