Last active
July 10, 2017 08:01
-
-
Save mendelgusmao/4334243 to your computer and use it in GitHub Desktop.
Random Winamp playlist using ActiveWinamp, Ruby and Win32OLE
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
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