youtube: Handle missing uploads playlist

This commit is contained in:
Mattéo Delabre 2021-09-13 11:01:26 +02:00
parent 20c3d12331
commit 90858fbf7b
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
1 changed files with 17 additions and 10 deletions

View File

@ -4,11 +4,12 @@ import json
import logging
import urllib
import urllib.request
from typing import Any, Iterable, Optional, Tuple
from typing import Any, Iterable, Tuple
from cachetools import cached, TTLCache
from ..util import send_with_retry
HTTPError = urllib.error.HTTPError
HTTPRequest = urllib.request.Request
HTTPResponse = http.client.HTTPResponse
HTTPException = http.client.HTTPException
@ -122,16 +123,22 @@ class APIClient:
:returns: list of latest videos
:throws HTTPException: if the query fails
"""
response = self._query(
url="https://youtube.googleapis.com/youtube/v3/playlistItems",
method="GET",
data=(
("part", "snippet"),
("part", "status"),
("playlistId", playlist_id),
("maxResults", 50),
try:
response = self._query(
url="https://youtube.googleapis.com/youtube/v3/playlistItems",
method="GET",
data=(
("part", "snippet"),
("part", "status"),
("playlistId", playlist_id),
("maxResults", 50),
)
)
)
except HTTPError as err:
if err.code == 404:
return []
raise err
return [
item["snippet"]