From c5ccefe6f7c127625c821d3b6836c23962a2b5b0 Mon Sep 17 00:00:00 2001 From: Svallinn <41585298+Svallinn@users.noreply.github.com> Date: Fri, 26 Mar 2021 03:52:28 +0000 Subject: [PATCH] Parse response to JSON instead of using regex --- src/invidious/channels.cr | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/invidious/channels.cr b/src/invidious/channels.cr index 30138d82..2d5b4475 100644 --- a/src/invidious/channels.cr +++ b/src/invidious/channels.cr @@ -358,16 +358,20 @@ end def fetch_channel_playlists(ucid, author, continuation, sort_by) if continuation response_json = request_youtube_api_browse(continuation) - result = JSON.parse(response_json.match(/"continuationItems": (?\[.*\]),/m).try &.["items"] || "{}") + # result = JSON.parse(response_json.match(/"continuationItems": (?\[.*\]),/m).try &.["items"] || "{}") + result = JSON.parse(response_json) + continuationItems = result["onResponseReceivedActions"]? + .try &.[0]["appendContinuationItemsAction"]["continuationItems"] - return [] of SearchItem, nil if result.size == 0 + return [] of SearchItem, nil if !continuationItems items = [] of SearchItem - result.as_a.select(&.as_h.has_key?("gridPlaylistRenderer")).each { |item| + continuationItems.as_a.select(&.as_h.has_key?("gridPlaylistRenderer")).each { |item| extract_item(item, author, ucid).try { |t| items << t } } - continuation = result.as_a.last["continuationItemRenderer"]?.try &.["continuationEndpoint"]["continuationCommand"]["token"].as_s + continuation = continuationItems.as_a.last["continuationItemRenderer"]? + .try &.["continuationEndpoint"]["continuationCommand"]["token"].as_s else url = "/channel/#{ucid}/playlists?flow=list&view=1"