mirror of https://git.sr.ht/~cadence/NewLeaf
Support premiere videos on channel
This commit is contained in:
parent
7d3b79b1cd
commit
1ea86101fd
|
@ -74,20 +74,29 @@ def extract_channel(ucid):
|
|||
v["gridVideoRenderer"] for v in tab_parts["gridRenderer"]["items"] if "gridVideoRenderer" in v
|
||||
)
|
||||
for v in videos:
|
||||
live = True
|
||||
length_text = "LIVE"
|
||||
live = False
|
||||
is_upcoming = False
|
||||
length_text = "UNKNOWN"
|
||||
length_seconds = -1
|
||||
for o in v["thumbnailOverlays"]:
|
||||
if "thumbnailOverlayTimeStatusRenderer" in o:
|
||||
length_text = combine_runs(o["thumbnailOverlayTimeStatusRenderer"]["text"])
|
||||
if o["thumbnailOverlayTimeStatusRenderer"]["style"] != "LIVE":
|
||||
length_text_style = o["thumbnailOverlayTimeStatusRenderer"]["style"]
|
||||
if length_text_style == "DEFAULT":
|
||||
length_seconds = length_text_to_seconds(length_text)
|
||||
live = False
|
||||
elif length_text_style == "LIVE":
|
||||
live = True
|
||||
elif length_text_style == "UPCOMING":
|
||||
is_upcoming = True
|
||||
published = 0
|
||||
published_text = "Live now"
|
||||
premiere_timestamp = None
|
||||
if "publishedTimeText" in v:
|
||||
published_text = v["publishedTimeText"]["simpleText"]
|
||||
published = past_text_to_time(published_text)
|
||||
if "upcomingEventData" in v:
|
||||
premiere_timestamp = v["upcomingEventData"]["startTime"]
|
||||
published_text = time_to_past_text(int(premiere_timestamp))
|
||||
|
||||
view_count_text = combine_runs(v["viewCountText"]) if "viewCountText" in v else None
|
||||
view_count_text_short = combine_runs(v["shortViewCountText"]) if "shortViewCountText" in v else None
|
||||
|
@ -112,7 +121,8 @@ def extract_channel(ucid):
|
|||
"liveNow": live,
|
||||
"paid": None,
|
||||
"premium": None,
|
||||
"isUpcoming": None
|
||||
"isUpcoming": is_upcoming,
|
||||
"premiereTimestamp": premiere_timestamp
|
||||
})
|
||||
|
||||
channel = {
|
||||
|
|
|
@ -191,6 +191,13 @@ def past_text_to_time(text):
|
|||
def time_to_past_text(timestamp):
|
||||
now = int(time.time())
|
||||
diff = now - timestamp
|
||||
|
||||
# also allow for times in the future by using the same algorithm, then altering the output at the end
|
||||
time_is_in_past = True
|
||||
if diff < 0:
|
||||
diff = -diff
|
||||
time_is_in_past = False
|
||||
|
||||
units = [
|
||||
["year", 365 * 24 * 60 * 60],
|
||||
["month", 30 * 24 * 60 * 60],
|
||||
|
@ -205,7 +212,10 @@ def time_to_past_text(timestamp):
|
|||
if diff > unit_value or index + 1 >= len(units):
|
||||
number = diff // unit_value
|
||||
plural_unit = unit_name if number == 1 else unit_name + "s"
|
||||
return "{} {} ago".format(number, plural_unit)
|
||||
if time_is_in_past:
|
||||
return "{} {} ago".format(number, plural_unit)
|
||||
else:
|
||||
return "in {} {}".format(number, plural_unit)
|
||||
|
||||
def get_language_label_from_url(url_string):
|
||||
url = urlparse(url_string)
|
||||
|
|
Loading…
Reference in New Issue