From c58841100a2507c41276d4f6d195b7d221034e0b Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sun, 27 Oct 2019 21:44:17 -0400 Subject: [PATCH] Fix extractor for channel community cursor --- spec/helpers_spec.cr | 4 ++-- src/invidious/channels.cr | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/spec/helpers_spec.cr b/spec/helpers_spec.cr index 7ede7e7a..2719af8d 100644 --- a/spec/helpers_spec.cr +++ b/spec/helpers_spec.cr @@ -117,9 +117,9 @@ describe "Helper" do describe "#extract_channel_community_cursor" do it "correctly extracts a community cursor from a given continuation" do extract_channel_community_cursor("4qmFsgIsEhhVQ0NqOTU2SUY2MkZiVDdHb3VzemFqOXcaEEVnbGpiMjF0ZFc1cGRIbTQ%3D").should eq("Egljb21tdW5pdHk=") - extract_channel_community_cursor("4qmFsgJoEhhVQ0NqOTU2SUY2MkZiVDdHb3VzemFqOXcaTEVnbGpiMjF0ZFc1cGRIbTRBUUNxQXlRYUlCSWFWV2QzY0U5TlFtVndXRWRqY2xoc1VIZzJXalJCWVVGQ1ExRklaR2dES0FBJTI1M0Q%3D").should eq("Egljb21tdW5pdHm4AQCqAyYaIhIcVWd3cE9NQmVwWEdjclhsUHg2WjRBYUFCQ1E9PUhkaAMoAA==") + extract_channel_community_cursor("4qmFsgJoEhhVQ0NqOTU2SUY2MkZiVDdHb3VzemFqOXcaTEVnbGpiMjF0ZFc1cGRIbTRBUUNxQXlRYUlCSWFWV2QzY0U5TlFtVndXRWRqY2xoc1VIZzJXalJCWVVGQ1ExRklaR2dES0FBJTI1M0Q%3D").should eq("Egljb21tdW5pdHm4AQCqAyQaIEhkaAMSGlVnd3BPTUJlcFhHY3JYbFB4Nlo0QWFBQkNRKAA=") - extract_channel_community_cursor("4qmFsgJoEhhVQy1sSEpaUjNHcXhtMjRfVmRfQUo1WXcaTEVnbGpiMjF0ZFc1cGRIbTRBUUNxQXlRYUlCSWFWV2Q1UlRJMk5XMXJVa2syY0U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cVWd5RTI2NW1rUkk2cE9uS21nbDRBYUFCQ1E9PUhkaAMoYw==") end end diff --git a/src/invidious/channels.cr b/src/invidious/channels.cr index 4cf322b0..c5381863 100644 --- a/src/invidious/channels.cr +++ b/src/invidious/channels.cr @@ -808,11 +808,23 @@ def produce_channel_community_continuation(ucid, cursor) end def extract_channel_community_cursor(continuation) - cursor = URI.decode_www_form(continuation) + object = URI.decode_www_form(continuation) .try { |i| Base64.decode(i) } .try { |i| IO::Memory.new(i) } .try { |i| Protodec::Any.parse(i) } - .try { |i| Protodec::Any.cast_json(i["80226972:0:embedded"]["3:1:base64"].as_h) } + .try { |i| i["80226972:0:embedded"]["3:1:base64"].as_h } + + if object["53:2:embedded"]?.try &.["3:0:embedded"]? + object["53:2:embedded"]["3:0:embedded"]["2:0:string"] = object["53:2:embedded"]["3:0:embedded"] + .try { |i| i["2:0:base64"].as_h } + .try { |i| Protodec::Any.cast_json(i) } + .try { |i| Protodec::Any.from_json(i) } + .try { |i| Base64.urlsafe_encode(i, padding: false) } + + object["53:2:embedded"]["3:0:embedded"].as_h.delete("2:0:base64") + end + + cursor = Protodec::Any.cast_json(object) .try { |i| Protodec::Any.from_json(i) } .try { |i| Base64.urlsafe_encode(i) }