|
|
|
@ -432,188 +432,108 @@ def fetch_channel_playlists(ucid, author, auto_generated, continuation, sort_by)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def produce_channel_videos_url(ucid, page = 1, auto_generated = nil, sort_by = "newest")
|
|
|
|
|
object = {
|
|
|
|
|
"80226972:embedded" => {
|
|
|
|
|
"2:string" => ucid,
|
|
|
|
|
"3:base64" => {
|
|
|
|
|
"2:string" => "videos",
|
|
|
|
|
"6:varint": 2_i64,
|
|
|
|
|
"7:varint": 1_i64,
|
|
|
|
|
"12:varint": 1_i64,
|
|
|
|
|
"13:string": "",
|
|
|
|
|
"23:varint": 0_i64,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if auto_generated
|
|
|
|
|
seed = Time.unix(1525757349)
|
|
|
|
|
|
|
|
|
|
until seed >= Time.utc
|
|
|
|
|
seed += 1.month
|
|
|
|
|
end
|
|
|
|
|
timestamp = seed - (page - 1).months
|
|
|
|
|
|
|
|
|
|
page = "#{timestamp.to_unix}"
|
|
|
|
|
switch = 0x36
|
|
|
|
|
object["80226972:embedded"]["3:base64"].as(Hash)["4:varint"] = 0x36_i64
|
|
|
|
|
object["80226972:embedded"]["3:base64"].as(Hash)["15:string"] = "#{timestamp.to_unix}"
|
|
|
|
|
else
|
|
|
|
|
page = "#{page}"
|
|
|
|
|
switch = 0x00
|
|
|
|
|
object["80226972:embedded"]["3:base64"].as(Hash)["4:varint"] = 0_i64
|
|
|
|
|
object["80226972:embedded"]["3:base64"].as(Hash)["15:string"] = "#{page}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
data = IO::Memory.new
|
|
|
|
|
data.write_byte 0x12
|
|
|
|
|
data.write_byte 0x06
|
|
|
|
|
data.print "videos"
|
|
|
|
|
|
|
|
|
|
data.write Bytes[0x30, 0x02]
|
|
|
|
|
data.write Bytes[0x38, 0x01]
|
|
|
|
|
data.write Bytes[0x60, 0x01]
|
|
|
|
|
data.write Bytes[0x6a, 0x00]
|
|
|
|
|
data.write Bytes[0xb8, 0x01, 0x00]
|
|
|
|
|
|
|
|
|
|
data.write Bytes[0x20, switch]
|
|
|
|
|
data.write_byte 0x7a
|
|
|
|
|
VarInt.to_io(data, page.bytesize)
|
|
|
|
|
data.print page
|
|
|
|
|
|
|
|
|
|
case sort_by
|
|
|
|
|
when "newest"
|
|
|
|
|
# Empty tags can be omitted
|
|
|
|
|
# data.write(Bytes[0x18,0x00])
|
|
|
|
|
when "popular"
|
|
|
|
|
data.write Bytes[0x18, 0x01]
|
|
|
|
|
object["80226972:embedded"]["3:base64"].as(Hash)["3:varint"] = 0x01_i64
|
|
|
|
|
when "oldest"
|
|
|
|
|
data.write Bytes[0x18, 0x02]
|
|
|
|
|
object["80226972:embedded"]["3:base64"].as(Hash)["3:varint"] = 0x02_i64
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
data = Base64.urlsafe_encode(data)
|
|
|
|
|
cursor = URI.encode_www_form(data)
|
|
|
|
|
|
|
|
|
|
data = IO::Memory.new
|
|
|
|
|
|
|
|
|
|
data.write_byte 0x12
|
|
|
|
|
VarInt.to_io(data, ucid.bytesize)
|
|
|
|
|
data.print ucid
|
|
|
|
|
object["80226972:embedded"]["3:string"] = Base64.urlsafe_encode(Protodec::Any.from_json(Protodec::Any.cast_json(object["80226972:embedded"]["3:base64"])))
|
|
|
|
|
object["80226972:embedded"].delete("3:base64")
|
|
|
|
|
|
|
|
|
|
data.write_byte 0x1a
|
|
|
|
|
VarInt.to_io(data, cursor.bytesize)
|
|
|
|
|
data.print cursor
|
|
|
|
|
continuation = object.try { |i| Protodec::Any.cast_json(object) }
|
|
|
|
|
.try { |i| Protodec::Any.from_json(i) }
|
|
|
|
|
.try { |i| Base64.urlsafe_encode(i) }
|
|
|
|
|
.try { |i| URI.encode_www_form(i) }
|
|
|
|
|
|
|
|
|
|
data.rewind
|
|
|
|
|
|
|
|
|
|
buffer = IO::Memory.new
|
|
|
|
|
buffer.write Bytes[0xe2, 0xa9, 0x85, 0xb2, 0x02]
|
|
|
|
|
VarInt.to_io(buffer, data.bytesize)
|
|
|
|
|
|
|
|
|
|
IO.copy data, buffer
|
|
|
|
|
|
|
|
|
|
continuation = Base64.urlsafe_encode(buffer)
|
|
|
|
|
continuation = URI.encode_www_form(continuation)
|
|
|
|
|
|
|
|
|
|
url = "/browse_ajax?continuation=#{continuation}&gl=US&hl=en"
|
|
|
|
|
|
|
|
|
|
return url
|
|
|
|
|
return "/browse_ajax?continuation=#{continuation}&gl=US&hl=en"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def produce_channel_playlists_url(ucid, cursor, sort = "newest", auto_generated = false)
|
|
|
|
|
object = {
|
|
|
|
|
"80226972:embedded" => {
|
|
|
|
|
"2:string" => ucid,
|
|
|
|
|
"3:base64" => {
|
|
|
|
|
"2:string" => "playlist",
|
|
|
|
|
"6:varint": 2_i64,
|
|
|
|
|
"7:varint": 1_i64,
|
|
|
|
|
"12:varint": 1_i64,
|
|
|
|
|
"13:string": "",
|
|
|
|
|
"23:varint": 0_i64,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !auto_generated
|
|
|
|
|
cursor = Base64.urlsafe_encode(cursor, false)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
data = IO::Memory.new
|
|
|
|
|
object["80226972:embedded"]["3:base64"].as(Hash)["15:string"] = cursor
|
|
|
|
|
|
|
|
|
|
if auto_generated
|
|
|
|
|
data.write Bytes[0x08, 0x0a]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
data.write Bytes[0x12, 0x09]
|
|
|
|
|
data.print "playlists"
|
|
|
|
|
|
|
|
|
|
if auto_generated
|
|
|
|
|
data.write Bytes[0x20, 0x32]
|
|
|
|
|
object["80226972:embedded"]["3:base64"].as(Hash)["4:varint"] = 0x32_i64
|
|
|
|
|
else
|
|
|
|
|
# TODO: Look at 0x01, 0x00
|
|
|
|
|
object["80226972:embedded"]["3:base64"].as(Hash)["4:varint"] = 1_i64
|
|
|
|
|
case sort
|
|
|
|
|
when "oldest", "oldest_created"
|
|
|
|
|
data.write Bytes[0x18, 0x02]
|
|
|
|
|
object["80226972:embedded"]["3:base64"].as(Hash)["3:varint"] = 2_i64
|
|
|
|
|
when "newest", "newest_created"
|
|
|
|
|
data.write Bytes[0x18, 0x03]
|
|
|
|
|
object["80226972:embedded"]["3:base64"].as(Hash)["3:varint"] = 3_i64
|
|
|
|
|
when "last", "last_added"
|
|
|
|
|
data.write Bytes[0x18, 0x04]
|
|
|
|
|
object["80226972:embedded"]["3:base64"].as(Hash)["3:varint"] = 4_i64
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
data.write Bytes[0x20, 0x01]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
data.write Bytes[0x30, 0x02]
|
|
|
|
|
data.write Bytes[0x38, 0x01]
|
|
|
|
|
data.write Bytes[0x60, 0x01]
|
|
|
|
|
data.write Bytes[0x6a, 0x00]
|
|
|
|
|
|
|
|
|
|
data.write_byte 0x7a
|
|
|
|
|
VarInt.to_io(data, cursor.bytesize)
|
|
|
|
|
data.print cursor
|
|
|
|
|
|
|
|
|
|
data.write Bytes[0xb8, 0x01, 0x00]
|
|
|
|
|
|
|
|
|
|
data.rewind
|
|
|
|
|
data = Base64.urlsafe_encode(data)
|
|
|
|
|
continuation = URI.encode_www_form(data)
|
|
|
|
|
|
|
|
|
|
data = IO::Memory.new
|
|
|
|
|
|
|
|
|
|
data.write_byte 0x12
|
|
|
|
|
VarInt.to_io(data, ucid.bytesize)
|
|
|
|
|
data.print ucid
|
|
|
|
|
|
|
|
|
|
data.write_byte 0x1a
|
|
|
|
|
VarInt.to_io(data, continuation.bytesize)
|
|
|
|
|
data.print continuation
|
|
|
|
|
|
|
|
|
|
data.rewind
|
|
|
|
|
|
|
|
|
|
buffer = IO::Memory.new
|
|
|
|
|
buffer.write Bytes[0xe2, 0xa9, 0x85, 0xb2, 0x02]
|
|
|
|
|
VarInt.to_io(buffer, data.bytesize)
|
|
|
|
|
object["80226972:embedded"]["3:string"] = Base64.urlsafe_encode(Protodec::Any.from_json(Protodec::Any.cast_json(object["80226972:embedded"]["3:base64"])))
|
|
|
|
|
object["80226972:embedded"].delete("3:base64")
|
|
|
|
|
|
|
|
|
|
IO.copy data, buffer
|
|
|
|
|
continuation = object.try { |i| Protodec::Any.cast_json(object) }
|
|
|
|
|
.try { |i| Protodec::Any.from_json(i) }
|
|
|
|
|
.try { |i| Base64.urlsafe_encode(i) }
|
|
|
|
|
.try { |i| URI.encode_www_form(i) }
|
|
|
|
|
|
|
|
|
|
continuation = Base64.urlsafe_encode(buffer)
|
|
|
|
|
continuation = URI.encode_www_form(continuation)
|
|
|
|
|
|
|
|
|
|
url = "/browse_ajax?continuation=#{continuation}&gl=US&hl=en"
|
|
|
|
|
|
|
|
|
|
return url
|
|
|
|
|
return "/browse_ajax?continuation=#{continuation}&gl=US&hl=en"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def extract_channel_playlists_cursor(url, auto_generated)
|
|
|
|
|
continuation = HTTP::Params.parse(URI.parse(url).query.not_nil!)["continuation"]
|
|
|
|
|
|
|
|
|
|
continuation = URI.decode_www_form(continuation)
|
|
|
|
|
data = IO::Memory.new(Base64.decode(continuation))
|
|
|
|
|
|
|
|
|
|
# 0xe2 0xa9 0x85 0xb2 0x02
|
|
|
|
|
data.pos += 5
|
|
|
|
|
|
|
|
|
|
continuation = Bytes.new(data.read_bytes(VarInt))
|
|
|
|
|
data.read continuation
|
|
|
|
|
data = IO::Memory.new(continuation)
|
|
|
|
|
|
|
|
|
|
data.read_byte # => 0x12
|
|
|
|
|
ucid = Bytes.new(data.read_bytes(VarInt))
|
|
|
|
|
data.read ucid
|
|
|
|
|
|
|
|
|
|
data.read_byte # => 0x1a
|
|
|
|
|
inner_continuation = Bytes.new(data.read_bytes(VarInt))
|
|
|
|
|
data.read inner_continuation
|
|
|
|
|
|
|
|
|
|
continuation = String.new(inner_continuation)
|
|
|
|
|
continuation = URI.decode_www_form(continuation)
|
|
|
|
|
data = IO::Memory.new(Base64.decode(continuation))
|
|
|
|
|
|
|
|
|
|
# 0x12 0x09 playlists
|
|
|
|
|
data.pos += 11
|
|
|
|
|
|
|
|
|
|
until data.peek[0] == 0x7a
|
|
|
|
|
key = data.read_bytes(VarInt)
|
|
|
|
|
value = data.read_bytes(VarInt)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
data.pos += 1 # => 0x7a
|
|
|
|
|
cursor = Bytes.new(data.read_bytes(VarInt))
|
|
|
|
|
data.read cursor
|
|
|
|
|
cursor = String.new(cursor)
|
|
|
|
|
cursor = URI.parse(url).query_params
|
|
|
|
|
.try { |i| Base64.decode(i["continuation"]) }
|
|
|
|
|
.try { |i| IO::Memory.new(i) }
|
|
|
|
|
.try { |i| Protodec::Any.parse(i) }
|
|
|
|
|
.try { |i| i["80226972:0:embedded"]["3:1:base64"]["15:7:string"].as_s }
|
|
|
|
|
|
|
|
|
|
if !auto_generated
|
|
|
|
|
cursor = URI.decode_www_form(cursor)
|
|
|
|
|
cursor = Base64.decode_string(cursor)
|
|
|
|
|
.try { |i| Base64.decode_string(i) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return cursor
|
|
|
|
@ -621,12 +541,9 @@ end
|
|
|
|
|
|
|
|
|
|
# TODO: Add "sort_by"
|
|
|
|
|
def fetch_channel_community(ucid, continuation, locale, config, kemal_config, format, thin_mode)
|
|
|
|
|
headers = HTTP::Headers.new
|
|
|
|
|
headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
|
|
|
|
|
|
|
|
|
|
response = YT_POOL.client &.get("/channel/#{ucid}/community?gl=US&hl=en", headers)
|
|
|
|
|
response = YT_POOL.client &.get("/channel/#{ucid}/community?gl=US&hl=en")
|
|
|
|
|
if response.status_code == 404
|
|
|
|
|
response = YT_POOL.client &.get("/user/#{ucid}/community?gl=US&hl=en", headers)
|
|
|
|
|
response = YT_POOL.client &.get("/user/#{ucid}/community?gl=US&hl=en")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if response.status_code == 404
|
|
|
|
@ -648,6 +565,7 @@ def fetch_channel_community(ucid, continuation, locale, config, kemal_config, fo
|
|
|
|
|
else
|
|
|
|
|
continuation = produce_channel_community_continuation(ucid, continuation)
|
|
|
|
|
|
|
|
|
|
headers = HTTP::Headers.new
|
|
|
|
|
headers["cookie"] = response.cookies.add_request_headers(headers)["cookie"]
|
|
|
|
|
headers["content-type"] = "application/x-www-form-urlencoded"
|
|
|
|
|
|
|
|
|
@ -874,53 +792,31 @@ def fetch_channel_community(ucid, continuation, locale, config, kemal_config, fo
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def produce_channel_community_continuation(ucid, cursor)
|
|
|
|
|
cursor = URI.encode_www_form(cursor)
|
|
|
|
|
|
|
|
|
|
data = IO::Memory.new
|
|
|
|
|
|
|
|
|
|
data.write_byte 0x12
|
|
|
|
|
VarInt.to_io(data, ucid.bytesize)
|
|
|
|
|
data.print ucid
|
|
|
|
|
|
|
|
|
|
data.write_byte 0x1a
|
|
|
|
|
VarInt.to_io(data, cursor.bytesize)
|
|
|
|
|
data.print cursor
|
|
|
|
|
|
|
|
|
|
data.rewind
|
|
|
|
|
|
|
|
|
|
buffer = IO::Memory.new
|
|
|
|
|
buffer.write Bytes[0xe2, 0xa9, 0x85, 0xb2, 0x02]
|
|
|
|
|
VarInt.to_io(buffer, data.size)
|
|
|
|
|
|
|
|
|
|
IO.copy data, buffer
|
|
|
|
|
|
|
|
|
|
continuation = Base64.urlsafe_encode(buffer)
|
|
|
|
|
continuation = URI.encode_www_form(continuation)
|
|
|
|
|
object = {
|
|
|
|
|
"80226972:embedded" => {
|
|
|
|
|
"2:string" => ucid,
|
|
|
|
|
"3:string" => cursor,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
continuation = object.try { |i| Protodec::Any.cast_json(object) }
|
|
|
|
|
.try { |i| Protodec::Any.from_json(i) }
|
|
|
|
|
.try { |i| Base64.urlsafe_encode(i) }
|
|
|
|
|
.try { |i| URI.encode_www_form(i) }
|
|
|
|
|
|
|
|
|
|
return continuation
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def extract_channel_community_cursor(continuation)
|
|
|
|
|
continuation = URI.decode_www_form(continuation)
|
|
|
|
|
data = IO::Memory.new(Base64.decode(continuation))
|
|
|
|
|
|
|
|
|
|
# 0xe2 0xa9 0x85 0xb2 0x02
|
|
|
|
|
data.pos += 5
|
|
|
|
|
|
|
|
|
|
continuation = Bytes.new(data.read_bytes(VarInt))
|
|
|
|
|
data.read continuation
|
|
|
|
|
data = IO::Memory.new(continuation)
|
|
|
|
|
|
|
|
|
|
data.read_byte # => 0x12
|
|
|
|
|
ucid = Bytes.new(data.read_bytes(VarInt))
|
|
|
|
|
data.read ucid
|
|
|
|
|
|
|
|
|
|
data.read_byte # => 0x1a
|
|
|
|
|
until data.peek[0] == 'E'.ord
|
|
|
|
|
data.read_byte
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return URI.decode_www_form(data.gets_to_end)
|
|
|
|
|
cursor = 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| Protodec::Any.from_json(i) }
|
|
|
|
|
.try { |i| Base64.urlsafe_encode(i) }
|
|
|
|
|
|
|
|
|
|
cursor
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def get_about_info(ucid, locale)
|
|
|
|
|