Last active
October 18, 2016 15:54
-
-
Save milothiesen/15968604c1457d98141b6872b4b54b9a to your computer and use it in GitHub Desktop.
A Vimeo API Scraper that will look through all videos belonging to a specific user.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'json' | |
| require 'httparty' | |
| require 'csv' | |
| output_counter = 0 | |
| video_info = [] | |
| (0..4).to_a.each do |p| | |
| # puts "THIS IS PAGE #{p.to_i+1}" | |
| user_id = "3045012" # substitute with the desired video ID | |
| api_url = "https://api.vimeo.com/users/#{user_id}/videos?page=#{p.to_i+1}&per_page=50&sort=date&fields=name,description,link,duration,stats.plays" | |
| auth = "Bearer [YOUR_VIMEO_ACCESS_TOKEN_HERE]" # use your access token | |
| r = HTTParty.get api_url, headers: { "Authorization" => auth, "Accept" => "application/vnd.vimeo.*+json;version=3.2" } # make sure to use the proper Accept header as recommended in the API docs | |
| v = JSON.parse(r) | |
| v['data'].each do |video| | |
| video_info << video | |
| end | |
| output_counter +=1 | |
| # puts JSON.pretty_generate(v) | |
| end | |
| File.open("vimeo_scraper_vs4_output.json","w") do |f| | |
| f.write(JSON.pretty_generate(video_info)) | |
| end | |
| CSV.open("vimeo_scraper_vs4_output.csv", "w", headers: video_info.first.keys) do |csv| | |
| video_info.each do |video| | |
| csv << video.values | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment