SplashYou.rb
# Make call to YouTube api and check duration and number of views
Make call to YouTube api and check duration and number of views
Make call to YouTube api and check duration and number of views
def check_video(vid)
  vid['youtube_url'] = vid['youtube_url'][0...43]
  tube_id = vid['youtube_url'][32...43]
  tube_info = video_info_by_id(@service, 'snippet,contentDetails,statistics', id: tube_id)
  dur_sec = ISO8601::Duration.new(tube_info.fetch("contentDetails").fetch("duration")).to_seconds
  views = tube_info.fetch("statistics").fetch("viewCount")
  if dur_sec > 2700 && views.to_i > 100
    @vids[tube_id] = Hash.new
    @vids[tube_id]['reach']       = vid['reach']
    @vids[tube_id]['title']       = vid['title']
    @vids[tube_id]['youtube_url'] = vid['youtube_url']
    @vids[tube_id]['view_count']  = tube_info.fetch("statistics").fetch("viewCount")
    @vids[tube_id]['duration']    = hms(dur_sec)
  end
end
def check_video ( vid ) vid [ 'youtube_url' ] = vid [ 'youtube_url' ] [ 0 ... 43 ] tube_id = vid [ 'youtube_url' ] [ 32 ... 43 ] tube_info = video_info_by_id ( @service , 'snippet,contentDetails,statistics' , id : tube_id ) dur_sec = ISO8601 :: Duration . new ( tube_info . fetch ( "contentDetails" ) . fetch ( "duration" ) ) . to_seconds views = tube_info . fetch ( "statistics" ) . fetch ( "viewCount" ) if dur_sec > 2700 && views . to_i > 100 @vids [ tube_id ] = Hash . new @vids [ tube_id ] [ 'reach' ] = vid [ 'reach' ] @vids [ tube_id ] [ 'title' ] = vid [ 'title' ] @vids [ tube_id ] [ 'youtube_url' ] = vid [ 'youtube_url' ] @vids [ tube_id ] [ 'view_count' ] = tube_info . fetch ( "statistics" ) . fetch ( "viewCount" ) @vids [ tube_id ] [ 'duration' ] = hms ( dur_sec ) end end
Make call to YouTube api and check duration and number of views
Make call to YouTube api and check duration and number of views
# puts ("This videos's ID is #{tube_info.fetch("id")}. " + #        "Its title is '#{tube_info.fetch("snippet").fetch("title")}'. ")
vid