]> git.gir.st - subscriptionfeed.git/blob - app/browse/protobuf.py
bypass eating disorder (and probably others) search results block
[subscriptionfeed.git] / app / browse / protobuf.py
1 import base64
2 from . import pyproto
3
4 def proto(d, padding=False):
5 return base64.urlsafe_b64encode(pyproto.ProtoBuf(d).toBuf()) \
6 .decode('ascii').replace("=", "%3D" if padding else "")
7
8 def continuation(subject, params, query=None):
9 return proto({
10 80226972: {
11 2: subject,
12 3: proto(params, padding=True),
13 11: query,
14 }
15 }, padding=True)
16
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)
25
26 return proto({
27 1: sortorder.get(sort),
28 2: {
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
36 }, padding=True)
37
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
43 4: 1, #type_i
44 3: sortorder.get(sort),#sort optional
45 7: 1, #unknown_const1
46 23: 0, #unknown_const2
47 6: 2, #list_or_grid (2=list, None/1=grid)
48 61: proto({1: proto({1: 0})}) #offset
49 })
50 elif typ in ("search",):
51 return continuation(subject, {
52 2: "search",#type_s
53 7: 1, #unknown_const1
54 23: 0, #unknown_const2
55 6: 2, #list_or_grid (2=list, None/1=grid)
56 }, query)
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: {
61 typekey[typ]: {
62 2: { 1: "00000000-0000-0000-0000-000000000000" },
63 3: sortorder.get(sort,1)
64 }
65 }}})
66 else:
67 raise NotImplementedError
68
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, {
73 15: "PT:" + proto(
74 { 2: '___________' } if mix_playlist else { 1: offset }
75 )
76 })
Imprint / Impressum