Skip to content

Instantly share code, notes, and snippets.

@ChrisRicca
Created November 7, 2009 06:19
Show Gist options
  • Save ChrisRicca/228570 to your computer and use it in GitHub Desktop.
Save ChrisRicca/228570 to your computer and use it in GitHub Desktop.
This is a script for downloading original files from premium (upgraded or manager) drops. Requires a few gems and curl (might need SSL libs installed)
#!/usr/bin/env ruby
# this will let you download the original files
# from a premium dropio drop
# run it in the command line with "ruby fetch_original_dropio_files.rb"
require 'rubygems'
require 'fileutils'
require 'httparty'
API_KEY = 'your_dropio_api_key'
class DropioFetcher
include HTTParty
format :json
base_uri 'api.drop.io'
default_params :api_key => API_KEY,
:version => '2.0',
:format => 'json'
def self.get_all_assets(dropname, password = nil)
password_option = password ? {:token => password} : {}
assets = []
total = 31
page = 1
while (page * 30) < total do
puts "Getting page #{page} of asset info..."
response = get("/drops/#{dropname}/assets", :query => {:page => page, :show_pagination_details => 'true'}.merge(password_option))
assets += response['assets']
total = response['total'].to_i
page+=1
end
assets
end
def self.get_original_file_url(dropname, assetname)
"http://api.drop.io/drops/#{dropname}/assets/#{assetname}/download/original"
end
end
# START SCRIPT
puts "Enter Drop Name: "
dropname = gets.chomp
puts "Enter Password (or nothing for guest access): "
password = gets.chomp
password = nil if password == ""
assets = DropioFetcher.get_all_assets(dropname, password)
FileUtils.mkdir dropname
FileUtils.cd dropname do
count = 0
assets.each do |asset|
puts "downloading asset #{count+=1} of #{assets.length}..."
puts `curl -o '#{asset['original_filename']}' --location --get -d api_key=#{API_KEY} -d version=2.0 "#{DropioFetcher.get_original_file_url(dropname,asset['name'])}"`
end
end
# THE END
# A note about the curl options for future reference
# -o designates the name of the file to save the request as
# --location tells curl to follow redirects
# --get tells curl to use GET and not POST
# -d parameters are used because curl isn't liking ?foo=bar params in the url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment