Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ItemsController < ApplicationController
before_action :set_item, only: [:show, :edit, :update, :destroy]
before_action :set_item, only: [:show, :edit, :update, :destroy, :adaptive]
before_action :require_login, except: [:index, :authorize]

def require_login
Expand Down Expand Up @@ -81,6 +81,12 @@ def authorize
end
end

# GET /items/1/adaptive.m3u8
def adaptive
@streams = @item.streams
render layout: false, content_type: 'text/plain'
end

private
# Use callbacks to share common setup or constraints between actions.
def set_item
Expand Down
5 changes: 5 additions & 0 deletions app/views/items/adaptive.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#EXTM3U
<% @streams.each do |stream| %>
#EXT-X-STREAM-INF:BANDWIDTH=<%= stream["bitrate"] %>
<%= stream["url"] + "?token=" + session[:token]%>
<% end %>
1 change: 1 addition & 0 deletions app/views/items/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
controls
preload="auto"
>
<source src="<%= adaptive_item_path(@item, format: "m3u8") %>" type="application/x-mpegURL" label="auto"/>
<% @item.streams.each do |stream| %>
<source src="<%= stream["url"] %>?token=<%= session[:token] %>" type="application/x-mpegURL" label="<%= stream["label"] %>"/>
<% end %>
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
collection do
get :authorize
end
member do
match 'adaptive', to: 'items#adaptive', via: [:get]
end
end
devise_for :users
root to: "items#index"
Expand Down