mirror of
https://github.com/iv-org/invidious.git
synced 2026-07-07 14:16:45 -05:00
improve playlist metadataRows and metadataParts parsing for channel playlists
This commit is contained in:
parent
84e53bfa61
commit
8e0cdbf0ae
@ -758,11 +758,45 @@ private module Parsers
|
|||||||
# "metadataParts": [ ... ] <-- metadataParts with the information we are searching for.
|
# "metadataParts": [ ... ] <-- metadataParts with the information we are searching for.
|
||||||
# }
|
# }
|
||||||
# ]
|
# ]
|
||||||
metadata_parts = metadata.dig?("metadata", "contentMetadataViewModel", "metadataRows").try &.as_a
|
#
|
||||||
.find { |row| row["metadataParts"]? }
|
# Playlist on channels also contain metadataRows, but not with the type of data we are searching
|
||||||
.try &.dig("metadataParts", 0)
|
# for which are the channel name and channel ID, instead they have two fields depending of the playlist
|
||||||
|
# updated date:
|
||||||
|
#
|
||||||
|
# It looks like this:
|
||||||
|
# "metadataRows": [
|
||||||
|
# {
|
||||||
|
# "metadataParts": [
|
||||||
|
# {
|
||||||
|
# "text": {
|
||||||
|
# "content": "Updated 4 days ago"
|
||||||
|
# }
|
||||||
|
# } <-- This object is missing if the playlist has not been updated in around 7
|
||||||
|
# days
|
||||||
|
# ]
|
||||||
|
# },
|
||||||
|
# {
|
||||||
|
# "metadataParts": [
|
||||||
|
# {
|
||||||
|
# "text": {
|
||||||
|
# "content": "View full playlist",
|
||||||
|
# "commandRuns": [ ... ],
|
||||||
|
# "styleRuns": [ ... ].
|
||||||
|
# }
|
||||||
|
# } <-- This object is always present, so we use this to determine if the
|
||||||
|
# metadataParts can be used or not.
|
||||||
|
# ]
|
||||||
|
# }
|
||||||
|
# ]
|
||||||
|
#
|
||||||
|
metadata_rows = metadata.dig?("metadata", "contentMetadataViewModel", "metadataRows").try &.as_a
|
||||||
|
metadata_parts = metadata_rows.try &.find { |row|
|
||||||
|
parts = row["metadataParts"]?.try &.as_a
|
||||||
|
parts && !parts.any? { |item| item.dig?("text", "content").try &.as_s == "View full playlist" }
|
||||||
|
}.try &.["metadataParts"].as_a
|
||||||
|
|
||||||
if author_info = metadata_parts.try &.["text"]?
|
if author_info = metadata_parts.try &.find { |item| item.dig?("text", "commandRuns") }
|
||||||
|
.try &.["text"]
|
||||||
author = author_info["content"].as_s
|
author = author_info["content"].as_s
|
||||||
author_id = author_info.dig?("commandRuns", 0, "onTap", "innertubeCommand", "browseEndpoint", "browseId")
|
author_id = author_info.dig?("commandRuns", 0, "onTap", "innertubeCommand", "browseEndpoint", "browseId")
|
||||||
.try &.as_s || author_fallback.id
|
.try &.as_s || author_fallback.id
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user