]>
git.gir.st - subscriptionfeed.git/blob - app/browse/protobuf.py
2 from dataclasses
import dataclass
3 from typing
import Optional
5 from pure_protobuf
.dataclasses_
import field
, message
6 from pure_protobuf
.types
import int64
8 def b64e(b
, padding
=True):
9 return base64
.urlsafe_b64encode(b
).decode('ascii') \
10 .replace("=", "%3D" if padding
else "")
16 verbatim
: Optional
[bool] = field(1, default
=None) # don't fix spelling
19 class Filters
: # adapted from invidious
20 date
: Optional
[int64
] = field(1, default
=None)
21 type: Optional
[int64
] = field(2, default
=None)
22 length
: Optional
[int64
] = field(3, default
=None)
23 is_hd
: Optional
[bool] = field(4, default
=None)
24 subtitles
: Optional
[bool] = field(5, default
=None)
25 ccommons
: Optional
[bool] = field(6, default
=None)
26 is_3d
: Optional
[bool] = field(7, default
=None)
27 live
: Optional
[bool] = field(8, default
=None)
28 purchased
: Optional
[bool] = field(9, default
=None)
29 is_4k
: Optional
[bool] = field(14, default
=None)
30 is_360
: Optional
[bool] = field(15, default
=None)
31 location
: Optional
[bool] = field(23, default
=None)
32 is_hdr
: Optional
[bool] = field(25, default
=None)
36 sorted: Optional
[int64
] = field(1, default
=None)
37 filter: Optional
[Filters
] = field(2, default
=None)
38 extras
: Optional
[Extras
] = field(8, default
=None)
40 def make_sp(sort
=None, date
=None, type=None, len=None, features
=[], extras
=[]):
41 sortorder
= dict(relevance
=0, rating
=1, date
=2, views
=3)
42 datefilter
= dict(hour
=1, day
=2, week
=3, month
=4, year
=5)
43 typefilter
= dict(video
=1, channel
=2, playlist
=3, movie
=4, show
=5)
44 lenfilter
= dict(short
=1, long=2)
46 return b64e(SearchRequest(
47 sorted=sortorder
.get(sort
),
49 date
=datefilter
.get(date
),
50 type=typefilter
.get(type),
51 length
=lenfilter
.get(len),
52 **{f
:True for f
in features
},
53 ) if date
or type or len or features
else None,
54 extras
=Extras(**{f
:True for f
in extras
}),
62 offset
: int64
= field(3, default
=0)
65 class ChannelDataInner
:
66 offset
: int64
= field(1)
69 class ChannelDataContainer
:
70 data
: str = field(1) # base64 of ChannelDataInner
74 type_s
: str = field(2)
75 type_i
: Optional
[int64
] = field(4)
76 page
: Optional
[str] = field(15)
77 sort
: Optional
[int64
] = field(3, default
=None)
78 unknown_const1
: int64
= field(7, default
=1)
79 unknown_const2
: int64
= field(23, default
=0)
80 # usually returns gridResponses. to switch to listResponses (cargo-culting
81 # invidious, playlist continuations (not yet supported) require list):
82 list_or_grid
: Optional
[int64
] = field(6,default
=2) # 2=list, None/1=grid
83 # invidious sets those, but no idea why:
84 #field12:int64 = field(12,default=1)
85 #field13:str = field(13,default="") # playlists in list mode don't work without this
86 field61
: Optional
[str] = field(61, default
=None) # base64 channelData
90 subject
: str = field(2) # ucid/plid
91 params
: str = field(3) # b64e encoded
92 query
: Optional
[str] = field(11, default
=None) # channel search
96 params
: Params
= field(80226972)
97 def make_channel_params(subject
, typ
="videos", page
=1, sort
=None, query
=None, v3
=False):
98 typestr
= dict(videos
="videos", playlists
="playlists", search
="search")
99 typeint
= dict(videos
=0, playlists
=1, search
=None) # not supporting autogen'd
100 sortorder
= dict(popular
=1, oldest
=2, newest
=3)
101 if typ
== "playlists":
102 sortorder
= dict(newest
=3, modified
=4)
103 elif typ
== "search":
106 if page
and typ
=="search":
107 _page
= b64e(SearchOffset(offset
=(page
-1)*30).dumps(), padding
=False)
110 return b64e(Continuation(
113 params
=b64e(Subparams(
114 type_s
=typestr
.get(typ
),
115 type_i
=typeint
.get(typ
),
116 sort
=sortorder
.get(sort
),
119 ChannelDataContainer(
123 ).dumps(), padding
=False
125 ).dumps(), padding
=False
137 offset
: Optional
[int64
] = field(1) # normal playlists
138 after
: Optional
[str] = field(2) # mix playlist (RDCL*, RDCM*): video id of last loaded item (how to get first page!?)
141 class PlaylistSubparams
:
142 data
: str = field(15)
143 def make_playlist_params(playlist_id
, offset
):
144 # TODO: special type of playlists: (see https://github.com/nlitsme/youtube_tool)
145 # - PL*: normal playlists
146 # - special channel playlists (suffix=channel_id without UC):
147 # - UU*: newest uploads (works)
148 # - PU*: popular uploads (works)
149 # Note: youtubekids (e.g. PLMYEtVRpaqY00V9W81Cwmzp6N6vZqfUKD4) fallback-only (youtube webui 404's)
150 # - FL*: favourited uploads (works; 404's if private)
151 # - LL*: liked uploads (untested)
152 # - RDCMUC*: mix for channel (fallback only; e.g. RDCMUCYO_jab_esuFRV4b17AJtAw, undisplayable on youtube (only works on watch))
153 # - CL, EL, MQ, TT: unknown
154 # - OLAK5uy_ music album playlist (works, e.g. OLAK5uy_m4xAFdmMC5rX3Ji3g93pQe3hqLZw_9LhM)
155 # - RD*: mix playlist (works with after=; e.g. RDCLAK5uy_kLWIr9gv1XLlPbaDS965-Db4TrBoUTxQ8, RDCLAK5uy_mx8mvGaCkyI12AedAu8yIbBpEYmg6Ayow, RDCLAK5uy_n340faD9pPGRVEVwozYTzIpfXuqmQwcgA, RDCLAK5uy_kQmVjdr90p2onIIAnijgU8u9iUUAOXM2I)
156 # https://www.youtube.com/watch?v=FTQbiNvZqaY&list=RDCLAK5uy_khNGopKCT_t38MZ1W7z4kERrqprkXovxo&start_radio=1
157 # - EC, UL, TL: unknown
158 # - own user playlists (obviously not working):
161 # - LL: own liked videos
162 # - LM: own liked youtube-music videos
164 if playlist_id
.startswith("RD"):
165 # NOTE: this only fixes RDCLAK5uy_, not RDCMUC
166 after
= '___________' # any video id that doesn't exist within the playlist requests the beginning
169 return b64e(Continuation(
171 subject
="VL" + playlist_id
,
172 params
=b64e(PlaylistSubparams(
173 data
="PT:" + b64e(PlaylistData(
176 ).dumps(), padding
=False)