Skip to content

Instantly share code, notes, and snippets.

@bo0ts
Created October 23, 2012 21:27
Show Gist options
  • Save bo0ts/3941705 to your computer and use it in GitHub Desktop.
Save bo0ts/3941705 to your computer and use it in GitHub Desktop.
Query IMDB and parse the result into org-mode
(require 'url)
(defun get-and-parse-json (url)
(interactive)
(with-current-buffer (url-retrieve-synchronously url)
(goto-char (point-min))
(re-search-forward "^$")
(json-read)))
(defun get-movie-json (title &optional year)
(let ((url (concat "http://omdbapi.com/?t=" (url-hexify-string title))))
(if (consp year)
(get-and-parse-json (concat url "&y=" (number-to-string year)))
(get-and-parse-json url))))
(defun org-from-imdb-json (jsonmovie)
(concat "* [[imdb:" (cdr (assoc 'imdbID jsonmovie)) "][" (cdr (assoc 'Title jsonmovie)) "]]\n"
":PROPERTIES:\n"
":Director: " (cdr (assoc 'Director jsonmovie)) "\n"
":Year: " (cdr (assoc 'Year jsonmovie)) "\n"
":Actors: " (cdr (assoc 'Genre jsonmovie)) "\n"
":Genre: " (cdr (assoc 'Actors jsonmovie)) "\n"
":Plot: " (cdr (assoc 'Plot jsonmovie))
":END:\n"
"[[" (cdr (assoc 'Poster jsonmovie)) "]]"
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment