Created
August 8, 2012 14:34
-
-
Save priyadarshan/3295498 to your computer and use it in GitHub Desktop.
imgur album downloader (by skeeto)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'cl) | |
(require 'json) | |
(defun imgur/get-json (url) | |
"Get JSON data from an imgur album at URL." | |
(with-current-buffer (url-retrieve-synchronously url) | |
(goto-char (point-min)) | |
(search-forward "images: ") | |
(json-read))) | |
(defun imgur/get-hashes (json) | |
"Get the list of image hash IDs from JSON." | |
(map 'list (lambda (e) (cdr (assoc 'hash e))) (cdr (assoc 'items json)))) | |
(defun imgur/insert-wget-script (prefix hashes) | |
"Insert a download script with a filename PREFIX for the list of HASHES." | |
(let ((count 0)) | |
(dolist (hash hashes) | |
(insert (format "wget -O %s-%03d.jpg http://imgur.com/%s.jpg\n" | |
prefix count hash)) | |
(incf count)))) | |
(defun imgur/gen-script (prefix url) | |
"Insert a download script with file PREFIX for the image album at URL." | |
(interactive "sPrefix: \nsUrl: ") | |
(imgur/insert-wget-script prefix (imgur/get-hashes (imgur/get-json url)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From: http://www.reddit.com/r/dailyprogrammer/comments/wk0jf/7132012_challenge_76_difficult_imgur_album/c5e1xro