Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix proxying live DASH streams #4589

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/invidious/routes/video_playback.cr
Expand Up @@ -21,7 +21,7 @@ module Invidious::Routes::VideoPlayback
end

# Sanity check, to avoid being used as an open proxy
if !host.matches?(/[\w-]+.googlevideo.com/)
if !host.matches?(/[\w-]+\.(?:googlevideo|c\.youtube)\.com/)
return error_template(400, "Invalid \"host\" parameter.")
end

Expand All @@ -37,7 +37,8 @@ module Invidious::Routes::VideoPlayback

# See: https://github.com/iv-org/invidious/issues/3302
range_header = env.request.headers["Range"]?
if range_header.nil?
sq = query_params["sq"]?
if range_header.nil? && sq.nil?
Comment on lines +40 to +41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Range header here is only added for the HEAD request below. After that, it's removed again. Does that change really make a difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm odd, when I tested it without this change before it didn't work but I've just tested it again and now it worked without removing the range header too???

Personally I wouldn't send it, even if it doesn't make a difference, as YouTube's player would never send it for live stream segments either, but it's up to you to decide what the best approach is for Invidious.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should try to get rid of that HEAD request at some point.
I really want to split the logic between DASH and progressive streams/download, but I don't know where to start, this code has always broke on me every time I tried to make significant changes...

range_for_head = query_params["range"]? || "0-640"
headers["Range"] = "bytes=#{range_for_head}"
end
Expand Down