Skip to content

Commit

Permalink
Fix watch_videos endpoint
Browse files Browse the repository at this point in the history
Playlists created by `watch_videos` do not have an author which caused a crash
previously.
  • Loading branch information
saltycrys committed Jan 4, 2021
1 parent 8b56a03 commit 36e9fb9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/invidious.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2621,6 +2621,8 @@ end

begin
playlist = get_playlist(PG_DB, plid, locale)
rescue ex : InfoException
next error_json(404, ex)
rescue ex
next error_json(404, "Playlist does not exist.")
end
Expand Down
24 changes: 16 additions & 8 deletions src/invidious/playlists.cr
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,13 @@ def fetch_playlist(plid, locale)
end

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

title = playlist_info["title"]?.try &.["runs"][0]?.try &.["text"]?.try &.as_s || ""

desc_item = playlist_info["description"]?
Expand All @@ -392,14 +396,18 @@ def fetch_playlist(plid, locale)
end
end

author_info = initial_data["sidebar"]?.try &.["playlistSidebarRenderer"]?.try &.["items"]?.try &.[1]["playlistSidebarSecondaryInfoRenderer"]?
.try &.["videoOwner"]["videoOwnerRenderer"]?

raise InfoException.new("Could not extract author info") if !author_info
if playlist_sidebar_renderer.size < 2
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

author_thumbnail = author_info["thumbnail"]["thumbnails"][0]["url"]?.try &.as_s || ""
author = author_info["title"]["runs"][0]["text"]?.try &.as_s || ""
ucid = author_info["title"]["runs"][0]["navigationEndpoint"]["browseEndpoint"]["browseId"]?.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 || ""
end

return Playlist.new({
title: title,
Expand Down

0 comments on commit 36e9fb9

Please sign in to comment.