vsco-dll2/vsco-dl.rb

38 lines
1.1 KiB
Ruby
Raw Normal View History

2017-09-15 05:21:39 +02:00
require 'json'
require 'open-uri'
user = ARGV[0]
Dir.mkdir user unless File.exist? user
# this is v gross, but they probably do it like this on purpose
initial = open "https://vsco.co/#{user}/images/1"
vs = /vs=(\S*);/.match(initial.meta['set-cookie']).captures[0]
siteId = JSON.parse(/window.VSCOVARS.SiteSettings = ({.*})/.match(initial.read).captures[0])['id']
images = JSON.load(open("https://vsco.co/ajxp/#{vs}/2.0/medias?site_id=#{siteId}&page=0&size=-1", 'Cookie' => "vs=#{vs};"))['media']
images.each_with_index do |r, i|
print "Image #{i + 1} of #{images.length}\r"
$stdout.flush
2017-09-16 01:45:39 +02:00
jsonPath = File.join user, "#{r['upload_date']}.json"
unless File.exist? jsonPath
File.open jsonPath, 'w' do |file|
2017-09-15 05:21:39 +02:00
file.write JSON.pretty_generate r
end
2017-09-16 01:45:39 +02:00
end
jpgPath = File.join user, "#{r['upload_date']}.jpg"
unless File.exist? jpgPath
2017-09-15 05:21:39 +02:00
open "https://#{r['responsive_url']}" do |f|
2017-09-16 01:45:39 +02:00
File.open jpgPath, 'wb' do |file|
2017-09-15 05:21:39 +02:00
file.write f.read
end
end
end
if (i + 1) == images.length
puts "Image #{i + 1} of #{images.length} ...done!"
end
end