@@ -154,8 +154,8 @@ if CONFIG.popular_enabled
154154 Invidious ::Jobs .register Invidious ::Jobs ::PullPopularVideosJob .new(PG_DB )
155155end
156156
157- connection_channel = Channel ({Bool , Channel (PQ ::Notification )}).new(32 )
158- Invidious ::Jobs .register Invidious ::Jobs ::NotificationJob .new(connection_channel , CONFIG .database_url)
157+ CONNECTION_CHANNEL = Channel ({Bool , Channel (PQ ::Notification )}).new(32 )
158+ Invidious ::Jobs .register Invidious ::Jobs ::NotificationJob .new(CONNECTION_CHANNEL , CONFIG .database_url)
159159
160160Invidious ::Jobs .start_all
161161
324324 Invidious ::Routing .get " /channel/:ucid/playlists" , Invidious ::Routes ::Channels , :playlists
325325 Invidious ::Routing .get " /channel/:ucid/community" , Invidious ::Routes ::Channels , :community
326326 Invidious ::Routing .get " /channel/:ucid/about" , Invidious ::Routes ::Channels , :about
327+ Invidious ::Routing .get " /channel/:ucid/live" , Invidious ::Routes ::Channels , :live
328+ Invidious ::Routing .get " /user/:user/live" , Invidious ::Routes ::Channels , :live
329+ Invidious ::Routing .get " /c/:user/live" , Invidious ::Routes ::Channels , :live
327330
328331 [" " , " /videos" , " /playlists" , " /community" , " /about" ].each do |path |
329332 # /c/LinusTechTips
360363 Invidious ::Routing .post " /playlist_ajax" , Invidious ::Routes ::Playlists , :playlist_ajax
361364 Invidious ::Routing .get " /playlist" , Invidious ::Routes ::Playlists , :show
362365 Invidious ::Routing .get " /mix" , Invidious ::Routes ::Playlists , :mix
366+ Invidious ::Routing .get " /watch_videos" , Invidious ::Routes ::Playlists , :watch_videos
363367
364368 Invidious ::Routing .get " /opensearch.xml" , Invidious ::Routes ::Search , :opensearch
365369 Invidious ::Routing .get " /results" , Invidious ::Routes ::Search , :results
@@ -406,85 +410,6 @@ define_v1_api_routes()
406410define_api_manifest_routes()
407411define_video_playback_routes()
408412
409- # Channels
410-
411- {" /channel/:ucid/live" , " /user/:user/live" , " /c/:user/live" }.each do |route |
412- get route do |env |
413- locale = env.get(" preferences" ).as(Preferences ).locale
414-
415- # Appears to be a bug in routing, having several routes configured
416- # as `/a/:a`, `/b/:a`, `/c/:a` results in 404
417- value = env.request.resource.split(" /" )[2 ]
418- body = " "
419- {" channel" , " user" , " c" }.each do |type |
420- response = YT_POOL .client & .get(" /#{ type } /#{ value } /live?disable_polymer=1" )
421- if response.status_code == 200
422- body = response.body
423- end
424- end
425-
426- video_id = body.match(/'VIDEO_ID': "(?<id>[a-zA-Z0-9_-] {11} ) "/ ).try & .[" id" ]?
427- if video_id
428- params = [] of String
429- env.params.query.each do |k , v |
430- params << " #{ k } =#{ v } "
431- end
432- params = params.join(" &" )
433-
434- url = " /watch?v=#{ video_id } "
435- if ! params.empty?
436- url += " &#{ params } "
437- end
438-
439- env.redirect url
440- else
441- env.redirect " /channel/#{ value } "
442- end
443- end
444- end
445-
446- # Authenticated endpoints
447-
448- # The notification APIs can't be extracted yet
449- # due to the requirement of the `connection_channel`
450- # used by the `NotificationJob`
451-
452- get " /api/v1/auth/notifications" do |env |
453- env.response.content_type = " text/event-stream"
454-
455- topics = env.params.query[" topics" ]?.try & .split(" ," ).uniq.first(1000 )
456- topics ||= [] of String
457-
458- create_notification_stream(env, topics, connection_channel)
459- end
460-
461- post " /api/v1/auth/notifications" do |env |
462- env.response.content_type = " text/event-stream"
463-
464- topics = env.params.body[" topics" ]?.try & .split(" ," ).uniq.first(1000 )
465- topics ||= [] of String
466-
467- create_notification_stream(env, topics, connection_channel)
468- end
469-
470- get " /Captcha" do |env |
471- headers = HTTP ::Headers {" :authority" => " accounts.google.com" }
472- response = YT_POOL .client & .get(env.request.resource, headers)
473- env.response.headers[" Content-Type" ] = response.headers[" Content-Type" ]
474- response.body
475- end
476-
477- # Undocumented, creates anonymous playlist with specified 'video_ids', max 50 videos
478- get " /watch_videos" do |env |
479- response = YT_POOL .client & .get(env.request.resource)
480- if url = response.headers[" Location" ]?
481- url = URI .parse(url).request_target
482- next env.redirect url
483- end
484-
485- env.response.status_code = response.status_code
486- end
487-
488413error 404 do |env |
489414 if md = env.request.path.match(/^\/ (?<id>([a-zA-Z0-9_-] {11} ) |(\w +) ) $/ )
490415 item = md[" id" ]
0 commit comments