mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-08-14.git
synced 2024-08-15 00:53:20 +00:00
Merge pull request #1633 from saltycrys/fix-watch_videos
Fix `watch_videos` endpoint
This commit is contained in:
commit
e036d89a86
3 changed files with 20 additions and 8 deletions
|
@ -2621,6 +2621,8 @@ end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
playlist = get_playlist(PG_DB, plid, locale)
|
playlist = get_playlist(PG_DB, plid, locale)
|
||||||
|
rescue ex : InfoException
|
||||||
|
next error_json(404, ex)
|
||||||
rescue ex
|
rescue ex
|
||||||
next error_json(404, "Playlist does not exist.")
|
next error_json(404, "Playlist does not exist.")
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,6 +26,7 @@ def error_template_helper(env : HTTP::Server::Context, config : Config, locale :
|
||||||
if exception.is_a?(InfoException)
|
if exception.is_a?(InfoException)
|
||||||
return error_template_helper(env, config, locale, status_code, exception.message || "")
|
return error_template_helper(env, config, locale, status_code, exception.message || "")
|
||||||
end
|
end
|
||||||
|
env.response.content_type = "text/html"
|
||||||
env.response.status_code = status_code
|
env.response.status_code = status_code
|
||||||
issue_template = %(Title: `#{exception.message} (#{exception.class})`)
|
issue_template = %(Title: `#{exception.message} (#{exception.class})`)
|
||||||
issue_template += %(\nDate: `#{Time::Format::ISO_8601_DATE_TIME.format(Time.utc)}`)
|
issue_template += %(\nDate: `#{Time::Format::ISO_8601_DATE_TIME.format(Time.utc)}`)
|
||||||
|
@ -43,6 +44,7 @@ def error_template_helper(env : HTTP::Server::Context, config : Config, locale :
|
||||||
end
|
end
|
||||||
|
|
||||||
def error_template_helper(env : HTTP::Server::Context, config : Config, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String)
|
def error_template_helper(env : HTTP::Server::Context, config : Config, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String)
|
||||||
|
env.response.content_type = "text/html"
|
||||||
env.response.status_code = status_code
|
env.response.status_code = status_code
|
||||||
error_message = translate(locale, message)
|
error_message = translate(locale, message)
|
||||||
return templated "error"
|
return templated "error"
|
||||||
|
|
|
@ -365,9 +365,13 @@ def fetch_playlist(plid, locale)
|
||||||
end
|
end
|
||||||
|
|
||||||
initial_data = extract_initial_data(response.body)
|
initial_data = extract_initial_data(response.body)
|
||||||
playlist_info = initial_data["sidebar"]?.try &.["playlistSidebarRenderer"]?.try &.["items"]?.try &.[0]["playlistSidebarPrimaryInfoRenderer"]?
|
|
||||||
|
|
||||||
|
playlist_sidebar_renderer = initial_data["sidebar"]?.try &.["playlistSidebarRenderer"]?.try &.["items"]?
|
||||||
|
raise InfoException.new("Could not extract playlistSidebarRenderer.") if !playlist_sidebar_renderer
|
||||||
|
|
||||||
|
playlist_info = playlist_sidebar_renderer[0]["playlistSidebarPrimaryInfoRenderer"]?
|
||||||
raise InfoException.new("Could not extract playlist info") if !playlist_info
|
raise InfoException.new("Could not extract playlist info") if !playlist_info
|
||||||
|
|
||||||
title = playlist_info["title"]?.try &.["runs"][0]?.try &.["text"]?.try &.as_s || ""
|
title = playlist_info["title"]?.try &.["runs"][0]?.try &.["text"]?.try &.as_s || ""
|
||||||
|
|
||||||
desc_item = playlist_info["description"]?
|
desc_item = playlist_info["description"]?
|
||||||
|
@ -392,14 +396,18 @@ def fetch_playlist(plid, locale)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
author_info = initial_data["sidebar"]?.try &.["playlistSidebarRenderer"]?.try &.["items"]?.try &.[1]["playlistSidebarSecondaryInfoRenderer"]?
|
if playlist_sidebar_renderer.size < 2
|
||||||
.try &.["videoOwner"]["videoOwnerRenderer"]?
|
author = ""
|
||||||
|
author_thumbnail = ""
|
||||||
|
ucid = ""
|
||||||
|
else
|
||||||
|
author_info = playlist_sidebar_renderer[1]["playlistSidebarSecondaryInfoRenderer"]?.try &.["videoOwner"]["videoOwnerRenderer"]?
|
||||||
raise InfoException.new("Could not extract author info") if !author_info
|
raise InfoException.new("Could not extract author info") if !author_info
|
||||||
|
|
||||||
author_thumbnail = author_info["thumbnail"]["thumbnails"][0]["url"]?.try &.as_s || ""
|
|
||||||
author = author_info["title"]["runs"][0]["text"]?.try &.as_s || ""
|
author = author_info["title"]["runs"][0]["text"]?.try &.as_s || ""
|
||||||
|
author_thumbnail = author_info["thumbnail"]["thumbnails"][0]["url"]?.try &.as_s || ""
|
||||||
ucid = author_info["title"]["runs"][0]["navigationEndpoint"]["browseEndpoint"]["browseId"]?.try &.as_s || ""
|
ucid = author_info["title"]["runs"][0]["navigationEndpoint"]["browseEndpoint"]["browseId"]?.try &.as_s || ""
|
||||||
|
end
|
||||||
|
|
||||||
return Playlist.new({
|
return Playlist.new({
|
||||||
title: title,
|
title: title,
|
||||||
|
|
Loading…
Reference in a new issue