mirror of
https://git.sr.ht/~cadence/NewLeaf
synced 2024-11-22 07:37:29 +00:00
Fix for if channel has no videos
This commit is contained in:
parent
097b6bf584
commit
e1bcc306b3
@ -21,28 +21,36 @@ def extract_channel(ucid):
|
|||||||
with requests.get("https://www.youtube.com/{}/{}/videos".format(channel_type, ucid)) as r:
|
with requests.get("https://www.youtube.com/{}/{}/videos".format(channel_type, ucid)) as r:
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
yt_initial_data = extract_yt_initial_data(r.content.decode("utf8"))
|
yt_initial_data = extract_yt_initial_data(r.content.decode("utf8"))
|
||||||
|
|
||||||
header = yt_initial_data["header"]["c4TabbedHeaderRenderer"]
|
header = yt_initial_data["header"]["c4TabbedHeaderRenderer"]
|
||||||
author = header["title"]
|
author = header["title"]
|
||||||
author_id = header["channelId"]
|
author_id = header["channelId"]
|
||||||
author_url = header["navigationEndpoint"]["commandMetadata"]["webCommandMetadata"]["url"]
|
author_url = header["navigationEndpoint"]["commandMetadata"]["webCommandMetadata"]["url"]
|
||||||
|
subscriber_count = combine_runs(header["subscriberCountText"])
|
||||||
|
description = yt_initial_data["metadata"]["channelMetadataRenderer"]["description"]
|
||||||
|
allowed_regions = yt_initial_data["metadata"]["channelMetadataRenderer"]["availableCountryCodes"]
|
||||||
|
|
||||||
author_banners = []
|
author_banners = []
|
||||||
if "banner" in header:
|
if "banner" in header:
|
||||||
author_banners = header["banner"]["thumbnails"]
|
author_banners = header["banner"]["thumbnails"]
|
||||||
for t in author_banners:
|
for t in author_banners:
|
||||||
t["url"] = normalise_url_protocol(t["url"])
|
t["url"] = normalise_url_protocol(t["url"])
|
||||||
|
|
||||||
author_thumbnails = []
|
author_thumbnails = []
|
||||||
if "avatar" in header:
|
if "avatar" in header:
|
||||||
author_thumbnails = generate_full_author_thumbnails(header["avatar"]["thumbnails"])
|
author_thumbnails = generate_full_author_thumbnails(header["avatar"]["thumbnails"])
|
||||||
subscriber_count = combine_runs(header["subscriberCountText"])
|
|
||||||
description = yt_initial_data["metadata"]["channelMetadataRenderer"]["description"]
|
latest_videos = []
|
||||||
allowed_regions = yt_initial_data["metadata"]["channelMetadataRenderer"]["availableCountryCodes"]
|
|
||||||
tabs = yt_initial_data["contents"]["twoColumnBrowseResultsRenderer"]["tabs"]
|
tabs = yt_initial_data["contents"]["twoColumnBrowseResultsRenderer"]["tabs"]
|
||||||
videos_tab = next(tab["tabRenderer"] for tab in tabs if tab["tabRenderer"]["title"] == "Videos")
|
videos_tab = next(tab["tabRenderer"] for tab in tabs if tab["tabRenderer"]["title"] == "Videos")
|
||||||
|
tab_parts = videos_tab["content"]["sectionListRenderer"]["contents"][0]["itemSectionRenderer"]["contents"][0]
|
||||||
|
|
||||||
|
# check that the channel actually has videos - this may be replaced
|
||||||
|
# with messageRenderer.text.simpleText == "This channel has no videos."
|
||||||
|
if "gridVideoRenderer" in tab_parts:
|
||||||
videos = (
|
videos = (
|
||||||
v["gridVideoRenderer"] for v in
|
v["gridVideoRenderer"] for v in tab_parts["gridRenderer"]["items"]
|
||||||
videos_tab["content"]["sectionListRenderer"]["contents"][0]["itemSectionRenderer"]["contents"][0]["gridRenderer"]["items"]
|
|
||||||
)
|
)
|
||||||
latest_videos = []
|
|
||||||
for v in videos:
|
for v in videos:
|
||||||
live = True
|
live = True
|
||||||
length_text = "LIVE"
|
length_text = "LIVE"
|
||||||
|
Loading…
Reference in New Issue
Block a user