Last active
December 18, 2015 00:19
-
-
Save kyv/5695560 to your computer and use it in GitHub Desktop.
Simple script in ruby which schedules genres of musica by hour. Personally I call it with mpdcron.
This file contains hidden or 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 ruby | |
require 'ruby-mpd' | |
mpd = MPD.new | |
mpd.connect | |
sched = ['Jazz', 'Jazz', 'Classical', 'Classical', 'Country', 'Blues', 'Son Jarocho', 'Jazz', 'Classical', 'Classical', 'Country', 'Blues', 'Jazz', 'Soul', 'R&B', 'R&B', 'Chilena', 'African', 'Afrobeat', 'Cumbia', 'Salsa', 'Tropical', 'Salsa' ,'Classical'] # 0-24 | |
# make list of filenames w/out extension | |
queue = mpd.queue.map {|x| x.file[/.*(?=\..+$)/]}.compact | |
time = Time.now + 900 # offset to account for queue length | |
# loop util we get a song which is not already in the playlist, removing file extensions | |
i = 0 | |
while i == 0 | |
s = mpd.search(:genre, sched[time.hour], :case_sensitive => false).sample | |
p "[try] #{s.file[/.*(?=\..+$)/]}" | |
unless queue.include?(s.file[/.*(?=\..+$)/]) | |
p "[add] #{s.file[/.*(?=\..+$)/]}" | |
mpd.add s.file | |
i = 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment