summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-07-30 08:17:47 -0500
committerGitHub <noreply@github.com>2018-07-30 08:17:47 -0500
commit01e5bec246c1e23303bdcbb57b1d7d47009ccf39 (patch)
treeb8fe7d31ee204b5dcf023bef959da6657e809815 /src
parent50222fb1bc720cf0047ceeeb35a3a259d25eb018 (diff)
parent10d82d2d95ff961da6c73fc2773d366024d7f285 (diff)
downloadinvidious-01e5bec246c1e23303bdcbb57b1d7d47009ccf39.tar.gz
invidious-01e5bec246c1e23303bdcbb57b1d7d47009ccf39.tar.bz2
invidious-01e5bec246c1e23303bdcbb57b1d7d47009ccf39.zip
Merge pull request #44 from omarroth/add-livestreams
Add livestream support [EXPERIMENTAL]
Diffstat (limited to 'src')
-rw-r--r--src/invidious.cr65
-rw-r--r--src/invidious/views/watch.ecr36
2 files changed, 87 insertions, 14 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index 3e5cf4a9..fa7c0b21 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -371,6 +371,20 @@ get "/watch" do |env|
end
captions ||= [] of JSON::Any
+ if video.info["hlsvp"]?
+ hlsvp = video.info["hlsvp"]
+
+ if Kemal.config.ssl || CONFIG.https_only
+ scheme = "https://"
+ else
+ scheme = "http://"
+ end
+ host = env.request.headers["Host"]
+ url = "#{scheme}#{host}"
+
+ hlsvp = hlsvp.gsub("https://manifest.googlevideo.com", url)
+ end
+
rvs = [] of Hash(String, String)
if video.info.has_key?("rvs")
video.info["rvs"].split(",").each do |rv|
@@ -2474,6 +2488,57 @@ options "/videoplayback*" do |env|
env.response.headers["Access-Control-Allow-Headers"] = "Content-Type, range"
end
+get "/api/manifest/hls_variant/*" do |env|
+ client = make_client(YT_URL)
+ manifest = client.get(env.request.path)
+
+ if manifest.status_code != 200
+ halt env, status_code: 403
+ end
+
+ manifest = manifest.body
+
+ if Kemal.config.ssl || CONFIG.https_only
+ scheme = "https://"
+ else
+ scheme = "http://"
+ end
+ host = env.request.headers["Host"]
+
+ url = "#{scheme}#{host}"
+
+ env.response.content_type = "application/x-mpegURL"
+ env.response.headers.add("Access-Control-Allow-Origin", "*")
+ manifest.gsub("https://www.youtube.com", url)
+end
+
+get "/api/manifest/hls_playlist/*" do |env|
+ client = make_client(YT_URL)
+ manifest = client.get(env.request.path)
+
+ if manifest.status_code != 200
+ halt env, status_code: 403
+ end
+
+ if Kemal.config.ssl || CONFIG.https_only
+ scheme = "https://"
+ else
+ scheme = "http://"
+ end
+ host = env.request.headers["Host"]
+
+ url = "#{scheme}#{host}"
+
+ manifest = manifest.body.gsub("https://www.youtube.com", url)
+ manifest = manifest.gsub(/https:\/\/r\d---.{11}\.c\.youtube\.com/, url)
+ fvip = manifest.match(/hls_chunk_host\/r(?<fvip>\d)---/).not_nil!["fvip"]
+ manifest = manifest.gsub("seg.ts", "seg.ts/fvip/#{fvip}")
+
+ env.response.content_type = "application/x-mpegURL"
+ env.response.headers.add("Access-Control-Allow-Origin", "*")
+ manifest
+end
+
get "/videoplayback*" do |env|
path = env.request.path
if path != "/videoplayback"
diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr
index 810a43e7..31008a8d 100644
--- a/src/invidious/views/watch.ecr
+++ b/src/invidious/views/watch.ecr
@@ -29,28 +29,36 @@
<title><%= video.title %> - Invidious</title>
<% end %>
+<% if hlsvp %>
+<script src="https://unpkg.com/videojs-contrib-hls@5.14.1/dist/videojs-contrib-hls.min.js"></script>
+<% end %>
+
<div class="h-box">
<video style="width:100%" playsinline poster="<%= thumbnail %>" title="<%= HTML.escape(video.title) %>"
id="player" class="video-js vjs-16-9" data-setup="{}"
<% if autoplay %>autoplay<% end %>
<% if video_loop %>loop<% end %>
controls>
- <% if listen %>
- <% audio_streams.each_with_index do |fmt, i| %>
- <source src="<%= fmt["url"] %>" type='<%= fmt["type"] %>' label="<%= fmt["bitrate"] %>k" selected="<%= i == 0 ? true : false %>">
- <% end %>
+ <% if hlsvp %>
+ <source src="<%= hlsvp %>" type="application/x-mpegURL">
<% else %>
- <% fmt_stream.each_with_index do |fmt, i| %>
- <% if preferences %>
- <source src="<%= fmt["url"] %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= preferences.quality == fmt["label"].split(" - ")[0] %>">
- <% else %>
- <source src="<%= fmt["url"] %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= i == 0 ? true : false %>">
+ <% if listen %>
+ <% audio_streams.each_with_index do |fmt, i| %>
+ <source src="<%= fmt["url"] %>" type='<%= fmt["type"] %>' label="<%= fmt["bitrate"] %>k" selected="<%= i == 0 ? true : false %>">
+ <% end %>
+ <% else %>
+ <% fmt_stream.each_with_index do |fmt, i| %>
+ <% if preferences %>
+ <source src="<%= fmt["url"] %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= preferences.quality == fmt["label"].split(" - ")[0] %>">
+ <% else %>
+ <source src="<%= fmt["url"] %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= i == 0 ? true : false %>">
+ <% end %>
+ <% end %>
+
+ <% captions.each do |caption| %>
+ <track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption["name"]["simpleText"] %>"
+ srclang="<%= caption["languageCode"] %>" label="<%= caption["name"]["simpleText"]%> ">
<% end %>
- <% end %>
-
- <% captions.each do |caption| %>
- <track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption["name"]["simpleText"] %>"
- srclang="<%= caption["languageCode"] %>" label="<%= caption["name"]["simpleText"]%> ">
<% end %>
<% end %>
</video>