mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-08-14.git
synced 2024-08-15 00:53:20 +00:00
Add produce_channel_playlists_url
This commit is contained in:
parent
3cce74d364
commit
7a9ef0d664
4 changed files with 121 additions and 9 deletions
|
@ -16,9 +16,9 @@ describe "Helpers" do
|
||||||
|
|
||||||
produce_channel_videos_url(ucid: "UCXuqSBlHAE6Xw-yeJA0Tunw", page: 20).should eq("/browse_ajax?continuation=4qmFsgJEEhhVQ1h1cVNCbEhBRTZYdy15ZUpBMFR1bncaKEVnWjJhV1JsYjNNd0FqZ0JZQUZxQUxnQkFDQUFlZ0l5TUElM0QlM0Q%3D&gl=US&hl=en")
|
produce_channel_videos_url(ucid: "UCXuqSBlHAE6Xw-yeJA0Tunw", page: 20).should eq("/browse_ajax?continuation=4qmFsgJEEhhVQ1h1cVNCbEhBRTZYdy15ZUpBMFR1bncaKEVnWjJhV1JsYjNNd0FqZ0JZQUZxQUxnQkFDQUFlZ0l5TUElM0QlM0Q%3D&gl=US&hl=en")
|
||||||
|
|
||||||
produce_channel_videos_url(ucid: "UC-9-kyTW8ZkZNDHQJ6FgpwQ", auto_generated: true).should eq("/browse_ajax?continuation=4qmFsgJIEhhVQy05LWt5VFc4WmtaTkRIUUo2Rmdwd1EaLEVnWjJhV1JsYjNNd0FqZ0JZQUZxQUxnQkFDQTJlZ294TlRRNU5qQXpOelE1&gl=US&hl=en")
|
produce_channel_videos_url(ucid: "UC-9-kyTW8ZkZNDHQJ6FgpwQ", auto_generated: true).should eq("/browse_ajax?continuation=4qmFsgJIEhhVQy05LWt5VFc4WmtaTkRIUUo2Rmdwd1EaLEVnWjJhV1JsYjNNd0FqZ0JZQUZxQUxnQkFDQTJlZ294TlRVeU1ESXlPVFE1&gl=US&hl=en")
|
||||||
|
|
||||||
produce_channel_videos_url(ucid: "UC-9-kyTW8ZkZNDHQJ6FgpwQ", page: 20, auto_generated: true, sort_by: "popular").should eq("/browse_ajax?continuation=4qmFsgJOEhhVQy05LWt5VFc4WmtaTkRIUUo2Rmdwd1EaMkVnWjJhV1JsYjNNd0FqZ0JZQUZxQUxnQkFDQTJlZ294TkRrNU5Ea3hOelE1R0FFJTNE&gl=US&hl=en")
|
produce_channel_videos_url(ucid: "UC-9-kyTW8ZkZNDHQJ6FgpwQ", page: 20, auto_generated: true, sort_by: "popular").should eq("/browse_ajax?continuation=4qmFsgJOEhhVQy05LWt5VFc4WmtaTkRIUUo2Rmdwd1EaMkVnWjJhV1JsYjNNd0FqZ0JZQUZxQUxnQkFDQTJlZ294TlRBeU1UY3dNVFE1R0FFJTNE&gl=US&hl=en")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -218,7 +218,8 @@ def produce_channel_videos_url(ucid, page = 1, auto_generated = nil, sort_by = "
|
||||||
meta.write(Bytes[0x6a, 0x00])
|
meta.write(Bytes[0x6a, 0x00])
|
||||||
meta.write(Bytes[0xb8, 0x01, 0x00])
|
meta.write(Bytes[0xb8, 0x01, 0x00])
|
||||||
|
|
||||||
meta.write(Bytes[0x20, switch, 0x7a, page.size])
|
meta.write(Bytes[0x20, switch])
|
||||||
|
meta.write(Bytes[0x7a, page.size])
|
||||||
meta.print(page)
|
meta.print(page)
|
||||||
|
|
||||||
case sort_by
|
case sort_by
|
||||||
|
|
|
@ -240,21 +240,21 @@ def get_referer(env, fallback = "/")
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_var_int(bytes)
|
def read_var_int(bytes)
|
||||||
numRead = 0
|
num_read = 0
|
||||||
result = 0
|
result = 0
|
||||||
|
|
||||||
read = bytes[numRead]
|
read = bytes[num_read]
|
||||||
|
|
||||||
if bytes.size == 1
|
if bytes.size == 1
|
||||||
result = bytes[0].to_i32
|
result = bytes[0].to_i32
|
||||||
else
|
else
|
||||||
while ((read & 0b10000000) != 0)
|
while ((read & 0b10000000) != 0)
|
||||||
read = bytes[numRead].to_u64
|
read = bytes[num_read].to_u64
|
||||||
value = (read & 0b01111111)
|
value = (read & 0b01111111)
|
||||||
result |= (value << (7 * numRead))
|
result |= (value << (7 * num_read))
|
||||||
|
|
||||||
numRead += 1
|
num_read += 1
|
||||||
if numRead > 5
|
if num_read > 5
|
||||||
raise "VarInt is too big"
|
raise "VarInt is too big"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -161,6 +161,117 @@ def produce_playlist_url(id, index)
|
||||||
return url
|
return url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def produce_channel_playlists_url(ucid, cursor, sort = "newest")
|
||||||
|
cursor = Base64.urlsafe_encode(cursor, false)
|
||||||
|
|
||||||
|
meta = IO::Memory.new
|
||||||
|
meta.write(Bytes[0x12, 0x09])
|
||||||
|
meta.print("playlists")
|
||||||
|
|
||||||
|
# TODO: Look at 0x01, 0x00
|
||||||
|
case sort
|
||||||
|
when "oldest", "oldest_created"
|
||||||
|
meta.write(Bytes[0x18, 0x02])
|
||||||
|
when "newest", "newest_created"
|
||||||
|
meta.write(Bytes[0x18, 0x03])
|
||||||
|
when "last", "last_added"
|
||||||
|
meta.write(Bytes[0x18, 0x04])
|
||||||
|
end
|
||||||
|
|
||||||
|
meta.write(Bytes[0x20, 0x01])
|
||||||
|
meta.write(Bytes[0x30, 0x02])
|
||||||
|
meta.write(Bytes[0x38, 0x01])
|
||||||
|
meta.write(Bytes[0x60, 0x01])
|
||||||
|
meta.write(Bytes[0x6a, 0x00])
|
||||||
|
|
||||||
|
meta.write(Bytes[0x7a, cursor.size])
|
||||||
|
meta.print(cursor)
|
||||||
|
|
||||||
|
meta.write(Bytes[0xb8, 0x01, 0x00])
|
||||||
|
|
||||||
|
meta.rewind
|
||||||
|
meta = Base64.urlsafe_encode(meta.to_slice)
|
||||||
|
meta = URI.escape(meta)
|
||||||
|
|
||||||
|
continuation = IO::Memory.new
|
||||||
|
continuation.write(Bytes[0x12, ucid.size])
|
||||||
|
continuation.print(ucid)
|
||||||
|
|
||||||
|
continuation.write(Bytes[0x1a])
|
||||||
|
continuation.write(write_var_int(meta.size))
|
||||||
|
continuation.print(meta)
|
||||||
|
|
||||||
|
continuation.rewind
|
||||||
|
continuation = continuation.gets_to_end
|
||||||
|
|
||||||
|
wrapper = IO::Memory.new
|
||||||
|
wrapper.write(Bytes[0xe2, 0xa9, 0x85, 0xb2, 0x02])
|
||||||
|
wrapper.write(write_var_int(continuation.size))
|
||||||
|
wrapper.print(continuation)
|
||||||
|
wrapper.rewind
|
||||||
|
|
||||||
|
wrapper = Base64.urlsafe_encode(wrapper.to_slice)
|
||||||
|
wrapper = URI.escape(wrapper)
|
||||||
|
|
||||||
|
url = "/browse_ajax?continuation=#{wrapper}&gl=US&hl=en"
|
||||||
|
|
||||||
|
return url
|
||||||
|
end
|
||||||
|
|
||||||
|
def extract_channel_playlists_cursor(url)
|
||||||
|
wrapper = HTTP::Params.parse(URI.parse(url).query.not_nil!)["continuation"]
|
||||||
|
|
||||||
|
wrapper = URI.unescape(wrapper)
|
||||||
|
wrapper = Base64.decode(wrapper)
|
||||||
|
|
||||||
|
# 0xe2 0xa9 0x85 0xb2 0x02
|
||||||
|
wrapper += 5
|
||||||
|
|
||||||
|
continuation_size = read_var_int(wrapper[0, 4])
|
||||||
|
wrapper += write_var_int(continuation_size).size
|
||||||
|
continuation = wrapper[0, continuation_size]
|
||||||
|
|
||||||
|
# 0x12
|
||||||
|
continuation += 1
|
||||||
|
ucid_size = continuation[0]
|
||||||
|
continuation += 1
|
||||||
|
ucid = continuation[0, ucid_size]
|
||||||
|
continuation += ucid_size
|
||||||
|
|
||||||
|
# 0x1a
|
||||||
|
continuation += 1
|
||||||
|
meta_size = read_var_int(continuation[0, 4])
|
||||||
|
continuation += write_var_int(meta_size).size
|
||||||
|
meta = continuation[0, meta_size]
|
||||||
|
continuation += meta_size
|
||||||
|
|
||||||
|
meta = String.new(meta)
|
||||||
|
meta = URI.unescape(meta)
|
||||||
|
meta = Base64.decode(meta)
|
||||||
|
|
||||||
|
# 0x12 0x09 playlists
|
||||||
|
meta += 11
|
||||||
|
|
||||||
|
until meta[0] == 0x7a
|
||||||
|
tag = read_var_int(meta[0, 4])
|
||||||
|
meta += write_var_int(tag).size
|
||||||
|
value = meta[0]
|
||||||
|
meta += 1
|
||||||
|
end
|
||||||
|
|
||||||
|
# 0x7a
|
||||||
|
meta += 1
|
||||||
|
cursor_size = meta[0]
|
||||||
|
meta += 1
|
||||||
|
cursor = meta[0, cursor_size]
|
||||||
|
|
||||||
|
cursor = String.new(cursor)
|
||||||
|
cursor = URI.unescape(cursor)
|
||||||
|
cursor = Base64.decode_string(cursor)
|
||||||
|
|
||||||
|
return cursor
|
||||||
|
end
|
||||||
|
|
||||||
def fetch_playlist(plid, locale)
|
def fetch_playlist(plid, locale)
|
||||||
client = make_client(YT_URL)
|
client = make_client(YT_URL)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue