Skip to content

Instantly share code, notes, and snippets.

Last active December 11, 2015 21:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A non-browser-based imitation of (play random videos from in 50 lines of Clojure in the REPL. Another way in which this is different from is that it doesn't repeat videos that have already been viewed (unless you restart the process). Make sure to set video-player to a video-player application tha…
(require '[cemerick.pomegranate :refer [add-dependencies]])
:coordinates '[[clj-http "0.6.3"]
[swiss-arrows "0.5.1"]]
:repositories {"clojars" ""})
(require '[clj-http.client :as client]
'[swiss-arrows.core :refer [-<>]]
'[clojure.string :as str]
'[ :refer [sh]])
(def search-term "")
(def video-player "/usr/bin/mplayer")
(defn vine-video-url [vine-url]
(try (-<> (:body (client/get vine-url))
(str/split #"\n")
(filter (partial re-find #"source src") <>)
(str/replace #"^.*(http[^\"]+)\".*$" "$1"))
(catch Exception e nil)))
(defn vine-urls []
(try (->> (client/get ""
{"q" (format " %s" (or search-term ""))
"rpp" "10"
"include_entities" "true"
"result_type" "mixed"}
:as :json})
(take 10)
(map (comp first
(partial filter #(re-find #"vine\.co" %))
(partial map :expanded_url)
(catch Exception e nil)))
(def play-video
(fn [url]
(with-open [w ( "tmp.mp4")]
(.write w (:body (client/get url {:as :byte-array}))))
(sh video-player "tmp.mp4"))))
(loop [] (doseq [vid-url (keep vine-video-url (vine-urls))]
(play-video vid-url))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment