1
0
Fork 0
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:
Cadence Ember 2026-06-27 13:43:49 +12:00
parent 19ed025d1b
commit c4182790b6
2 changed files with 8 additions and 3 deletions

View file

@ -132,12 +132,16 @@ def extract_channel(ucid, second__path="user"):
for r in maybe_get(lv, "metadata", "lockupMetadataViewModel", "metadata", "contentMetadataViewModel", "metadataRows", default=[]): for r in maybe_get(lv, "metadata", "lockupMetadataViewModel", "metadata", "contentMetadataViewModel", "metadataRows", default=[]):
for p in r.get("metadataParts", []): for p in r.get("metadataParts", []):
t = maybe_get(p, "text", "content", default="") t = maybe_get(p, "text", "content", default="")
a = maybe_get(p, "accessibilityLabel", default="")
if t.startswith("Streamed") or t.endswith("ago"): if t.startswith("Streamed") or t.endswith("ago"):
published_text = t published_text = t
published = past_text_to_time(published_text) published = past_text_to_time(published_text)
elif t.endswith("views"): elif t.endswith("views"):
view_count_text_short = t view_count_text_short = t
view_count_text = 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"]: for o in lv["contentImage"]["thumbnailViewModel"]["overlays"]:
if m := o.get("thumbnailBottomOverlayViewModel"): if m := o.get("thumbnailBottomOverlayViewModel"):

View file

@ -169,15 +169,16 @@ def uncompress_counter(text):
return int(float(text[:-1]) * multiplier) return int(float(text[:-1]) * multiplier)
def past_text_to_time(text): 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": if words[0] == "Streamed":
words = words[1:] words = words[1:]
if len(words) != 3: if len(words) != 3:
print(words) print(words)
raise Exception("Past text is not 3 words") raise Exception(f"Past text is not 3 words: '{text}'")
if words[2] != "ago": if words[2] != "ago":
print(words) 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]) number = int(words[0])
unit = words[1][:2] unit = words[1][:2]
multiplier = 1 multiplier = 1