|
|
@ -277,96 +277,97 @@ end
|
|
|
|
|
|
|
|
|
|
|
|
def produce_search_params(sort : String = "relevance", date : String = "", content_type : String = "",
|
|
|
|
def produce_search_params(sort : String = "relevance", date : String = "", content_type : String = "",
|
|
|
|
duration : String = "", features : Array(String) = [] of String)
|
|
|
|
duration : String = "", features : Array(String) = [] of String)
|
|
|
|
head = "\x08"
|
|
|
|
header = IO::Memory.new
|
|
|
|
head += case sort
|
|
|
|
header.write Bytes[0x08]
|
|
|
|
|
|
|
|
header.write case sort
|
|
|
|
when "relevance"
|
|
|
|
when "relevance"
|
|
|
|
"\x00"
|
|
|
|
Bytes[0x00]
|
|
|
|
when "rating"
|
|
|
|
when "rating"
|
|
|
|
"\x01"
|
|
|
|
Bytes[0x01]
|
|
|
|
when "upload_date", "date"
|
|
|
|
when "upload_date", "date"
|
|
|
|
"\x02"
|
|
|
|
Bytes[0x02]
|
|
|
|
when "view_count", "views"
|
|
|
|
when "view_count", "views"
|
|
|
|
"\x03"
|
|
|
|
Bytes[0x03]
|
|
|
|
else
|
|
|
|
else
|
|
|
|
raise "No sort #{sort}"
|
|
|
|
raise "No sort #{sort}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
body = ""
|
|
|
|
body = IO::Memory.new
|
|
|
|
body += case date
|
|
|
|
body.write case date
|
|
|
|
when "hour"
|
|
|
|
when "hour"
|
|
|
|
"\x08\x01"
|
|
|
|
Bytes[0x08, 0x01]
|
|
|
|
when "today"
|
|
|
|
when "today"
|
|
|
|
"\x08\x02"
|
|
|
|
Bytes[0x08, 0x02]
|
|
|
|
when "week"
|
|
|
|
when "week"
|
|
|
|
"\x08\x03"
|
|
|
|
Bytes[0x08, 0x03]
|
|
|
|
when "month"
|
|
|
|
when "month"
|
|
|
|
"\x08\x04"
|
|
|
|
Bytes[0x08, 0x04]
|
|
|
|
when "year"
|
|
|
|
when "year"
|
|
|
|
"\x08\x05"
|
|
|
|
Bytes[0x08, 0x05]
|
|
|
|
else
|
|
|
|
else
|
|
|
|
""
|
|
|
|
Bytes.new(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
body += case content_type
|
|
|
|
body.write case content_type
|
|
|
|
when "video"
|
|
|
|
when "video"
|
|
|
|
"\x10\x01"
|
|
|
|
Bytes[0x10, 0x01]
|
|
|
|
when "channel"
|
|
|
|
when "channel"
|
|
|
|
"\x10\x02"
|
|
|
|
Bytes[0x10, 0x02]
|
|
|
|
when "playlist"
|
|
|
|
when "playlist"
|
|
|
|
"\x10\x03"
|
|
|
|
Bytes[0x10, 0x03]
|
|
|
|
when "movie"
|
|
|
|
when "movie"
|
|
|
|
"\x10\x04"
|
|
|
|
Bytes[0x10, 0x04]
|
|
|
|
when "show"
|
|
|
|
when "show"
|
|
|
|
"\x10\x05"
|
|
|
|
Bytes[0x10, 0x05]
|
|
|
|
when "all"
|
|
|
|
when "all"
|
|
|
|
""
|
|
|
|
Bytes.new(0)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
"\x10\x01"
|
|
|
|
Bytes[0x10, 0x01]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
body += case duration
|
|
|
|
body.write case duration
|
|
|
|
when "short"
|
|
|
|
when "short"
|
|
|
|
"\x18\x01"
|
|
|
|
Bytes[0x18, 0x01]
|
|
|
|
when "long"
|
|
|
|
when "long"
|
|
|
|
"\x18\x02"
|
|
|
|
Bytes[0x18, 0x12]
|
|
|
|
else
|
|
|
|
else
|
|
|
|
""
|
|
|
|
Bytes.new(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
features.each do |feature|
|
|
|
|
features.each do |feature|
|
|
|
|
body += case feature
|
|
|
|
body.write case feature
|
|
|
|
when "hd"
|
|
|
|
when "hd"
|
|
|
|
"\x20\x01"
|
|
|
|
Bytes[0x20, 0x01]
|
|
|
|
when "subtitles"
|
|
|
|
when "subtitles"
|
|
|
|
"\x28\x01"
|
|
|
|
Bytes[0x28, 0x01]
|
|
|
|
when "creative_commons", "cc"
|
|
|
|
when "creative_commons", "cc"
|
|
|
|
"\x30\x01"
|
|
|
|
Bytes[0x30, 0x01]
|
|
|
|
when "3d"
|
|
|
|
when "3d"
|
|
|
|
"\x38\x01"
|
|
|
|
Bytes[0x38, 0x01]
|
|
|
|
when "live", "livestream"
|
|
|
|
when "live", "livestream"
|
|
|
|
"\x40\x01"
|
|
|
|
Bytes[0x40, 0x01]
|
|
|
|
when "purchased"
|
|
|
|
when "purchased"
|
|
|
|
"\x48\x01"
|
|
|
|
Bytes[0x48, 0x01]
|
|
|
|
when "4k"
|
|
|
|
when "4k"
|
|
|
|
"\x70\x01"
|
|
|
|
Bytes[0x70, 0x01]
|
|
|
|
when "360"
|
|
|
|
when "360"
|
|
|
|
"\x78\x01"
|
|
|
|
Bytes[0x78, 0x01]
|
|
|
|
when "location"
|
|
|
|
when "location"
|
|
|
|
"\xb8\x01\x01"
|
|
|
|
Bytes[0xb8, 0x01, 0x01]
|
|
|
|
when "hdr"
|
|
|
|
when "hdr"
|
|
|
|
"\xc8\x01\x01"
|
|
|
|
Bytes[0xc8, 0x01, 0x01]
|
|
|
|
else
|
|
|
|
else
|
|
|
|
raise "Unknown feature #{feature}"
|
|
|
|
Bytes.new(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
token = header
|
|
|
|
if !body.empty?
|
|
|
|
if !body.empty?
|
|
|
|
token = head + "\x12" + body.size.unsafe_chr + body
|
|
|
|
token.write Bytes[0x12, body.bytesize]
|
|
|
|
else
|
|
|
|
token.write body.to_slice
|
|
|
|
token = head
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
token = Base64.urlsafe_encode(token)
|
|
|
|
token = Base64.urlsafe_encode(token.to_slice)
|
|
|
|
token = URI.escape(token)
|
|
|
|
token = URI.escape(token)
|
|
|
|
|
|
|
|
|
|
|
|
return token
|
|
|
|
return token
|
|
|
|