Skip to content

Instantly share code, notes, and snippets.

@ongaeshi
Created February 25, 2017 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ongaeshi/2d6892bccd34d67e43a7e39a2ed9395b to your computer and use it in GitHub Desktop.
Save ongaeshi/2d6892bccd34d67e43a7e39a2ed9395b to your computer and use it in GitHub Desktop.
url = Popup.input "amebloのURLを入力してください"
#todo: amebloアプリからsafariで開いた際に余計なパラメータが付くことがありyqlで失敗する。パラメータを除去する
url = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D'" + url + "'%20and%20xpath%3D'%2F%2Fimg%5Bcontains(%40src%2C%20%22http%3A%2F%2Fstat.ameba.jp%2Fuser_images%2F%22)%5D%5Bnot(contains(%40src%2C%20%22%3Fcpd%3D%22))%5D'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"
json = Browser.json url
#p json
imgs = json['query']['results']['img']
imgs = [imgs] unless imgs.is_a? Array
num = 0
imgs.each do |e|
src = e['src']
# src = src.sub(/^http/, "https")
if src =~ /\?caw=/
i = Image.load(src)
puts i, src
i.save
num += 1
end
end
puts "Saved #{num} photos to camera roll."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment