Fix published date and views for collaboration videos in lockupViewModel

For collaboration videos, YouTube adds a second metadata row with the
author names before the row containing view count and publish date.
The LockupViewModelParser only checked metadataRows[0], so it missed
the actual data on rows 1+.

Scan all metadata rows for the one containing views/publish info.
This commit is contained in:
Luvi-1 2026-08-23 21:43:14 -07:00
parent 6e04e743be
commit a937fe1707

View File

@ -662,7 +662,12 @@ private module Parsers
metadata = item_contents.dig("metadata", "lockupMetadataViewModel")
title = metadata.dig("title", "content").as_s
# Contains the views of the video and the published time of the video.
metadata_parts = metadata.dig("metadata", "contentMetadataViewModel", "metadataRows", 0, "metadataParts").try &.as_a
# For collaboration videos, the first row contains the author names
# instead, so we scan all rows for the one with view/publish info.
metadata_parts = metadata.dig?("metadata", "contentMetadataViewModel", "metadataRows")
.try &.as_a
.compact_map { |row| row.dig?("metadataParts").try &.as_a }
.find { |parts| parts.any? { |item| item.dig?("text", "content").try &.as_s.includes?("views") || item.dig?("text", "content").try &.as_s.includes?("ago") } }
view_count_text = metadata_parts.try &.find { |item| item["icon"]?.nil? && item.dig?("text", "content").try &.as_s.includes?("views") }
.try &.dig("text", "content").as_s