Last active
August 29, 2015 14:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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