mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-08-14.git
synced 2024-08-15 00:53:20 +00:00
Parse response to JSON instead of using regex
This commit is contained in:
parent
e248e7ebaf
commit
c5ccefe6f7
1 changed files with 8 additions and 4 deletions
|
@ -358,16 +358,20 @@ end
|
||||||
def fetch_channel_playlists(ucid, author, continuation, sort_by)
|
def fetch_channel_playlists(ucid, author, continuation, sort_by)
|
||||||
if continuation
|
if continuation
|
||||||
response_json = request_youtube_api_browse(continuation)
|
response_json = request_youtube_api_browse(continuation)
|
||||||
result = JSON.parse(response_json.match(/"continuationItems": (?<items>\[.*\]),/m).try &.["items"] || "{}")
|
# result = JSON.parse(response_json.match(/"continuationItems": (?<items>\[.*\]),/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
|
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 }
|
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
|
else
|
||||||
url = "/channel/#{ucid}/playlists?flow=list&view=1"
|
url = "/channel/#{ucid}/playlists?flow=list&view=1"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue