about summary refs log tree commit diff
path: root/configs/shared/.emacs.d/wpc/imdb.el
blob: 2969da140935d4f21ddfcf93b6b625e076f38305 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
;;; imdb.el --- Internet Movie Database -*- lexical-binding: t -*-
;; Author: William Carroll <wpcarro@gmail.com>

;;; Commentary:
;; Some Elisp to help me pick movies more quickly.

;;; Code:

(require 'f)
(require 'macros)
(require 'pcre2el)
(require 'random)
(require 'maybe)

;; TODO: How do you support types herein?
(cl-defstruct movie
  name
  year
  director
  watched?)

;; TODO: Support famous directors like:
;; - Wes Anderson
;; - Woody Allen
;; - Tarantino
;; - Coen Brothers
;; - Alfonso Cauron
;; - Alejandro González Iñárritu
;; - Alfred Hitchcock
;; - Stanley Kubrick

;; TODO: Dump this into SQL.

(defconst imdb/kubrick-films
  (->> '((:watched? nil :year 1951 :name "Flying Padre")
         (:watched? nil :year 1953 :name "Fear and Desire")
         (:watched? nil :year 1953 :name "The Seafarers")
         (:watched? nil :year 1955 :name "Killer's Kiss")
         (:watched? nil :year 1956 :name "The Killing")
         (:watched? nil :year 1957 :name "Paths of Glory")
         (:watched? nil :year 1960 :name "Spartacus")
         (:watched? nil :year 1962 :name "Lolita")
         (:watched? nil :year 1964 :name "Dr. Strangelove")
         (:watched? nil :year 1968 :name "2001: A Space Odyssey")
         (:watched? t   :year 1971 :name "A Clockwork Orange")
         (:watched? nil :year 1975 :name "Barry Lyndon")
         (:watched? nil :year 1980 :name "The Shining")
         (:watched? t   :year 1987 :name "Full Metal Jacket")
         (:watched? nil :year 1999 :name "Eyes Wide Shut"))
       (list/map (lambda (x)
                   (make-movie :name (plist-get :name x)
                               :year (plist-get :year x)
                               :director "Stanley Kubrick"
                               :watched? (plist-get :watched? x))))))

(defconst imdb/non-top-250
  (->> '("Doctor Zhivago"
         )
       (list/map #'imdb/new-movie)))

(defun imdb/new-movie (name)
  "Create a new movie with NAME."
  (make-movie :name name
              :year nil
              :director nil
              :watched? nil))

(defun imdb/org->movie (line)
  "Parse an org LINE into a movie struct."
  (let ((match (s-match
                (pcre-to-elisp "^\*\*\s(TODO|DONE)\s(.+)$")
                line)))
    (if (maybe/some? match)
        (make-movie :name (list/get 2 match)
                    :year nil
                    :director nil
                    :watched? (equal "DONE" (list/get 1 match)))
      (error (s-concat "Parsing error: " line)))))

;; TODO: Store these in a database or define them herein.
(defun imdb/org->movies ()
  "Parse entire IMDB org file into movie structs."
  (->> "~/Dropbox/org/imdb_top_250.org"
       f-read
       (s-split "\n")
       (-drop 1)
       (list/filter (>> (s-starts-with? "** ")))
       (list/map #'imdb/org->movie)))

(defun imdb/watched? (movie)
  "Return t if MOVIE has been watched."
  (movie-watched? movie))

(defconst imdb/movies (imdb/org->movies)
  "Structs of all watched movies.")

(defun imdb/unwatched ()
  "Return list of unwatched movies."
  (->> imdb/movies
       (list/filter (lambda (x) (not (imdb/watched? x))))))

(defun imdb/name (movie)
  "Return name of MOVIE."
  (movie-name movie))


(defun imdb/suggest ()
  "Randomly select movie from unwatched list."
  (->> (imdb/unwatched)
       (random/choice)
       (imdb/name)))

(defun imdb/unwatched-list ()
  "Dump all unwatched movies into a list."
  (f-write-text (->> (imdb/unwatched)
                     (list/map #'imdb/name)
                     (s-join "\n"))
                'utf-8
                "/tmp/unwatched.txt"))

(macros/comment
 (imdb/org->movies)
 (imdb/unwatched-list)
 (imdb/suggest)
 )

(provide 'imdb)
;;; imdb.el ends here