Search filters protobuf (#516)
* [Wip] search filters protobuf * Filters work * Small tweaks * changelog
This commit is contained in:
1 parent
c6853cd2fc
commit
564afd9685
19 files changed
+895
-10
No files matched your search
@@ -5,6 +5,7 @@ import "pkg:/components/Services/Innertube/NextEndpoint.bs"
|
||||
import "pkg:/components/Services/Innertube/OAuth.bs"
|
||||
import "pkg:/components/Services/Innertube/PlayerEndpoint.bs"
|
||||
import "pkg:/components/Services/Innertube/Search.bs"
|
||||
import "pkg:/components/Services/Innertube/SearchFilters.bs"
|
||||
import "pkg:/source/services/HttpClient.bs"
|
||||
import "pkg:/source/utils/CancellationUtils.bs"
|
||||
import "pkg:/source/utils/ObjectUtils.bs"
|
||||
@@ -83,8 +84,8 @@ namespace InnertubeService
|
||||
}
|
||||
end function
|
||||
|
||||
function Search(query as string, cancellation = invalid as object) as object
|
||||
return Innertube.Search(query, cancellation)
|
||||
function Search(query as string, searchFilters as object, cancellation = invalid as object) as object
|
||||
return Innertube.Search(query, searchFilters, cancellation)
|
||||
end function
|
||||
|
||||
function GetTrending(options = invalid as object) as object
|
||||
|
||||
@@ -3,7 +3,7 @@ import "pkg:/components/Services/Innertube/Parser.bs"
|
||||
|
||||
namespace Innertube
|
||||
|
||||
function Search(query as string, cancellation = invalid as object) as object
|
||||
function Search(query as string, searchFilters as object, cancellation = invalid as object) as object
|
||||
deviceInfo = CreateObject("roDeviceInfo")
|
||||
|
||||
payload = {
|
||||
@@ -11,6 +11,13 @@ namespace Innertube
|
||||
context: Innertube.CreateContext(Innertube.ClientType.WEB, deviceInfo, "")
|
||||
}
|
||||
|
||||
if searchFilters <> invalid and searchFilters.Count() > 0
|
||||
params = Innertube.GetEncodedSearchFilters(searchFilters)
|
||||
if params <> ""
|
||||
payload["params"] = Innertube.GetEncodedSearchFilters(searchFilters)
|
||||
end if
|
||||
end if
|
||||
|
||||
request = HttpClient.PostJson("https://www.youtube.com/youtubei/v1/search?prettyPrint=false&alt=json", payload)
|
||||
request.Headers({
|
||||
"accept": "*/*"
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import "pkg:/components/Services/Innertube/protos/params.proto.gen.bs"
|
||||
|
||||
namespace Innertube
|
||||
function GetEncodedSearchFilters(searchFilters as object) as string
|
||||
searchFiltersObj = {
|
||||
filters: {}
|
||||
}
|
||||
|
||||
if searchFilters.DoesExist("sort")
|
||||
sort = searchFilters["sort"]
|
||||
if sort = "relevance"
|
||||
searchFiltersObj["sort_by"] = Protobuf.Generated.misc.SortBy.RELEVANCE
|
||||
else if sort = "rating"
|
||||
searchFiltersObj["sort_by"] = Protobuf.Generated.misc.SortBy.RATING
|
||||
else if sort = "views"
|
||||
searchFiltersObj["sort_by"] = Protobuf.Generated.misc.SortBy.VIEW_COUNT
|
||||
else if sort = "date"
|
||||
searchFiltersObj["sort_by"] = Protobuf.Generated.misc.SortBy.UPLOAD_DATE
|
||||
end if
|
||||
end if
|
||||
|
||||
if searchFilters.DoesExist("date")
|
||||
date = searchFilters["date"]
|
||||
if date = "hour"
|
||||
searchFiltersObj["filters"]["upload_date"] = Protobuf.Generated.misc.UploadDate.HOUR
|
||||
else if date = "today"
|
||||
searchFiltersObj["filters"]["upload_date"] = Protobuf.Generated.misc.UploadDate.TODAY
|
||||
else if date = "week"
|
||||
searchFiltersObj["filters"]["upload_date"] = Protobuf.Generated.misc.UploadDate.WEEK
|
||||
else if date = "month"
|
||||
searchFiltersObj["filters"]["upload_date"] = Protobuf.Generated.misc.UploadDate.MONTH
|
||||
else if date = "year"
|
||||
searchFiltersObj["filters"]["upload_date"] = Protobuf.Generated.misc.UploadDate.YEAR
|
||||
end if
|
||||
end if
|
||||
|
||||
if searchFilters.DoesExist("type")
|
||||
_type = searchFilters["type"]
|
||||
if _type = "video"
|
||||
searchFiltersObj["filters"]["type"] = Protobuf.Generated.misc.SearchType.VIDEO
|
||||
else if _type = "channel"
|
||||
searchFiltersObj["filters"]["type"] = Protobuf.Generated.misc.SearchType.CHANNEL
|
||||
else if _type = "playlist"
|
||||
searchFiltersObj["filters"]["type"] = Protobuf.Generated.misc.SearchType.PLAYLIST
|
||||
else if _type = "movie"
|
||||
searchFiltersObj["filters"]["type"] = Protobuf.Generated.misc.SearchType.MOVIE
|
||||
end if
|
||||
end if
|
||||
|
||||
if searchFilters.DoesExist("duration")
|
||||
duration = searchFilters["duration"]
|
||||
if duration = "short"
|
||||
searchFiltersObj["filters"]["duration"] = Protobuf.Generated.misc.Duration.SHORT
|
||||
else if duration = "long"
|
||||
searchFiltersObj["filters"]["duration"] = Protobuf.Generated.misc.Duration.LONG
|
||||
else if duration = "medium"
|
||||
searchFiltersObj["filters"]["duration"] = Protobuf.Generated.misc.Duration.MEDIUM
|
||||
end if
|
||||
end if
|
||||
|
||||
if searchFilters.DoesExist("features")
|
||||
features = searchFilters["features"]
|
||||
for each feature in features
|
||||
if feature = "hd"
|
||||
searchFiltersObj["filters"]["features_hd"] = true
|
||||
else if feature = "subtitles"
|
||||
searchFiltersObj["filters"]["features_subtitles"] = true
|
||||
else if feature = "creative_commons"
|
||||
searchFiltersObj["filters"]["features_creative_commons"] = true
|
||||
else if feature = "3d"
|
||||
searchFiltersObj["filters"]["features_3d"] = true
|
||||
else if feature = "live"
|
||||
searchFiltersObj["filters"]["features_live"] = true
|
||||
else if feature = "purchased"
|
||||
searchFiltersObj["filters"]["features_purchased"] = true
|
||||
else if feature = "4k"
|
||||
searchFiltersObj["filters"]["features_4k"] = true
|
||||
else if feature = "360"
|
||||
searchFiltersObj["filters"]["features_360"] = true
|
||||
else if feature = "location"
|
||||
searchFiltersObj["filters"]["features_location"] = true
|
||||
else if feature = "hdr"
|
||||
searchFiltersObj["filters"]["features_hdr"] = true
|
||||
else if feature = "vr180"
|
||||
searchFiltersObj["filters"]["features_vr180"] = true
|
||||
end if
|
||||
end for
|
||||
end if
|
||||
|
||||
return Protobuf.Generated.misc.encodeSearchFilter(searchFiltersObj)
|
||||
end function
|
||||
end namespace
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
syntax = "proto3";
|
||||
package misc;
|
||||
|
||||
// https://github.com/LuanRT/YouTube.js/blob/5f83a7416d5dc3167e6af2767e9b90f4bf89f3dc/protos/misc/params.proto#L9-L71
|
||||
message SearchFilter {
|
||||
optional SortBy sort_by = 1;
|
||||
|
||||
enum SortBy {
|
||||
RELEVANCE = 0;
|
||||
RATING = 1;
|
||||
UPLOAD_DATE = 2;
|
||||
VIEW_COUNT = 3;
|
||||
}
|
||||
|
||||
message Filters {
|
||||
optional UploadDate upload_date = 1;
|
||||
optional SearchType type = 2;
|
||||
optional Duration duration = 3;
|
||||
|
||||
optional bool features_hd = 4;
|
||||
optional bool features_subtitles = 5;
|
||||
optional bool features_creative_commons = 6;
|
||||
optional bool features_3d = 7;
|
||||
optional bool features_live = 8;
|
||||
optional bool features_purchased = 9;
|
||||
optional bool features_4k = 14;
|
||||
optional bool features_360 = 15;
|
||||
optional bool features_location = 23;
|
||||
optional bool features_hdr = 25;
|
||||
optional bool features_vr180 = 26;
|
||||
|
||||
enum UploadDate {
|
||||
ANY_DATE = 0;
|
||||
HOUR = 1;
|
||||
TODAY = 2;
|
||||
WEEK = 3;
|
||||
MONTH = 4;
|
||||
YEAR = 5;
|
||||
}
|
||||
|
||||
enum SearchType {
|
||||
ANY_TYPE = 0;
|
||||
VIDEO = 1;
|
||||
CHANNEL = 2;
|
||||
PLAYLIST = 3;
|
||||
MOVIE = 4;
|
||||
}
|
||||
|
||||
enum Duration {
|
||||
ANY_DURATION = 0;
|
||||
SHORT = 1;
|
||||
LONG = 2;
|
||||
MEDIUM = 3;
|
||||
}
|
||||
}
|
||||
|
||||
optional Filters filters = 2;
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
' Auto-generated file - do not modify manually
|
||||
' md5:dfefe3075a9c6332b6072e7c02fdccf8
|
||||
|
||||
import "pkg:/source/Protobuf/BinaryReader.bs"
|
||||
import "pkg:/source/Protobuf/BinaryWriter.bs"
|
||||
import "pkg:/source/Protobuf/Decoder.bs"
|
||||
import "pkg:/source/Protobuf/Encoder.bs"
|
||||
|
||||
namespace Protobuf
|
||||
namespace Generated
|
||||
namespace misc
|
||||
|
||||
enum SortBy
|
||||
RELEVANCE = 0
|
||||
RATING = 1
|
||||
UPLOAD_DATE = 2
|
||||
VIEW_COUNT = 3
|
||||
end enum
|
||||
|
||||
enum UploadDate
|
||||
ANY_DATE = 0
|
||||
HOUR = 1
|
||||
TODAY = 2
|
||||
WEEK = 3
|
||||
MONTH = 4
|
||||
YEAR = 5
|
||||
end enum
|
||||
|
||||
enum SearchType
|
||||
ANY_TYPE = 0
|
||||
VIDEO = 1
|
||||
CHANNEL = 2
|
||||
PLAYLIST = 3
|
||||
MOVIE = 4
|
||||
end enum
|
||||
|
||||
enum Duration
|
||||
ANY_DURATION = 0
|
||||
SHORT = 1
|
||||
LONG = 2
|
||||
MEDIUM = 3
|
||||
end enum
|
||||
|
||||
|
||||
|
||||
function encodeFilters(message as dynamic) as string
|
||||
buffer = CreateObject("roByteArray")
|
||||
writer = new Protobuf.BinaryWriter()
|
||||
writer.SetBuffer(buffer)
|
||||
encoder = new Protobuf.Encoder(writer)
|
||||
if message.DoesExist("upload_date")
|
||||
value = message["upload_date"]
|
||||
encoder.EncodeInt32(1, value)
|
||||
end if
|
||||
if message.DoesExist("type")
|
||||
value = message["type"]
|
||||
encoder.EncodeInt32(2, value)
|
||||
end if
|
||||
if message.DoesExist("duration")
|
||||
value = message["duration"]
|
||||
encoder.EncodeInt32(3, value)
|
||||
end if
|
||||
if message.DoesExist("features_hd")
|
||||
value = message["features_hd"]
|
||||
encoder.EncodeBool(4, value)
|
||||
end if
|
||||
if message.DoesExist("features_subtitles")
|
||||
value = message["features_subtitles"]
|
||||
encoder.EncodeBool(5, value)
|
||||
end if
|
||||
if message.DoesExist("features_creative_commons")
|
||||
value = message["features_creative_commons"]
|
||||
encoder.EncodeBool(6, value)
|
||||
end if
|
||||
if message.DoesExist("features_3d")
|
||||
value = message["features_3d"]
|
||||
encoder.EncodeBool(7, value)
|
||||
end if
|
||||
if message.DoesExist("features_live")
|
||||
value = message["features_live"]
|
||||
encoder.EncodeBool(8, value)
|
||||
end if
|
||||
if message.DoesExist("features_purchased")
|
||||
value = message["features_purchased"]
|
||||
encoder.EncodeBool(9, value)
|
||||
end if
|
||||
if message.DoesExist("features_4k")
|
||||
value = message["features_4k"]
|
||||
encoder.EncodeBool(14, value)
|
||||
end if
|
||||
if message.DoesExist("features_360")
|
||||
value = message["features_360"]
|
||||
encoder.EncodeBool(15, value)
|
||||
end if
|
||||
if message.DoesExist("features_location")
|
||||
value = message["features_location"]
|
||||
encoder.EncodeBool(23, value)
|
||||
end if
|
||||
if message.DoesExist("features_hdr")
|
||||
value = message["features_hdr"]
|
||||
encoder.EncodeBool(25, value)
|
||||
end if
|
||||
if message.DoesExist("features_vr180")
|
||||
value = message["features_vr180"]
|
||||
encoder.EncodeBool(26, value)
|
||||
end if
|
||||
return buffer.ToBase64String().EncodeUriComponent()
|
||||
end function
|
||||
|
||||
function encodeSearchFilter(message as dynamic) as string
|
||||
buffer = CreateObject("roByteArray")
|
||||
writer = new Protobuf.BinaryWriter()
|
||||
writer.SetBuffer(buffer)
|
||||
encoder = new Protobuf.Encoder(writer)
|
||||
if message.DoesExist("sort_by")
|
||||
value = message["sort_by"]
|
||||
encoder.EncodeInt32(1, value)
|
||||
end if
|
||||
if message.DoesExist("filters")
|
||||
value = message["filters"]
|
||||
encoder.EncodeMessage(2, Protobuf.Generated.misc.encodeFilters(value))
|
||||
end if
|
||||
return buffer.ToBase64String().EncodeUriComponent()
|
||||
end function
|
||||
|
||||
|
||||
|
||||
end namespace
|
||||
end namespace
|
||||
end namespace
|
||||
@@ -0,0 +1,6 @@
|
||||
<component name="SearchFiltersTestNode" extends="Node">
|
||||
<interface>
|
||||
<function name="Innertube_GetEncodedSearchFilters" />
|
||||
</interface>
|
||||
<script type="text/brightscript" uri="pkg:/components/Services/Innertube/SearchFilters.bs" />
|
||||
</component>
|
||||
+23
-1
@@ -66,7 +66,29 @@ namespace Http
|
||||
|
||||
query = request.query.q
|
||||
|
||||
feeds = InnertubeService.Search(query)
|
||||
searchFilters = {}
|
||||
sort = request.query.sort
|
||||
if not StringUtils.IsNullOrEmpty(sort)
|
||||
searchFilters.sort = sort
|
||||
end if
|
||||
date = request.query.date
|
||||
if not StringUtils.IsNullOrEmpty(date)
|
||||
searchFilters.date = date
|
||||
end if
|
||||
_type = request.query.type
|
||||
if not StringUtils.IsNullOrEmpty(_type)
|
||||
searchFilters.type = _type
|
||||
end if
|
||||
duration = request.query.duration
|
||||
if not StringUtils.IsNullOrEmpty(duration)
|
||||
searchFilters.duration = duration
|
||||
end if
|
||||
features = request.query.features
|
||||
if not StringUtils.IsNullOrEmpty(features)
|
||||
searchFilters.features = features.Split(",")
|
||||
end if
|
||||
|
||||
feeds = InnertubeService.Search(query, searchFilters)
|
||||
if not IsArray(feeds) or feeds.Count() = 0
|
||||
response.Default(500, "Failed to search")
|
||||
return true
|
||||
|
||||
@@ -47,10 +47,6 @@ search:
|
||||
- channel
|
||||
- all
|
||||
arrayType: CommaSeparated
|
||||
default:
|
||||
- video
|
||||
- playlist
|
||||
- channel
|
||||
features:
|
||||
type:
|
||||
- hd
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
namespace Protobuf
|
||||
|
||||
class BinaryReader
|
||||
private buffer
|
||||
private position
|
||||
|
||||
function SetBuffer(buffer as dynamic) as void
|
||||
if buffer = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
if GetInterface(buffer, "ifString") <> invalid
|
||||
b = CreateObject("roByteArray")
|
||||
b.FromBase64String(buffer.DecodeUriComponent())
|
||||
buffer = b
|
||||
end if
|
||||
|
||||
m.buffer = buffer
|
||||
m.position = 0
|
||||
end function
|
||||
|
||||
function ReadVarInt() as dynamic
|
||||
value = 0
|
||||
_shift = 0
|
||||
while true
|
||||
byte = m.ReadByte()
|
||||
if byte = invalid
|
||||
return invalid
|
||||
end if
|
||||
|
||||
if _shift < 32
|
||||
value = value or ((byte and &h7F) << _shift)
|
||||
else
|
||||
value = value + ((byte and &h7F) * (2 ^ _shift))
|
||||
end if
|
||||
_shift += 7
|
||||
|
||||
if (byte and &h80) = 0
|
||||
return value
|
||||
end if
|
||||
end while
|
||||
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function ReadByte() as dynamic
|
||||
if m.position >= m.buffer.Count()
|
||||
return invalid
|
||||
end if
|
||||
byte = m.buffer[m.position]
|
||||
m.position += 1
|
||||
return byte
|
||||
end function
|
||||
|
||||
function ReadInt32() as dynamic
|
||||
if m.position + 4 > m.buffer.Count()
|
||||
return invalid
|
||||
end if
|
||||
value = m.buffer[m.position] or (m.buffer[m.position + 1] << 8) or (m.buffer[m.position + 2] << 16) or (m.buffer[m.position + 3] << 24)
|
||||
m.position += 4
|
||||
return value
|
||||
end function
|
||||
|
||||
function ReadInt64() as dynamic
|
||||
if m.position + 8 > m.buffer.Count()
|
||||
return invalid
|
||||
end if
|
||||
value = m.buffer[m.position] or (m.buffer[m.position + 1] << 8) or (m.buffer[m.position + 2] << 16) or (m.buffer[m.position + 3] << 24) or (m.buffer[m.position + 4] << 32) or (m.buffer[m.position + 5] << 40) or (m.buffer[m.position + 6] << 48) or (m.buffer[m.position + 7] << 56)
|
||||
m.position += 8
|
||||
return value
|
||||
end function
|
||||
|
||||
function ReadBytes() as dynamic
|
||||
length = m.ReadVarInt()
|
||||
if length = invalid
|
||||
return invalid
|
||||
end if
|
||||
endPosition = m.position + length
|
||||
if endPosition > m.buffer.Count()
|
||||
return invalid
|
||||
end if
|
||||
value = m.buffer.Slice(m.position, endPosition)
|
||||
m.position += length
|
||||
return value
|
||||
end function
|
||||
|
||||
function ReadString() as dynamic
|
||||
bytes = m.ReadBytes()
|
||||
if bytes = invalid
|
||||
return invalid
|
||||
end if
|
||||
return bytes.ToAsciiString()
|
||||
end function
|
||||
end class
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,66 @@
|
||||
namespace Protobuf
|
||||
|
||||
class BinaryWriter
|
||||
private buffer
|
||||
private position
|
||||
|
||||
function SetBuffer(buffer as dynamic) as void
|
||||
if buffer = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
if GetInterface(buffer, "ifString") <> invalid
|
||||
b = CreateObject("roByteArray")
|
||||
b.FromBase64String(buffer.DecodeUriComponent())
|
||||
buffer = b
|
||||
end if
|
||||
|
||||
m.buffer = buffer
|
||||
m.position = 0
|
||||
end function
|
||||
|
||||
function WriteByte(byte as dynamic) as void
|
||||
m.buffer[m.position] = byte
|
||||
m.position += 1
|
||||
end function
|
||||
|
||||
function WriteInt32(value as dynamic) as void
|
||||
m.buffer[m.position] = value and &hFF
|
||||
m.buffer[m.position + 1] = (value >> 8) and &hFF
|
||||
m.buffer[m.position + 2] = (value >> 16) and &hFF
|
||||
m.buffer[m.position + 3] = (value >> 24) and &hFF
|
||||
m.position += 4
|
||||
end function
|
||||
|
||||
function WriteVarInt(value as dynamic) as void
|
||||
while true
|
||||
byte = value and &h7F
|
||||
value >>= 7
|
||||
if value = 0
|
||||
m.WriteByte(byte)
|
||||
return
|
||||
end if
|
||||
m.WriteByte(byte or &h80)
|
||||
end while
|
||||
end function
|
||||
|
||||
function WriteString(value as dynamic) as void
|
||||
strBuffer = CreateObject("roByteArray")
|
||||
strBuffer.FromAsciiString(value)
|
||||
m.WriteVarInt(strBuffer.Count())
|
||||
for i = 0 to strBuffer.Count() - 1
|
||||
m.buffer[m.position + i] = strBuffer[i]
|
||||
end for
|
||||
m.position += strBuffer.Count()
|
||||
end function
|
||||
|
||||
function WriteBool(value as dynamic) as void
|
||||
if value = true
|
||||
m.WriteByte(1)
|
||||
else
|
||||
m.WriteByte(0)
|
||||
end if
|
||||
end function
|
||||
end class
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,54 @@
|
||||
namespace Protobuf
|
||||
|
||||
class Decoder
|
||||
private reader
|
||||
|
||||
function new(reader as object)
|
||||
m.reader = reader
|
||||
end function
|
||||
|
||||
' TODO:P2 decoder is not finished, does not work properly
|
||||
function DecodeMessage(buffer as object) as dynamic
|
||||
m.reader.SetBuffer(buffer)
|
||||
|
||||
message = {}
|
||||
while true
|
||||
field = m.reader.ReadByte()
|
||||
if field = invalid
|
||||
exit while
|
||||
end if
|
||||
|
||||
tag = field >> 3
|
||||
wire_type = field and &h7
|
||||
|
||||
value = invalid
|
||||
if wire_type = 0
|
||||
value = m.reader.ReadVarInt()
|
||||
else if wire_type = 1
|
||||
value = m.reader.ReadInt64()
|
||||
else if wire_type = 2
|
||||
value = m.reader.ReadString()
|
||||
else if wire_type = 5
|
||||
value = m.reader.ReadInt32()
|
||||
end if
|
||||
|
||||
if value = invalid
|
||||
return invalid
|
||||
end if
|
||||
|
||||
tagStr = `${tag}`
|
||||
if message[tagStr] = invalid
|
||||
message[tagStr] = value
|
||||
else if GetInterface(message[tagStr], "ifArray") <> invalid
|
||||
message[tagStr].Push(value)
|
||||
else
|
||||
message[tagStr] = [message[tagStr], value]
|
||||
end if
|
||||
end while
|
||||
|
||||
return message
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,52 @@
|
||||
namespace Protobuf
|
||||
|
||||
class Encoder
|
||||
private writer
|
||||
|
||||
function new(writer as object) as void
|
||||
m.writer = writer
|
||||
end function
|
||||
|
||||
function EncodeString(tag as integer, value as dynamic) as void
|
||||
m.writer.WriteByte((tag << 3) or 2)
|
||||
m.writer.WriteString(value)
|
||||
end function
|
||||
|
||||
function EncodeInt32(tag as integer, value as dynamic) as void
|
||||
m.writer.WriteByte((tag << 3) or 0)
|
||||
m.writer.WriteVarInt(value)
|
||||
end function
|
||||
|
||||
function EncodeInt64(tag as integer, value as dynamic) as void
|
||||
m.writer.WriteByte((tag << 3) or 0)
|
||||
m.writer.WriteInt64(value)
|
||||
end function
|
||||
|
||||
function EncodeFloat(tag as integer, value as dynamic) as void
|
||||
m.writer.WriteByte((tag << 3) or 5)
|
||||
m.writer.WriteFloat(value)
|
||||
end function
|
||||
|
||||
function EncodeDouble(tag as integer, value as dynamic) as void
|
||||
m.writer.WriteByte((tag << 3) or 1)
|
||||
m.writer.WriteDouble(value)
|
||||
end function
|
||||
|
||||
function EncodeBool(tag as integer, value as dynamic) as void
|
||||
m.writer.WriteByte((tag << 3) or 0)
|
||||
m.writer.WriteBool(value)
|
||||
end function
|
||||
|
||||
function EncodeMessage(tag as integer, value as dynamic) as void
|
||||
m.writer.WriteByte((tag << 3) or 2)
|
||||
buffer = CreateObject("roByteArray")
|
||||
buffer.FromBase64String(value.DecodeUriComponent())
|
||||
m.writer.WriteVarInt(buffer.Count())
|
||||
for i = 0 to buffer.Count() - 1
|
||||
m.writer.WriteByte(buffer[i])
|
||||
end for
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,40 @@
|
||||
namespace Tests
|
||||
|
||||
@SGNode("SearchFiltersTestNode")
|
||||
@suite
|
||||
class SearchFiltersTests extends Rooibos.BaseTestSuite
|
||||
|
||||
@describe("SearchFilters")
|
||||
|
||||
@it("Encodes search filters")
|
||||
function _()
|
||||
testCases = m.GetEncodingTestCases()
|
||||
for each testCase in testCases
|
||||
encoded = m.top@.Innertube_GetEncodedSearchFilters(testCase.input)
|
||||
m.assertEqual(encoded, testCase.encoded)
|
||||
end for
|
||||
end function
|
||||
|
||||
function GetEncodingTestCases() as object
|
||||
return [{
|
||||
input: {
|
||||
"sort": "date"
|
||||
}
|
||||
encoded: "CAISAA%3D%3D"
|
||||
}, {
|
||||
input: {
|
||||
"sort": "views"
|
||||
"features": ["3d", "hd", "live"]
|
||||
}
|
||||
encoded: "CAMSBiABOAFAAQ%3D%3D"
|
||||
}, {
|
||||
input: {
|
||||
"type": "playlist"
|
||||
}
|
||||
encoded: "EgIQAw%3D%3D"
|
||||
}]
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
Reference in new issue
Block a user