Skip to content

Instantly share code, notes, and snippets.

@mendelgusmao
Last active July 10, 2017 08:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mendelgusmao/4334243 to your computer and use it in GitHub Desktop.
Save mendelgusmao/4334243 to your computer and use it in GitHub Desktop.
Random Winamp playlist using ActiveWinamp, Ruby and Win32OLE
require "win32ole"
count = 100
ttl = 86400
cache_file = "wa.random.cache"
query = [
'type = "0"',
'length > "2:00"',
'title NOTHAS "intro"',
'filename NOTHAS "~"'
].join(" AND ")
winamp = WIN32OLE.connect "ActiveWinamp.Application"
winamp.playlist.clear
cache = File.open(cache_file, "r") { |io| io.read }.to_i
if cache > 0 and File.mtime(cache_file) + ttl < Time.now
(0..cache).to_a.sample(count).each do |index|
winamp.medialibrary.item(index).enqueue
end
else
items = winamp.medialibrary.runqueryarray(query)
items.sample(count).map &:enqueue
File.open(cache_file, "w") { |io| io.write(items.size) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment