-
Notifications
You must be signed in to change notification settings - Fork 7
/
audacious-dmenu
executable file
·48 lines (35 loc) · 1.11 KB
/
audacious-dmenu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env ruby
require 'shellwords'
# Array of [ [dirname, path], ... ]
raw_mp3s = Dir["#{ENV["HOME"]}/m/music/*"] +
Dir["#{ENV["HOME"]}/m/music/\\[offline\\]/*"] +
Dir["#{ENV["HOME"]}/m/music/\\[radio\\]/*"]
paths = raw_mp3s.
reject { |e| e =~ /\.\w{1,4}$/ unless e =~ /\.(xspf|m3u8?)$/ }.
map {|path| [path.split("/").last, path] }.
sort_by {|path| path.first.downcase }
paths =
paths.sample(10) + # Random albums
[["-"*50,nil]] + # ASCII horizontal line
paths
names = paths.to_h
path =
IO.popen(%w[dmenu -l 40 -i -b -p Album:], "r+") do |f|
f.puts names.keys.join("\n")
f.close_write
picked = f.gets.strip
names[picked]
end
EXTS = %w[
mp3 m4a flac ogg wma fla flv mp2
]
AUDIO_RE = /\.#{Regexp.union EXTS}$/
# expanded =
# Dir.open(path).
# drop(2).
# map { |filename| File.join(path, filename) }.
# select { |fullpath| File.directory?(fullpath) || fullpath =~ AUDIO_RE }
# # require 'pp'; pp expanded
# exec("audacious", *expanded)
files = Dir["#{Shellwords.escape path}/**/*.{#{EXTS.join(",")}}"]
exec("audacious", *files)