Parse response to JSON instead of using regex
This commit is contained in:
parent
e248e7ebaf
commit
c5ccefe6f7
|
@ -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": (?<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
|
||||
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"
|
||||
|
||||
|
|
Loading…
Reference in a new issue