Skip to content

Instantly share code, notes, and snippets.

@priyadarshan
Created August 8, 2012 14:34
Show Gist options
  • Save priyadarshan/3295498 to your computer and use it in GitHub Desktop.
Save priyadarshan/3295498 to your computer and use it in GitHub Desktop.
imgur album downloader (by skeeto)
(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