summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/invidious/channels/community.cr28
-rw-r--r--src/invidious/comments.cr3
-rw-r--r--src/invidious/helpers/serialized_yt_data.cr1
-rw-r--r--src/invidious/helpers/utils.cr4
-rw-r--r--src/invidious/routes/account.cr3
-rw-r--r--src/invidious/routes/api/v1/authenticated.cr23
-rw-r--r--src/invidious/routes/api/v1/channels.cr2
-rw-r--r--src/invidious/routes/api/v1/misc.cr27
-rw-r--r--src/invidious/routes/api/v1/videos.cr70
-rw-r--r--src/invidious/routes/login.cr6
-rw-r--r--src/invidious/routes/subscriptions.cr29
-rw-r--r--src/invidious/routing.cr6
-rw-r--r--src/invidious/trending.cr7
-rw-r--r--src/invidious/user/exports.cr35
-rw-r--r--src/invidious/videos.cr6
-rw-r--r--src/invidious/videos/caption.cr66
-rw-r--r--src/invidious/videos/music.cr12
-rw-r--r--src/invidious/videos/parser.cr29
-rw-r--r--src/invidious/views/watch.ecr22
-rw-r--r--src/invidious/yt_backend/extractors.cr16
20 files changed, 327 insertions, 68 deletions
diff --git a/src/invidious/channels/community.cr b/src/invidious/channels/community.cr
index 8e300288..13af2d8b 100644
--- a/src/invidious/channels/community.cr
+++ b/src/invidious/channels/community.cr
@@ -69,7 +69,7 @@ def fetch_channel_community(ucid, continuation, locale, format, thin_mode)
next if !post
content_html = post["contentText"]?.try { |t| parse_content(t) } || ""
- author = post["authorText"]?.try &.["simpleText"]? || ""
+ author = post["authorText"]["runs"]?.try &.[0]?.try &.["text"]? || ""
json.object do
json.field "author", author
@@ -189,6 +189,32 @@ def fetch_channel_community(ucid, continuation, locale, format, thin_mode)
# when .has_key?("pollRenderer")
# attachment = attachment["pollRenderer"]
# json.field "type", "poll"
+ when .has_key?("postMultiImageRenderer")
+ attachment = attachment["postMultiImageRenderer"]
+ json.field "type", "multiImage"
+ json.field "images" do
+ json.array do
+ attachment["images"].as_a.each do |image|
+ json.array do
+ thumbnail = image["backstageImageRenderer"]["image"]["thumbnails"][0].as_h
+ width = thumbnail["width"].as_i
+ height = thumbnail["height"].as_i
+ aspect_ratio = (width.to_f / height.to_f)
+ url = thumbnail["url"].as_s.gsub(/=w\d+-h\d+(-p)?(-nd)?(-df)?(-rwa)?/, "=s640")
+
+ qualities = {320, 560, 640, 1280, 2000}
+
+ qualities.each do |quality|
+ json.object do
+ json.field "url", url.gsub(/=s\d+/, "=s#{quality}")
+ json.field "width", quality
+ json.field "height", (quality / aspect_ratio).ceil.to_i
+ end
+ end
+ end
+ end
+ end
+ end
else
json.field "type", "unknown"
json.field "error", "Unrecognized attachment type."
diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr
index d691ca36..357a461c 100644
--- a/src/invidious/comments.cr
+++ b/src/invidious/comments.cr
@@ -181,6 +181,8 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
json.field "content", html_to_content(content_html)
json.field "contentHtml", content_html
+ json.field "isPinned", (node_comment["pinnedCommentBadge"]? != nil)
+
json.field "published", published.to_unix
json.field "publishedText", translate(locale, "`x` ago", recode_date(published, locale))
@@ -670,6 +672,7 @@ def content_to_comment_html(content, video_id : String? = "")
end
text = "<b>#{text}</b>" if run["bold"]?
+ text = "<s>#{text}</s>" if run["strikethrough"]?
text = "<i>#{text}</i>" if run["italics"]?
text
diff --git a/src/invidious/helpers/serialized_yt_data.cr b/src/invidious/helpers/serialized_yt_data.cr
index 635f0984..c1874780 100644
--- a/src/invidious/helpers/serialized_yt_data.cr
+++ b/src/invidious/helpers/serialized_yt_data.cr
@@ -74,6 +74,7 @@ struct SearchVideo
json.field "author", self.author
json.field "authorId", self.ucid
json.field "authorUrl", "/channel/#{self.ucid}"
+ json.field "authorVerified", self.author_verified
json.field "videoThumbnails" do
Invidious::JSONify::APIv1.thumbnails(json, self.id)
diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr
index ed0cca38..500a2582 100644
--- a/src/invidious/helpers/utils.cr
+++ b/src/invidious/helpers/utils.cr
@@ -162,7 +162,7 @@ def number_with_separator(number)
end
def short_text_to_number(short_text : String) : Int64
- matches = /(?<number>\d+(\.\d+)?)\s?(?<suffix>[mMkKbB])?/.match(short_text)
+ matches = /(?<number>\d+(\.\d+)?)\s?(?<suffix>[mMkKbB]?)/.match(short_text)
number = matches.try &.["number"].to_f || 0.0
case matches.try &.["suffix"].downcase
@@ -259,7 +259,7 @@ def get_referer(env, fallback = "/", unroll = true)
end
referer = referer.request_target
- referer = "/" + referer.gsub(/[^\/?@&%=\-_.0-9a-zA-Z]/, "").lstrip("/\\")
+ referer = "/" + referer.gsub(/[^\/?@&%=\-_.:,0-9a-zA-Z]/, "").lstrip("/\\")
if referer == env.request.path
referer = fallback
diff --git a/src/invidious/routes/account.cr b/src/invidious/routes/account.cr
index 9bb73136..8f69df94 100644
--- a/src/invidious/routes/account.cr
+++ b/src/invidious/routes/account.cr
@@ -203,7 +203,7 @@ module Invidious::Routes::Account
referer = get_referer(env)
if !user
- return env.redirect referer
+ return env.redirect "/login?referer=#{URI.encode_path_segment(env.request.resource)}"
end
user = user.as(User)
@@ -262,6 +262,7 @@ module Invidious::Routes::Account
end
query["token"] = access_token
+ query["username"] = user.email
url.query = query.to_s
env.redirect url.to_s
diff --git a/src/invidious/routes/api/v1/authenticated.cr b/src/invidious/routes/api/v1/authenticated.cr
index 421355bb..6b935312 100644
--- a/src/invidious/routes/api/v1/authenticated.cr
+++ b/src/invidious/routes/api/v1/authenticated.cr
@@ -31,6 +31,29 @@ module Invidious::Routes::API::V1::Authenticated
env.response.status_code = 204
end
+ def self.export_invidious(env)
+ env.response.content_type = "application/json"
+ user = env.get("user").as(User)
+
+ return Invidious::User::Export.to_invidious(user)
+ end
+
+ def self.import_invidious(env)
+ user = env.get("user").as(User)
+
+ begin
+ if body = env.request.body
+ body = env.request.body.not_nil!.gets_to_end
+ else
+ body = "{}"
+ end
+ Invidious::User::Import.from_invidious(user, body)
+ rescue
+ end
+
+ env.response.status_code = 204
+ end
+
def self.feed(env)
env.response.content_type = "application/json"
diff --git a/src/invidious/routes/api/v1/channels.cr b/src/invidious/routes/api/v1/channels.cr
index ca2b2734..bcb4db2c 100644
--- a/src/invidious/routes/api/v1/channels.cr
+++ b/src/invidious/routes/api/v1/channels.cr
@@ -89,6 +89,8 @@ module Invidious::Routes::API::V1::Channels
json.field "descriptionHtml", channel.description_html
json.field "allowedRegions", channel.allowed_regions
+ json.field "tabs", channel.tabs
+ json.field "authorVerified", channel.verified
json.field "latestVideos" do
json.array do
diff --git a/src/invidious/routes/api/v1/misc.cr b/src/invidious/routes/api/v1/misc.cr
index 43d360e6..e499f4d6 100644
--- a/src/invidious/routes/api/v1/misc.cr
+++ b/src/invidious/routes/api/v1/misc.cr
@@ -150,4 +150,31 @@ module Invidious::Routes::API::V1::Misc
response
end
+
+ # resolve channel and clip urls, return the UCID
+ def self.resolve_url(env)
+ env.response.content_type = "application/json"
+ url = env.params.query["url"]?
+
+ return error_json(400, "Missing URL to resolve") if !url
+
+ begin
+ resolved_url = YoutubeAPI.resolve_url(url.as(String))
+ endpoint = resolved_url["endpoint"]
+ pageType = endpoint.dig?("commandMetadata", "webCommandMetadata", "webPageType").try &.as_s || ""
+ if resolved_ucid = endpoint.dig?("watchEndpoint", "videoId")
+ elsif resolved_ucid = endpoint.dig?("browseEndpoint", "browseId")
+ elsif pageType == "WEB_PAGE_TYPE_UNKNOWN"
+ return error_json(400, "Unknown url")
+ end
+ rescue ex
+ return error_json(500, ex)
+ end
+ JSON.build do |json|
+ json.object do
+ json.field "ucid", resolved_ucid.try &.as_s || ""
+ json.field "pageType", pageType
+ end
+ end
+ end
end
diff --git a/src/invidious/routes/api/v1/videos.cr b/src/invidious/routes/api/v1/videos.cr
index 79f7bd3f..f312211e 100644
--- a/src/invidious/routes/api/v1/videos.cr
+++ b/src/invidious/routes/api/v1/videos.cr
@@ -93,45 +93,50 @@ module Invidious::Routes::API::V1::Videos
# as well as some other markup that makes it cumbersome, so we try to fix that here
if caption.name.includes? "auto-generated"
caption_xml = YT_POOL.client &.get(url).body
- caption_xml = XML.parse(caption_xml)
- webvtt = String.build do |str|
- str << <<-END_VTT
- WEBVTT
- Kind: captions
- Language: #{tlang || caption.language_code}
+ if caption_xml.starts_with?("<?xml")
+ webvtt = caption.timedtext_to_vtt(caption_xml, tlang)
+ else
+ caption_xml = XML.parse(caption_xml)
+ webvtt = String.build do |str|
+ str << <<-END_VTT
+ WEBVTT
+ Kind: captions
+ Language: #{tlang || caption.language_code}
- END_VTT
- caption_nodes = caption_xml.xpath_nodes("//transcript/text")
- caption_nodes.each_with_index do |node, i|
- start_time = node["start"].to_f.seconds
- duration = node["dur"]?.try &.to_f.seconds
- duration ||= start_time
+ END_VTT
- if caption_nodes.size > i + 1
- end_time = caption_nodes[i + 1]["start"].to_f.seconds
- else
- end_time = start_time + duration
- end
+ caption_nodes = caption_xml.xpath_nodes("//transcript/text")
+ caption_nodes.each_with_index do |node, i|
+ start_time = node["start"].to_f.seconds
+ duration = node["dur"]?.try &.to_f.seconds
+ duration ||= start_time
- start_time = "#{start_time.hours.to_s.rjust(2, '0')}:#{start_time.minutes.to_s.rjust(2, '0')}:#{start_time.seconds.to_s.rjust(2, '0')}.#{start_time.milliseconds.to_s.rjust(3, '0')}"
- end_time = "#{end_time.hours.to_s.rjust(2, '0')}:#{end_time.minutes.to_s.rjust(2, '0')}:#{end_time.seconds.to_s.rjust(2, '0')}.#{end_time.milliseconds.to_s.rjust(3, '0')}"
+ if caption_nodes.size > i + 1
+ end_time = caption_nodes[i + 1]["start"].to_f.seconds
+ else
+ end_time = start_time + duration
+ end
- text = HTML.unescape(node.content)
- text = text.gsub(/<font color="#[a-fA-F0-9]{6}">/, "")
- text = text.gsub(/<\/font>/, "")
- if md = text.match(/(?<name>.*) : (?<text>.*)/)
- text = "<v #{md["name"]}>#{md["text"]}</v>"
- end
+ start_time = "#{start_time.hours.to_s.rjust(2, '0')}:#{start_time.minutes.to_s.rjust(2, '0')}:#{start_time.seconds.to_s.rjust(2, '0')}.#{start_time.milliseconds.to_s.rjust(3, '0')}"
+ end_time = "#{end_time.hours.to_s.rjust(2, '0')}:#{end_time.minutes.to_s.rjust(2, '0')}:#{end_time.seconds.to_s.rjust(2, '0')}.#{end_time.milliseconds.to_s.rjust(3, '0')}"
- str << <<-END_CUE
- #{start_time} --> #{end_time}
- #{text}
+ text = HTML.unescape(node.content)
+ text = text.gsub(/<font color="#[a-fA-F0-9]{6}">/, "")
+ text = text.gsub(/<\/font>/, "")
+ if md = text.match(/(?<name>.*) : (?<text>.*)/)
+ text = "<v #{md["name"]}>#{md["text"]}</v>"
+ end
+ str << <<-END_CUE
+ #{start_time} --> #{end_time}
+ #{text}
- END_CUE
+
+ END_CUE
+ end
end
end
else
@@ -141,7 +146,12 @@ module Invidious::Routes::API::V1::Videos
#
# See: https://github.com/iv-org/invidious/issues/2391
webvtt = YT_POOL.client &.get("#{url}&format=vtt").body
- .gsub(/([0-9:.]{12} --> [0-9:.]{12}).+/, "\\1")
+ if webvtt.starts_with?("<?xml")
+ webvtt = caption.timedtext_to_vtt(webvtt)
+ else
+ webvtt = YT_POOL.client &.get("#{url}&format=vtt").body
+ .gsub(/([0-9:.]{12} --> [0-9:.]{12}).+/, "\\1")
+ end
end
if title = env.params.query["title"]?
diff --git a/src/invidious/routes/login.cr b/src/invidious/routes/login.cr
index 99fc13a2..6454131a 100644
--- a/src/invidious/routes/login.cr
+++ b/src/invidious/routes/login.cr
@@ -6,14 +6,14 @@ module Invidious::Routes::Login
user = env.get? "user"
- return env.redirect "/feed/subscriptions" if user
+ referer = get_referer(env, "/feed/subscriptions")
+
+ return env.redirect referer if user
if !CONFIG.login_enabled
return error_template(400, "Login has been disabled by administrator.")
end
- referer = get_referer(env, "/feed/subscriptions")
-
email = nil
password = nil
captcha = nil
diff --git a/src/invidious/routes/subscriptions.cr b/src/invidious/routes/subscriptions.cr
index 7b1fa876..0704c05e 100644
--- a/src/invidious/routes/subscriptions.cr
+++ b/src/invidious/routes/subscriptions.cr
@@ -104,33 +104,8 @@ module Invidious::Routes::Subscriptions
if format == "json"
env.response.content_type = "application/json"
env.response.headers["content-disposition"] = "attachment"
- playlists = Invidious::Database::Playlists.select_like_iv(user.email)
-
- return JSON.build do |json|
- json.object do
- json.field "subscriptions", user.subscriptions
- json.field "watch_history", user.watched
- json.field "preferences", user.preferences
- json.field "playlists" do
- json.array do
- playlists.each do |playlist|
- json.object do
- json.field "title", playlist.title
- json.field "description", html_to_content(playlist.description_html)
- json.field "privacy", playlist.privacy.to_s
- json.field "videos" do
- json.array do
- Invidious::Database::PlaylistVideos.select_ids(playlist.id, playlist.index, limit: 500).each do |video_id|
- json.string video_id
- end
- end
- end
- end
- end
- end
- end
- end
- end
+
+ return Invidious::User::Export.to_invidious(user)
else
env.response.content_type = "application/xml"
env.response.headers["content-disposition"] = "attachment"
diff --git a/src/invidious/routing.cr b/src/invidious/routing.cr
index 491022a5..dca2f117 100644
--- a/src/invidious/routing.cr
+++ b/src/invidious/routing.cr
@@ -132,6 +132,8 @@ module Invidious::Routing
get "/c/:user#{path}", Routes::Channels, :brand_redirect
# /user/linustechtips | Not always the same as /c/
get "/user/:user#{path}", Routes::Channels, :brand_redirect
+ # /@LinusTechTips | Handle
+ get "/@:user#{path}", Routes::Channels, :brand_redirect
# /attribution_link?a=anything&u=/channel/UCZYTClx2T1of7BRZ86-8fow
get "/attribution_link#{path}", Routes::Channels, :brand_redirect
# /profile?user=linustechtips
@@ -252,6 +254,9 @@ module Invidious::Routing
get "/api/v1/auth/preferences", {{namespace}}::Authenticated, :get_preferences
post "/api/v1/auth/preferences", {{namespace}}::Authenticated, :set_preferences
+ get "/api/v1/auth/export/invidious", {{namespace}}::Authenticated, :export_invidious
+ post "/api/v1/auth/import/invidious", {{namespace}}::Authenticated, :import_invidious
+
get "/api/v1/auth/feed", {{namespace}}::Authenticated, :feed
get "/api/v1/auth/subscriptions", {{namespace}}::Authenticated, :get_subscriptions
@@ -279,6 +284,7 @@ module Invidious::Routing
get "/api/v1/playlists/:plid", {{namespace}}::Misc, :get_playlist
get "/api/v1/auth/playlists/:plid", {{namespace}}::Misc, :get_playlist
get "/api/v1/mixes/:rdid", {{namespace}}::Misc, :mixes
+ get "/api/v1/resolveurl", {{namespace}}::Misc, :resolve_url
{% end %}
end
end
diff --git a/src/invidious/trending.cr b/src/invidious/trending.cr
index 1f957081..134eb437 100644
--- a/src/invidious/trending.cr
+++ b/src/invidious/trending.cr
@@ -4,11 +4,12 @@ def fetch_trending(trending_type, region, locale)
plid = nil
- if trending_type == "Music"
+ case trending_type.try &.downcase
+ when "music"
params = "4gINGgt5dG1hX2NoYXJ0cw%3D%3D"
- elsif trending_type == "Gaming"
+ when "gaming"
params = "4gIcGhpnYW1pbmdfY29ycHVzX21vc3RfcG9wdWxhcg%3D%3D"
- elsif trending_type == "Movies"
+ when "movies"
params = "4gIKGgh0cmFpbGVycw%3D%3D"
else # Default
params = ""
diff --git a/src/invidious/user/exports.cr b/src/invidious/user/exports.cr
new file mode 100644
index 00000000..b52503c9
--- /dev/null
+++ b/src/invidious/user/exports.cr
@@ -0,0 +1,35 @@
+struct Invidious::User
+ module Export
+ extend self
+
+ def to_invidious(user : User)
+ playlists = Invidious::Database::Playlists.select_like_iv(user.email)
+
+ return JSON.build do |json|
+ json.object do
+ json.field "subscriptions", user.subscriptions
+ json.field "watch_history", user.watched
+ json.field "preferences", user.preferences
+ json.field "playlists" do
+ json.array do
+ playlists.each do |playlist|
+ json.object do
+ json.field "title", playlist.title
+ json.field "description", html_to_content(playlist.description_html)
+ json.field "privacy", playlist.privacy.to_s
+ json.field "videos" do
+ json.array do
+ Invidious::Database::PlaylistVideos.select_ids(playlist.id, playlist.index, limit: CONFIG.playlist_length_limit).each do |video_id|
+ json.string video_id
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end # module
+end
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr
index d626c7d1..436ac82d 100644
--- a/src/invidious/videos.cr
+++ b/src/invidious/videos.cr
@@ -247,6 +247,12 @@ struct Video
info["reason"]?.try &.as_s
end
+ def music : Array(VideoMusic)
+ info["music"].as_a.map { |music_json|
+ VideoMusic.new(music_json["album"].as_s, music_json["artist"].as_s, music_json["license"].as_s)
+ }
+ end
+
# Macros defining getters/setters for various types of data
private macro getset_string(name)
diff --git a/src/invidious/videos/caption.cr b/src/invidious/videos/caption.cr
index 4642c1a7..13f81a31 100644
--- a/src/invidious/videos/caption.cr
+++ b/src/invidious/videos/caption.cr
@@ -31,6 +31,72 @@ module Invidious::Videos
return captions_list
end
+ def timedtext_to_vtt(timedtext : String, tlang = nil) : String
+ # In the future, we could just directly work with the url. This is more of a POC
+ cues = [] of XML::Node
+ tree = XML.parse(timedtext)
+ tree = tree.children.first
+
+ tree.children.each do |item|
+ if item.name == "body"
+ item.children.each do |cue|
+ if cue.name == "p" && !(cue.children.size == 1 && cue.children[0].content == "\n")
+ cues << cue
+ end
+ end
+ break
+ end
+ end
+ result = String.build do |result|
+ result << <<-END_VTT
+ WEBVTT
+ Kind: captions
+ Language: #{tlang || @language_code}
+
+
+ END_VTT
+
+ result << "\n\n"
+
+ cues.each_with_index do |node, i|
+ start_time = node["t"].to_f.milliseconds
+
+ duration = node["d"]?.try &.to_f.milliseconds
+
+ duration ||= start_time
+
+ if cues.size > i + 1
+ end_time = cues[i + 1]["t"].to_f.milliseconds
+ else
+ end_time = start_time + duration
+ end
+
+ # start_time
+ result << start_time.hours.to_s.rjust(2, '0')
+ result << ':' << start_time.minutes.to_s.rjust(2, '0')
+ result << ':' << start_time.seconds.to_s.rjust(2, '0')
+ result << '.' << start_time.milliseconds.to_s.rjust(3, '0')
+
+ result << " --> "
+
+ # end_time
+ result << end_time.hours.to_s.rjust(2, '0')
+ result << ':' << end_time.minutes.to_s.rjust(2, '0')
+ result << ':' << end_time.seconds.to_s.rjust(2, '0')
+ result << '.' << end_time.milliseconds.to_s.rjust(3, '0')
+
+ result << "\n"
+
+ node.children.each do |s|
+ result << s.content
+ end
+ result << "\n"
+ result << "\n"
+ end
+ end
+ return result
+ end
+
# List of all caption languages available on Youtube.
LANGUAGES = {
"",
diff --git a/src/invidious/videos/music.cr b/src/invidious/videos/music.cr
new file mode 100644
index 00000000..402ae46f
--- /dev/null
+++ b/src/invidious/videos/music.cr
@@ -0,0 +1,12 @@
+require "json"
+
+struct VideoMusic
+ include JSON::Serializable
+
+ property album : String
+ property artist : String
+ property license : String
+
+ def initialize(@album : String, @artist : String, @license : String)
+ end
+end
diff --git a/src/invidious/videos/parser.cr b/src/invidious/videos/parser.cr
index 5c323975..cf43f1be 100644
--- a/src/invidious/videos/parser.cr
+++ b/src/invidious/videos/parser.cr
@@ -311,6 +311,33 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
end
end
+ # Music section
+
+ music_list = [] of VideoMusic
+ music_desclist = player_response.dig?(
+ "engagementPanels", 1, "engagementPanelSectionListRenderer",
+ "content", "structuredDescriptionContentRenderer", "items", 2,
+ "videoDescriptionMusicSectionRenderer", "carouselLockups"
+ )
+
+ music_desclist.try &.as_a.each do |music_desc|
+ artist = nil
+ album = nil
+ music_license = nil
+
+ music_desc.dig?("carouselLockupRenderer", "infoRows").try &.as_a.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_license = extract_text(desc.dig?("infoRowRenderer", "expandedMetadata"))
+ end
+ end
+ music_list << VideoMusic.new(album.to_s, artist.to_s, music_license.to_s)
+ end
+
# Author infos
author = video_details["author"]?.try &.as_s
@@ -361,6 +388,8 @@ 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" => JSON.parse(music_list.to_json),
# 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 a6f2e524..666eb3b0 100644
--- a/src/invidious/views/watch.ecr
+++ b/src/invidious/views/watch.ecr
@@ -235,6 +235,28 @@ we're going to need to do it here in order to allow for translations.
<hr>
+ <% if !video.music.empty? %>
+ <input id="music-desc-expansion" type="checkbox"/>
+ <label for="music-desc-expansion">
+ <h3 id="music-description-title">
+ <%= translate(locale, "Music in this video") %>
+ <span class="icon ion-ios-arrow-up"></span>
+ <span class="icon ion-ios-arrow-down"></span>
+ </h3>
+ </label>
+
+ <div id="music-description-box">
+ <% video.music.each do |music| %>
+ <div class="music-item">
+ <p id="music-artist"><%= translate(locale, "Artist: ") %><%= music.artist %></p>
+ <p id="music-album"><%= translate(locale, "Album: ") %><%= music.album %></p>
+ <p id="music-license"><%= translate(locale, "License: ") %><%= music.license %></p>
+ </div>
+ <% end %>
+ </div>
+ <hr>
+
+ <% end %>
<div id="comments">
<% if nojs %>
<%= comment_html %>
diff --git a/src/invidious/yt_backend/extractors.cr b/src/invidious/yt_backend/extractors.cr
index 65d107b2..b14ad7b9 100644
--- a/src/invidious/yt_backend/extractors.cr
+++ b/src/invidious/yt_backend/extractors.cr
@@ -172,7 +172,17 @@ private module Parsers
# When public subscriber count is disabled, the subscriberCountText isn't sent by InnerTube.
# Always simpleText
# TODO change default value to nil
+
subscriber_count = item_contents.dig?("subscriberCountText", "simpleText")
+
+ # Since youtube added channel handles, `VideoCountText` holds the number of
+ # subscribers and `subscriberCountText` holds the handle, except when the
+ # channel doesn't have a handle (e.g: some topic music channels).
+ # See https://github.com/iv-org/invidious/issues/3394#issuecomment-1321261688
+ if !subscriber_count || !subscriber_count.as_s.includes? " subscriber"
+ subscriber_count = item_contents.dig?("videoCountText", "simpleText")
+ end
+ subscriber_count = subscriber_count
.try { |s| short_text_to_number(s.as_s.split(" ")[0]).to_i32 } || 0
# Auto-generated channels doesn't have videoCountText
@@ -682,7 +692,11 @@ module HelperExtractors
# Returns a 0 when it's unable to do so
def self.get_video_count(container : JSON::Any) : Int32
if box = container["videoCountText"]?
- return extract_text(box).try &.gsub(/\D/, "").to_i || 0
+ if (extracted_text = extract_text(box)) && !extracted_text.includes? " subscriber"
+ return extracted_text.gsub(/\D/, "").to_i
+ else
+ return 0
+ end
elsif box = container["videoCount"]?
return box.as_s.to_i
else