From 92c0ed20c7bfa36bce19e0f3f10ba366ccc62f9e Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 14 Feb 2025 14:30:10 -0500 Subject: [PATCH 1/2] Handle `None` in `video["duration"]` Fixes #725 Translate `None` from `get` to `0` for `float` --- tubesync/sync/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tubesync/sync/tasks.py b/tubesync/sync/tasks.py index e59efcce..894cb0d0 100644 --- a/tubesync/sync/tasks.py +++ b/tubesync/sync/tasks.py @@ -213,7 +213,7 @@ def index_source_task(source_id): except Media.DoesNotExist: media = Media(key=key) media.source = source - media.duration = float(video.get(fields('duration', media), 0)) or None + media.duration = float(video.get(fields('duration', media), 0) or 0) or None media.title = str(video.get(fields('title', media), ''))[:200] timestamp = video.get(fields('timestamp', media), None) if timestamp is not None: From 1f3cf1c62e014434c963902d607c60e968d900b8 Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 14 Feb 2025 14:38:05 -0500 Subject: [PATCH 2/2] Tweak for readability Changing the default to `None` makes it clearer why the `or 0` is needed. --- tubesync/sync/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tubesync/sync/tasks.py b/tubesync/sync/tasks.py index 894cb0d0..1f283d72 100644 --- a/tubesync/sync/tasks.py +++ b/tubesync/sync/tasks.py @@ -213,7 +213,7 @@ def index_source_task(source_id): except Media.DoesNotExist: media = Media(key=key) media.source = source - media.duration = float(video.get(fields('duration', media), 0) or 0) or None + media.duration = float(video.get(fields('duration', media), None) or 0) or None media.title = str(video.get(fields('title', media), ''))[:200] timestamp = video.get(fields('timestamp', media), None) if timestamp is not None: