From 1b5fbfc13efa9eace904d24dc89b7fdf72c1ce52 Mon Sep 17 00:00:00 2001
From: techmetx11
Date: Sat, 14 Jan 2023 09:38:55 +0100
Subject: [PATCH] Video: Add support for the music section
---
locales/en-US.json | 3 +++
src/invidious/videos.cr | 3 +++
src/invidious/videos/parser.cr | 22 ++++++++++++++++++++++
src/invidious/views/watch.ecr | 9 +++++++++
4 files changed, 37 insertions(+)
diff --git a/locales/en-US.json b/locales/en-US.json
index 129556654..bc6a32759 100644
--- a/locales/en-US.json
+++ b/locales/en-US.json
@@ -188,6 +188,9 @@
"Engagement: ": "Engagement: ",
"Whitelisted regions: ": "Whitelisted regions: ",
"Blacklisted regions: ": "Blacklisted regions: ",
+ "Music artist: ": "Music artist: ",
+ "Music album: ": "Music album: ",
+ "Music licenses: ": "Music licenses: ",
"Shared `x`": "Shared `x`",
"Premieres in `x`": "Premieres in `x`",
"Premieres `x`": "Premieres `x`",
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr
index d626c7d18..be4854fe1 100644
--- a/src/invidious/videos.cr
+++ b/src/invidious/videos.cr
@@ -314,6 +314,9 @@ struct Video
getset_string genre
getset_string genreUcid
getset_string license
+ getset_string music_artist
+ getset_string music_album
+ getset_string music_licenses
getset_string shortDescription
getset_string subCountText
getset_string title
diff --git a/src/invidious/videos/parser.cr b/src/invidious/videos/parser.cr
index 5df492868..4540dd13c 100644
--- a/src/invidious/videos/parser.cr
+++ b/src/invidious/videos/parser.cr
@@ -309,6 +309,24 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
end
end
+ # Music section
+
+ music_desc = player_response.dig?("engagementPanels", 1, "engagementPanelSectionListRenderer", "content", "structuredDescriptionContentRenderer", "items", 2, "videoDescriptionMusicSectionRenderer", "carouselLockups", 0, "carouselLockupRenderer", "infoRows").try &.as_a
+ artist = nil
+ album = nil
+ music_licenses = nil
+
+ music_desc.try &.each do |desc|
+ desc_title = extract_text(desc.dig?("infoRowRenderer", "title"))
+ if desc_title == "ARTIST"
+ artist = extract_text(desc.dig?("infoRowRenderer", "defaultMetadata"))
+ elsif desc_title == "ALBUM"
+ album = extract_text(desc.dig?("infoRowRenderer", "defaultMetadata"))
+ elsif desc_title == "LICENSES"
+ music_licenses = extract_text(desc.dig?("infoRowRenderer", "expandedMetadata"))
+ end
+ end
+
# Author infos
author = video_details["author"]?.try &.as_s
@@ -359,6 +377,10 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
"genre" => JSON::Any.new(genre.try &.as_s || ""),
"genreUcid" => JSON::Any.new(genre_ucid.try &.as_s || ""),
"license" => JSON::Any.new(license.try &.as_s || ""),
+ # Music section
+ "music_artist" => JSON::Any.new(artist || ""),
+ "music_album" => JSON::Any.new(album || ""),
+ "music_licenses" => JSON::Any.new(music_licenses || ""),
# Author infos
"author" => JSON::Any.new(author || ""),
"ucid" => JSON::Any.new(ucid || ""),
diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr
index a6f2e5242..beab1bb2c 100644
--- a/src/invidious/views/watch.ecr
+++ b/src/invidious/views/watch.ecr
@@ -196,6 +196,15 @@ we're going to need to do it here in order to allow for translations.
<% end %>
<% end %>
+ <% if !video.music_artist.empty? %>
+ <%= translate(locale, "Music artist: ") %><%= video.music_artist %>
+ <% end %>
+ <% if !video.music_album.empty? %>
+ <%= translate(locale, "Music album: ") %><%= video.music_album %>
+ <% end %>
+ <% if !video.music_licenses.empty? %>
+ <%= translate(locale, "Music licenses: ") %><%= video.music_licenses %>
+ <% end %>