mirror of
https://git.sr.ht/~cadence/NewLeaf
synced 2024-11-21 23:27: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:
|
||||
r.raise_for_status()
|
||||
yt_initial_data = extract_yt_initial_data(r.content.decode("utf8"))
|
||||
|
||||
header = yt_initial_data["header"]["c4TabbedHeaderRenderer"]
|
||||
author = header["title"]
|
||||
author_id = header["channelId"]
|
||||
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 = []
|
||||
if "banner" in header:
|
||||
author_banners = header["banner"]["thumbnails"]
|
||||
for t in author_banners:
|
||||
t["url"] = normalise_url_protocol(t["url"])
|
||||
|
||||
author_thumbnails = []
|
||||
if "avatar" in header:
|
||||
author_thumbnails = generate_full_author_thumbnails(header["avatar"]["thumbnails"])
|
||||
subscriber_count = combine_runs(header["subscriberCountText"])
|
||||
description = yt_initial_data["metadata"]["channelMetadataRenderer"]["description"]
|
||||
allowed_regions = yt_initial_data["metadata"]["channelMetadataRenderer"]["availableCountryCodes"]
|
||||
|
||||
latest_videos = []
|
||||
tabs = yt_initial_data["contents"]["twoColumnBrowseResultsRenderer"]["tabs"]
|
||||
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 = (
|
||||
v["gridVideoRenderer"] for v in
|
||||
videos_tab["content"]["sectionListRenderer"]["contents"][0]["itemSectionRenderer"]["contents"][0]["gridRenderer"]["items"]
|
||||
v["gridVideoRenderer"] for v in tab_parts["gridRenderer"]["items"]
|
||||
)
|
||||
latest_videos = []
|
||||
for v in videos:
|
||||
live = True
|
||||
length_text = "LIVE"
|
||||
|
Loading…
Reference in New Issue
Block a user