add owner badges for related videos, use short text for text view count
This commit is contained in:
@@ -188,7 +188,7 @@ def videos(data):
|
||||
title = safeTraverse(video_details, ['title'], default=video_id)
|
||||
views = int(safeTraverse(video_details, ['viewCount'], default=0))
|
||||
length = int(safeTraverse(video_details, ['lengthSeconds'], default=1))
|
||||
published = datetime.datetime.fromisoformat(safeTraverse(microformat, ['publishDate'], default="2004-10-29T10:30:00-07:00")).timestamp() # ISO format to Unix timestamp
|
||||
published = datetime.datetime.fromisoformat(safeTraverse(microformat, ['publishDate'], default="1970-01-02T00:00:00Z")).timestamp() # ISO format to Unix timestamp
|
||||
published_date = epochToDate(published)
|
||||
premiere_timestamp = safeTraverse(microformat, ['liveBroadcastDetails', 'startTimestamp'], default=0) # let's ignore the nitty gritty for the time being
|
||||
premiere_timestamp = premiere_timestamp if premiere_timestamp else safeTraverse(microformat, ['playabilityStatus', 'liveStreamability', 'liveStreamabilityRenderer', 'offlineSlate', 'liveStreamOfflineSlateRenderer', 'scheduledStartTime'], default=0)
|
||||
@@ -201,7 +201,6 @@ def videos(data):
|
||||
is_upcoming = safeTraverse(video_details, ['isUpcoming'], default=False)
|
||||
keywords = safeTraverse(video_details, ['keywords'], default=[])
|
||||
|
||||
# TODO: https://github.com/iv-org/invidious/blob/master/src/invidious/videos/parser.cr#L258
|
||||
related_raw = safeTraverse(wdata, ['ec2', 'contents', 'twoColumnWatchNextResults', 'secondaryResults', 'secondaryResults', 'results'], default=[]) # can possibly change in the future
|
||||
related = []
|
||||
for x in related_raw:
|
||||
@@ -216,6 +215,8 @@ def videos(data):
|
||||
related_video['authorId'] = safeTraverse(y, ['longBylineText', 'runs', 0, 'navigationEndpoint', 'browseEndpoint', 'browseId'], default="UNKNOWNCHANNELID")
|
||||
related_video['authorUrl'] = '/channel/' + related_video['authorId']
|
||||
related_video['authorVerified'] = False
|
||||
if "ownerBadges" in y:
|
||||
related_video['authorVerified'] = True # hopefully this won't break things, as invidious API doesn't distinguish music and normal verified badges
|
||||
related_video['authorThumbnails'] = safeTraverse(y, ['channelThumbnail', 'thumbnails'], default=[])
|
||||
for z in related_video['authorThumbnails']:
|
||||
z['url'] = ythdd_globals.translateLinks(z['url'])
|
||||
@@ -225,7 +226,7 @@ def videos(data):
|
||||
for z in range(len(time_list)):
|
||||
related_video['lengthSeconds'] += time_lookup_list[z] * int(time_list[len(time_list) - 1 - z])
|
||||
related_views_text = safeTraverse(y, ['viewCountText', 'simpleText'], default="0").split(" ")[0]
|
||||
related_video['viewCountText'] = related_views_text
|
||||
related_video['viewCountText'] = safeTraverse(y, ['shortViewCountText', 'simpleText'], default="0").split(" ")[0]
|
||||
related_views = 0
|
||||
if related_views_text:
|
||||
related_views = int("".join([z for z in related_views_text if 48 <= ord(z) and ord(z) <= 57]))
|
||||
@@ -265,7 +266,11 @@ def videos(data):
|
||||
for x in author_thumbnail:
|
||||
# rewrite to use views.py
|
||||
x['url'] = ythdd_globals.translateLinks(x['url'])
|
||||
# TODO: author_verified = ...
|
||||
|
||||
# so far it seems to be impossible to tell if a channel is verified or not,
|
||||
# that is - without making another request
|
||||
author_verified = False
|
||||
|
||||
|
||||
hls_url = safeTraverse(idata, ['stage1', 'streamingData', 'hlsManifestUrl'], default="")
|
||||
adaptive_formats = safeTraverse(idata, ['stage1', 'streamingData', 'adaptiveFormats'], default=[])
|
||||
@@ -279,6 +284,11 @@ def videos(data):
|
||||
else:
|
||||
video_type = "video"
|
||||
|
||||
premium = False
|
||||
if "YouTube Red" in keywords:
|
||||
premium = True
|
||||
# TODO: detect paywalled patron-only videos
|
||||
|
||||
if not format_streams:
|
||||
format_streams = []
|
||||
# providing format streams breaks Clipious client
|
||||
@@ -305,7 +315,7 @@ def videos(data):
|
||||
"dislikeCount": 0,
|
||||
|
||||
"paid": False, # not implemented
|
||||
"premium": False, # not implemented
|
||||
"premium": premium,
|
||||
"isFamilyFriendly": family_friendly,
|
||||
"allowedRegions": allowed_regions,
|
||||
"genre": genre,
|
||||
@@ -314,7 +324,7 @@ def videos(data):
|
||||
"author": author,
|
||||
"authorId": ucid,
|
||||
"authorUrl": "/channel/" + ucid,
|
||||
"authorVerified": False, # not implemented
|
||||
"authorVerified": author_verified,
|
||||
"authorThumbnails": author_thumbnail,
|
||||
|
||||
"subCountText": subs_text,
|
||||
|
||||
Reference in New Issue
Block a user