mirror of
https://git.sr.ht/~cadence/NewLeaf
synced 2026-06-27 15:15:27 +00:00
Support new channel views layout
This commit is contained in:
parent
19ed025d1b
commit
c4182790b6
2 changed files with 8 additions and 3 deletions
|
|
@ -132,12 +132,16 @@ def extract_channel(ucid, second__path="user"):
|
|||
for r in maybe_get(lv, "metadata", "lockupMetadataViewModel", "metadata", "contentMetadataViewModel", "metadataRows", default=[]):
|
||||
for p in r.get("metadataParts", []):
|
||||
t = maybe_get(p, "text", "content", default="")
|
||||
a = maybe_get(p, "accessibilityLabel", default="")
|
||||
if t.startswith("Streamed") or t.endswith("ago"):
|
||||
published_text = t
|
||||
published = past_text_to_time(published_text)
|
||||
elif t.endswith("views"):
|
||||
view_count_text_short = t
|
||||
view_count_text = t
|
||||
elif a.endswith("views"):
|
||||
view_count_text_short = f"{t} views"
|
||||
view_count_text = f"{t} views"
|
||||
|
||||
for o in lv["contentImage"]["thumbnailViewModel"]["overlays"]:
|
||||
if m := o.get("thumbnailBottomOverlayViewModel"):
|
||||
|
|
|
|||
|
|
@ -169,15 +169,16 @@ def uncompress_counter(text):
|
|||
return int(float(text[:-1]) * multiplier)
|
||||
|
||||
def past_text_to_time(text):
|
||||
words = text.split(" ")
|
||||
spaced_text = re.sub(r"^([0-9]+)([^ ])", r"\1 \2", text)
|
||||
words = spaced_text.split(" ")
|
||||
if words[0] == "Streamed":
|
||||
words = words[1:]
|
||||
if len(words) != 3:
|
||||
print(words)
|
||||
raise Exception("Past text is not 3 words")
|
||||
raise Exception(f"Past text is not 3 words: '{text}'")
|
||||
if words[2] != "ago":
|
||||
print(words)
|
||||
raise Exception('Past text does not end with "ago"')
|
||||
raise Exception(f"Past text does not end with \"ago\": '{text}'")
|
||||
number = int(words[0])
|
||||
unit = words[1][:2]
|
||||
multiplier = 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue