add fallback total video length if ffmpeg extraction failes

This commit is contained in:
simon 2022-03-12 21:53:03 +07:00
parent 34708dd59f
commit 8170d4913b
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -183,6 +183,8 @@ class ArchivistResultsView(ArchivistViewConfig):
if video["youtube_id"] in in_progress: if video["youtube_id"] in in_progress:
played_sec = in_progress.get(video["youtube_id"]) played_sec = in_progress.get(video["youtube_id"])
total = video["player"]["duration"] total = video["player"]["duration"]
if not total:
total = played_sec * 2
video["player"]["progress"] = 100 * (played_sec / total) video["player"]["progress"] = 100 * (played_sec / total)
def get_in_progress(self, results): def get_in_progress(self, results):
@ -202,6 +204,8 @@ class ArchivistResultsView(ArchivistViewConfig):
matched = [i for i in results if i["youtube_id"] == youtube_id] matched = [i for i in results if i["youtube_id"] == youtube_id]
played_sec = matched[0]["position"] played_sec = matched[0]["position"]
total = video["source"]["player"]["duration"] total = video["source"]["player"]["duration"]
if not total:
total = matched[0].get("position") * 2
video["source"]["player"]["progress"] = 100 * (played_sec / total) video["source"]["player"]["progress"] = 100 * (played_sec / total)
return videos return videos