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