Skip to content

Instantly share code, notes, and snippets.

@yuya-takeyama
Last active August 29, 2015 14:11
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 yuya-takeyama/f270e904903911d108ea to your computer and use it in GitHub Desktop.
Save yuya-takeyama/f270e904903911d108ea to your computer and use it in GitHub Desktop.
はてなフォトライフにアップロードしている写真の一括バックアップ

API 使ってやろう、とも思ったけど OAuth 認証がやたらめんどくさそうだったので断念... 登録した写真はログイン後のトップページに全て収まる程度の量だったので、その URL (http://f.hatena.ne.jp/*/) を開いた状態で、Chrome のコンソールに

Array.prototype.map.apply(document.querySelectorAll('.foto_thumb'), [function (e) { return e.src.replace('_120', ''); }])

と入力。 これで URL の一覧を JSON っぽい文字列で取得できる。

["http://f.st-hatena.com/images/fotolife/*/*/20051021/20051021*.jpg","http://f.st-hatena.com/images/fotolife/*/*/20051021/20051021*.jpg"]

みたいな感じの配列。

これを適当に data.json とかで保存。 そした以下のコマンドを実行。

$ jq '.[]' data.json -r | ruby -ne 'url = $_.chop; basename = File.basename(url); cmd = "curl #{$_.chop} > #{basename}"; puts `#{cmd}`'

カレントディレクトリに画像が全てダウンロードされる。

ちなみにこのアカウントはプライベート設定なんだけど、jpg ファイルそれ自体には何のアクセス制限もかかっていないので、�素の curl コマンドでそのままダウンロードすることができた。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment