New method of getting vs and site_id (now with less html regexing)

Old way broke due to their react rewrite
This commit is contained in:
Nick/Nelson 2017-12-15 18:44:23 +00:00
parent bed0a8e84f
commit 66a657baa2
No known key found for this signature in database
GPG Key ID: 01365471E7AAA465
1 changed files with 12 additions and 5 deletions

View File

@ -2,6 +2,7 @@ require 'json'
require 'open-uri' require 'open-uri'
require 'fileutils' require 'fileutils'
require 'optparse' require 'optparse'
require 'securerandom'
options = {} options = {}
parser = OptionParser.new do |opts| parser = OptionParser.new do |opts|
@ -30,10 +31,16 @@ end
print "Loading initial data" print "Loading initial data"
# this is v gross, but they probably do it like this on purpose # this endpoint requires the referer for some reason
initial = open "https://vsco.co/#{user}/images/1" initial = open "https://vsco.co/content/Static/userinfo",
vs = /vs=(\S*);/.match(initial.meta['set-cookie']).captures[0] 'Cookie' => "vs_anonymous_id=#{SecureRandom.uuid}",
site_id = JSON.parse(/window.VSCOVARS.SiteSettings = ({.*})/.match(initial.read).captures[0])['id'] 'Referer' => "https://vsco.co/#{user}/images/1"
# the ol' jsonp for same origin requests because why not
vs = JSON.parse(initial.read[/{.+}/])['tkn']
sites = JSON.load open "https://vsco.co/ajxp/#{vs}/2.0/sites?subdomain=#{user}", 'Cookie' => "vs=#{vs}"
# the ol' return an array when you only queried for one thing
site_id = sites['sites'][0]['id']
# vsco seems to timeout on requests for very large amounts of images # vsco seems to timeout on requests for very large amounts of images
# it also doesn't send the actual total amount of images in requests # it also doesn't send the actual total amount of images in requests
@ -43,7 +50,7 @@ page = 1
size = 1000 size = 1000
images = [] images = []
loop do loop do
response = JSON.load open "https://vsco.co/ajxp/#{vs}/2.0/medias?site_id=#{site_id}&page=#{page}&size=#{size}", 'Cookie' => "vs=#{vs};" response = JSON.load open "https://vsco.co/ajxp/#{vs}/2.0/medias?site_id=#{site_id}&page=#{page}&size=#{size}", 'Cookie' => "vs=#{vs}"
images.concat response['media'] images.concat response['media']
break if response['total'] <= page * size break if response['total'] <= page * size
page += 1 page += 1