Skip to content

Commit

Permalink
I don't think this is a perfect replica of how the search endpoint wo…
Browse files Browse the repository at this point in the history
…rked, but I am at least seeing upcoming videos in the feed.. Haven't seen one that is live yet.
  • Loading branch information
stefansundin committed Jul 3, 2019
1 parent 315401f commit 3765232
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions app.rb
Expand Up @@ -237,10 +237,6 @@
end

get "/youtube/:channel_id/:username" do
if params.has_key?(:eventType) && params[:eventType] != "completed"
return [400, "Sorry, the eventType parameter has been discontinued since it is very expensive on my YouTube API quota, which has been running out every day for a while. I am unsure if it will be supported again in the future."]
end

@channel_id = params[:channel_id]
playlist_id = "UU" + @channel_id[2..]
@username = params[:username]
Expand All @@ -255,8 +251,18 @@
raise(GoogleError, response) if !response.success?
@data = response.json["items"]

if params[:eventType] == "completed"
@data.select! { |v| v.has_key?("liveStreamingDetails") }
if params.has_key?(:eventType)
eventTypes = params[:eventType].split(",")
eventType_completed = eventTypes.include?("completed")
eventType_live = eventTypes.include?("live")
eventType_upcoming = eventTypes.include?("upcoming")
@data.select! do |v|
v.has_key?("liveStreamingDetails") && (
(eventType_completed && v["liveStreamingDetails"].has_key?("actualEndTime")) ||
(eventType_live && v["liveStreamingDetails"].has_key?("actualStartTime") && !v["liveStreamingDetails"].has_key?("actualEndTime")) ||
(eventType_upcoming && v["liveStreamingDetails"].has_key?("scheduledStartTime") && !v["liveStreamingDetails"].has_key?("actualStartTime"))
)
end
end

if params.has_key?(:q)
Expand Down

0 comments on commit 3765232

Please sign in to comment.