]>
git.gir.st - subscriptionfeed.git/blob - app/browse/protobuf.py
4 def proto(d
, padding
=False):
5 return base64
.urlsafe_b64encode(pyproto
.ProtoBuf(d
).toBuf()) \
6 .decode('ascii').replace("=", "%3D" if padding
else "")
8 def continuation(subject
, params
, query
=None):
12 3: proto(params
, padding
=True),
17 def make_sp(sort
=None, date
=None, type=None, len=None, features
=[], extras
=[]):
18 sortorder
= dict(relevance
=0, rating
=1, date
=2, views
=3)
19 datefilter
= dict(hour
=1, day
=2, week
=3, month
=4, year
=5)
20 typefilter
= dict(video
=1, channel
=2, playlist
=3, movie
=4, show
=5)
21 lenfilter
= dict(short
=1, long=2, medium
=3) # short=0-4min, long=20+min, medium=4-20min
22 extraflags
= dict(verbatim
=1)
23 featureflags
= dict(is_hd
=4, subtitles
=5, ccommons
=6, is_3d
=7, live
=8,
24 purchased
=9, is_4k
=14, is_360
=15, location
=23, is_hdr
=25)
27 1: sortorder
.get(sort
),
29 1: datefilter
.get(date
),
30 2: typefilter
.get(type),
31 3: lenfilter
.get(len),
32 **{featureflags
[k
]:True for k
in features
if k
in featureflags
}
33 } if date
or type or len or features
else None,
34 8: { extraflags
[k
]:True for k
in extras
if k
in extraflags
} or None,
35 30: 1, # bypass searchFrictionViewModel
38 def make_channel_params(subject
, typ
="videos", sort
=None, query
=None):
39 if typ
in ("playlists",):
40 sortorder
= dict(newest
=3, modified
=4)
41 return continuation(subject
, {
42 2: "playlists", #type_s
44 3: sortorder
.get(sort
),#sort optional
46 23: 0, #unknown_const2
47 6: 2, #list_or_grid (2=list, None/1=grid)
48 61: proto({1: proto({1: 0})}) #offset
50 elif typ
in ("search",):
51 return continuation(subject
, {
54 23: 0, #unknown_const2
55 6: 2, #list_or_grid (2=list, None/1=grid)
57 elif typ
in ("videos", "streams", "shorts"):
58 sortorder
= dict(newest
=1, popular
=2)
59 typekey
= dict(videos
=15, streams
=14, shorts
=10)
60 return continuation(subject
, { 110: { 3: {
62 2: { 1: "00000000-0000-0000-0000-000000000000" },
63 3: sortorder
.get(sort
,1)
67 raise NotImplementedError
69 def make_playlist_params(playlist_id
, offset
):
70 # mix takes video id instead of offset. an id not in the playlist requests the beginning.
71 mix_playlist
= playlist_id
.startswith("RD")
72 return continuation("VL" + playlist_id
, {
74 { 2: '___________' } if mix_playlist
else { 1: offset
}