]> git.gir.st - subscriptionfeed.git/blob - app/browse/protobuf.py
search: support new 'medium length' filter
[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 }, padding=True)
36
37 def make_channel_params(subject, typ="videos", sort=None, query=None):
38 if typ in ("playlists",):
39 sortorder = dict(newest=3, modified=4)
40 return continuation(subject, {
41 2: "playlists", #type_s
42 4: 1, #type_i
43 3: sortorder.get(sort),#sort optional
44 7: 1, #unknown_const1
45 23: 0, #unknown_const2
46 6: 2, #list_or_grid (2=list, None/1=grid)
47 61: proto({1: proto({1: 0})}) #offset
48 })
49 elif typ in ("search",):
50 return continuation(subject, {
51 2: "search",#type_s
52 7: 1, #unknown_const1
53 23: 0, #unknown_const2
54 6: 2, #list_or_grid (2=list, None/1=grid)
55 }, query)
56 elif typ in ("videos", "streams", "shorts"):
57 sortorder = dict(newest=1, popular=2)
58 typekey = dict(videos=15, streams=14, shorts=10)
59 return continuation(subject, { 110: { 3: {
60 typekey[typ]: {
61 2: { 1: "00000000-0000-0000-0000-000000000000" },
62 3: sortorder.get(sort,1)
63 }
64 }}})
65 else:
66 raise NotImplementedError
67
68 def make_playlist_params(playlist_id, offset):
69 # mix takes video id instead of offset. an id not in the playlist requests the beginning.
70 mix_playlist = playlist_id.startswith("RD")
71 return continuation("VL" + playlist_id, {
72 15: "PT:" + proto(
73 { 2: '___________' } if mix_playlist else { 1: offset }
74 )
75 })
Imprint / Impressum