@@ -27,28 +27,21 @@ module Invidious::Routes::API::Manifest
27
27
haltf env, status_code: response.status_code
28
28
end
29
29
30
- manifest = response.body
31
-
32
- manifest = manifest.gsub(/<BaseURL>[^<] +<\/ BaseURL>/ ) do |baseurl |
33
- url = baseurl.lchop(" <BaseURL>" )
34
- url = url.rchop(" </BaseURL>" )
35
-
36
- if local
37
- uri = URI .parse(url)
38
- url = " #{ HOST_URL } #{ uri.request_target } host/#{ uri.host } /"
39
- end
40
-
30
+ # Proxy URLs for video playback on invidious.
31
+ # Other API clients can get the original URLs by omiting `local=true`.
32
+ manifest = response.body.gsub(/<BaseURL>[^<] +<\/ BaseURL>/ ) do |baseurl |
33
+ url = baseurl.lchop(" <BaseURL>" ).rchop(" </BaseURL>" )
34
+ url = HttpServer ::Utils .proxy_video_url(url, absolute: true ) if local
41
35
" <BaseURL>#{ url } </BaseURL>"
42
36
end
43
37
44
38
return manifest
45
39
end
46
40
47
- adaptive_fmts = video.adaptive_fmts
48
-
41
+ # Ditto, only proxify URLs if `local=true` is used
49
42
if local
50
- adaptive_fmts.each do |fmt |
51
- fmt[" url" ] = JSON ::Any .new(" #{ HOST_URL } #{ URI .parse (fmt[" url" ].as_s).request_target } " )
43
+ video. adaptive_fmts.each do |fmt |
44
+ fmt[" url" ] = JSON ::Any .new(HttpServer :: Utils .proxy_video_url (fmt[" url" ].as_s, absolute: true ) )
52
45
end
53
46
end
54
47
@@ -178,7 +171,8 @@ module Invidious::Routes::API::Manifest
178
171
179
172
if local
180
173
manifest = manifest.gsub(/^https:\/\/\w +---.{11} \. c\. youtube\. com[^\n ] */m ) do |match |
181
- path = URI .parse(match).path
174
+ uri = URI .parse(match)
175
+ path = uri.path
182
176
183
177
path = path.lchop(" /videoplayback/" )
184
178
path = path.rchop(" /" )
@@ -207,7 +201,7 @@ module Invidious::Routes::API::Manifest
207
201
raw_params[" fvip" ] = fvip[" fvip" ]
208
202
end
209
203
210
- raw_params[" local " ] = " true "
204
+ raw_params[" host " ] = uri.host.not_nil!
211
205
212
206
" #{ HOST_URL } /videoplayback?#{ raw_params } "
213
207
end
0 commit comments