Skip to content

Instantly share code, notes, and snippets.

@edne
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edne/5914c7c849b77dd21ee9 to your computer and use it in GitHub Desktop.
Save edne/5914c7c849b77dd21ee9 to your computer and use it in GitHub Desktop.
When a friend (who cares more BPMs than bitrate) ask you "Can you make me a CD?", and you know what he likes
#! /usr/bin/env hy
(import [sh [cat du rm youtube-dl]]
[soundcloud [Client]])
(def SIZE 700)
(def MIN_BPM 170)
(def MAX_DURATION 10)
(def GENRE "jump up")
(def TAGS "drum and bass, dnb")
(defn foldersize []
(-> (du "-b") (.split "\t") car int))
(defn download [tracks]
(if tracks (do
(setv t (car tracks))
(setv filename
(.join "."
[t.title "mp3"]))
(print "downloading:" filename)
(youtube-dl "-v"
"--no-overwrites"
"-o" filename
t.stream_url)
(if (> (foldersize)
(* SIZE 1000 1000))
(rm filename)
(download (cdr tracks))))))
(defn alphanumeric [x]
(.join ""
(filter (fn [c]
(or (.isdigit c)
(.isalpha c)))
(str x))))
(defn tracklist []
(setv client
(apply Client
[]
{ "client_id"
(alphanumeric (cat "CLIENT_ID"))}))
(apply sorted
[(filter (fn [t]
t.streamable)
(apply .get
[client "/tracks"]
{ "limit" 200 ; is the maximum
"bpmfrom" MIN_BPM
"durationto" (* 1000 60 MAX_DURATION)
"tags" TAGS
"genres" GENRE}))]
{"key" (fn [t] t.playback_count)
"reverse" true}))
(defmain [&rest args]
(download (tracklist)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment