meeb / tubesync

Syncs YouTube channels and playlists to a locally hosted media server
GNU Affero General Public License v3.0
1.96k stars 123 forks source link

"Failed to retrieve tasks. Database unreachable" when downloading a video which has been blocked by Youtube #59

Closed Jay2645 closed 3 years ago

Jay2645 commented 3 years ago

I'm trying to download the Yu-Gi-Oh Abridged playlist, but it doesn't seem to want to download any media after leaving it on overnight.

Checking the logs, I see:

tubesync        | 2021-02-18 01:18:48,234 [tubesync/INFO] Scheduling task to download metadata for: https://www.youtube.com/watch?v=h5azqtdUfyw
tubesync        | 2021-02-18 01:18:48,962 [tubesync/WARNING] Download task triggeredd media: -32NGYLqwAQ (UUID: e5723126-7a92-4c4b-8899-be5bb76cf9ef) but it has already been marked as downloaded, not downloading again
tubesync        | 2021-02-18 01:18:56,726 [tubesync/DEBUG] [youtube] h5azqtdUfyw: Downloading webpage
tubesync        | 2021-02-18 01:18:58,352 [tubesync/ERROR] ERROR: Video unavailable
tubesync        | This video contains content from 4K Media Inc, who has blocked it in your country on copyright grounds.
tubesync        | Rescheduling Downloading metadata for "87a99e79-a856-4b9a-85b1-dbd16a819447"
tubesync        | Traceback (most recent call last):
tubesync        |   File "/usr/local/lib/python3.7/dist-packages/background_task/tasks.py", line 43, in bg_runner
tubesync        |     func(*args, **kwargs)
tubesync        |   File "/app/sync/tasks.py", line 228, in download_media_metadata
tubesync        |     upload_date = media.upload_date
tubesync        |   File "/app/sync/models.py", line 971, in upload_date
tubesync        |     upload_date_str = self.loaded_metadata.get(field, '').strip()
tubesync        | AttributeError: 'NoneType' object has no attribute 'get'
tubesync        | Failed to retrieve tasks. Database unreachable.
tubesync        | [2021-02-18 01:19:07 -0800] [431] [CRITICAL] WORKER TIMEOUT (pid:457)
tubesync        | [2021-02-18 01:19:08 -0800] [494] [INFO] Booting worker with pid: 494
tubesync        | 2021/02/18 01:19:08 [error] 451#451: *3 upstream prematurely closed connection while reading response

This is on 0.9.

meeb commented 3 years ago

I've pushed a quick hack for this, which is in :latest if you want to try it or will be bundled into the future v1.0 first non-alpha release if you want to wait and live with the error for now.

Internally I'm not entirely show how json.loads(...) returns a None which is the only possible situation your error might be triggered by, by I've wrapped it in an exception for now to catch it anyway.

This will all get tidied up before the v1.0 launch with the pending work on #47 anyway so I won't spend too much time on it other than hacking around specific reported issues.