mirror of
https://github.com/iv-org/invidious.git
synced 2026-07-07 06:06:48 -05:00
Make watch page work without Invidious Companion
- player endpoint now uses direct _post_json when companion is absent - When player endpoint fails, fall back to /next-only data extraction - Watch page renders with title, description, comments from /next - Set reason when companion unavailable for graceful error display - Handle not-found videos correctly with 404 redirect - Disabled companion in config for dev testing
This commit is contained in:
parent
d4a5593ab9
commit
f86bddd8b8
@ -57,10 +57,31 @@ module Invidious::Videos::Parser
|
|||||||
|
|
||||||
def extract_video_info(video_id : String)
|
def extract_video_info(video_id : String)
|
||||||
# Fetch data from the player endpoint
|
# Fetch data from the player endpoint
|
||||||
player_response = YoutubeAPI.player(video_id: video_id)
|
player_response = nil
|
||||||
|
begin
|
||||||
|
player_response = YoutubeAPI.player(video_id: video_id)
|
||||||
|
rescue ex
|
||||||
|
LOGGER.debug("extract_video_info: player endpoint failed for #{video_id}: #{ex.message}")
|
||||||
|
end
|
||||||
|
|
||||||
if player_response.nil?
|
if player_response.nil?
|
||||||
return nil
|
# Player endpoint failed (e.g. no companion). Try to get data from /next only.
|
||||||
|
begin
|
||||||
|
player_response = YoutubeAPI.next({"videoId": video_id, "params": ""})
|
||||||
|
rescue ex
|
||||||
|
LOGGER.debug("extract_video_info: /next also failed for #{video_id}: #{ex.message}")
|
||||||
|
raise NotFoundException.new("Video unavailable")
|
||||||
|
end
|
||||||
|
begin
|
||||||
|
params = self.parse_video_info(video_id, player_response)
|
||||||
|
params["version"] = JSON::Any.new(Video::SCHEMA_VERSION.to_i64)
|
||||||
|
params["reason"] = JSON::Any.new("Video unavailable")
|
||||||
|
params["subreason"] = JSON::Any.new("Invidious Companion is not available. Video playback is not possible.")
|
||||||
|
return params
|
||||||
|
rescue ex
|
||||||
|
LOGGER.debug("extract_video_info: parse from /next failed for #{video_id}: #{ex.message}")
|
||||||
|
raise NotFoundException.new("Video unavailable")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
playability_status = player_response.dig?("playabilityStatus", "status").try &.as_s
|
playability_status = player_response.dig?("playabilityStatus", "status").try &.as_s
|
||||||
|
|||||||
@ -463,7 +463,7 @@ module YoutubeAPI
|
|||||||
if CONFIG.invidious_companion.present?
|
if CONFIG.invidious_companion.present?
|
||||||
return self._post_invidious_companion("/youtubei/v1/player", data)
|
return self._post_invidious_companion("/youtubei/v1/player", data)
|
||||||
else
|
else
|
||||||
return nil
|
return self._post_json("/youtubei/v1/player", data, nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user