Skip to content

Instantly share code, notes, and snippets.

@kyv
Last active December 18, 2015 00:19
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 kyv/5695560 to your computer and use it in GitHub Desktop.
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.
#!/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