Skip to content

Commit

Permalink
Add headers which seem to fix the calendar name.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Apr 26, 2020
1 parent 3604d00 commit 73d1d90
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
end
body location.to_json
end

if headers["Content-Type"].start_with?("text/calendar")
headers({
"Content-Transfer-Encoding" => "binary",
"Content-Disposition" => "attachment; filename=\"#{@title}.ics\"",
})
end
end

get "/" do
Expand Down Expand Up @@ -238,6 +245,7 @@
get "/youtube/:channel_id/:username.ics" do
@channel_id = params[:channel_id]
@username = params[:username]
@title = "#{@username} on YouTube"

# The API is really inconsistent in listing scheduled live streams, but the RSS endpoint seems to consistently list them, so experiment with using that
response = HTTP.get("https://www.youtube.com/feeds/videos.xml?channel_id=#{@channel_id}")
Expand Down Expand Up @@ -267,9 +275,6 @@
@query = params[:q]
q = @query.downcase
@data.select! { |v| v["snippet"]["title"].downcase.include?(q) }
@title = "\"#{@query}\" from #{@username}"
else
@title = "#{@username} on YouTube"
end

@data.sort_by! do |video|
Expand Down

0 comments on commit 73d1d90

Please sign in to comment.