muzak 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/muzak-index +106 -0
- data/lib/muzak/const.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dde0b299d121d7389c4ffc2e24c5239a6320ba92
|
4
|
+
data.tar.gz: bab3a86df140ae8b470d5781fb075b189ba7bc14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9244e21c503e122501659f1dcc58531f4b1ccc4764ac52a075b68be8c155d8e54ca3ce7e0e83043a368112e8dd4d4ec8a51f39a177a0b58678dd52f6dd570b2e
|
7
|
+
data.tar.gz: 274799ee46ae741ec52a36e2ddeba7072469f3503f297c887844091a62ad347a96673d42cc3b9df51ba6fccc352748df24f73fb780bfc1a5a81312bb976d867a
|
data/bin/muzak-index
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "muzak"
|
4
|
+
|
5
|
+
VERSION = 1
|
6
|
+
|
7
|
+
OPTS = {
|
8
|
+
deep: ARGV.delete("--deep") || ARGV.delete("-d"),
|
9
|
+
verbose: ARGV.delete("--verbose") || ARGV.delete("-V"),
|
10
|
+
help: ARGV.delete("--help") || ARGV.delete("-h"),
|
11
|
+
version: ARGV.delete("--version") || ARGV.delete("-v")
|
12
|
+
}
|
13
|
+
|
14
|
+
def help
|
15
|
+
puts <<~EOS
|
16
|
+
Usage: #{$PROGRAM_NAME} [options] <tree> [index]
|
17
|
+
|
18
|
+
Options:
|
19
|
+
--deep, -d Build a "deep" index (contains metadata)
|
20
|
+
--verbose, -V Be verbose while indexing
|
21
|
+
--help, -h Print this help message
|
22
|
+
--version, -v Print version information
|
23
|
+
|
24
|
+
Arguments:
|
25
|
+
[tree] The filesystem tree to index (default: ~/music)
|
26
|
+
[index] The saved index (default: ~/.config/muzak/index.dat)
|
27
|
+
EOS
|
28
|
+
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
|
32
|
+
def version
|
33
|
+
puts "muzak-index version #{VERSION}."
|
34
|
+
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
|
38
|
+
def info(msg)
|
39
|
+
puts "[\e[32minfo\e[0m]: #{msg}" if OPTS[:verbose]
|
40
|
+
end
|
41
|
+
|
42
|
+
def bail(msg)
|
43
|
+
STDERR.puts "[\e[31merror\e[0m]: #{msg}"
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
|
47
|
+
help if OPTS[:help]
|
48
|
+
version if OPTS[:version]
|
49
|
+
|
50
|
+
tree = ARGV.shift || Muzak::Config.music
|
51
|
+
bail "missing or invalid tree: <tree>" unless tree && File.exist?(tree)
|
52
|
+
|
53
|
+
index_file = ARGV.shift || Muzak::INDEX_FILE
|
54
|
+
|
55
|
+
index_hash = {
|
56
|
+
"tree" => tree,
|
57
|
+
"timestamp" => Time.now.to_i,
|
58
|
+
"artists" => {},
|
59
|
+
"deep" => OPTS[:deep]
|
60
|
+
}
|
61
|
+
|
62
|
+
Dir.entries(tree).each do |artist|
|
63
|
+
next unless File.directory?(File.join(tree, artist))
|
64
|
+
next if artist.start_with?(".")
|
65
|
+
|
66
|
+
info "indexing '#{artist}'..."
|
67
|
+
|
68
|
+
index_hash["artists"][artist] = {}
|
69
|
+
index_hash["artists"][artist]["albums"] = {}
|
70
|
+
|
71
|
+
Dir.entries(File.join(tree, artist)).each do |album|
|
72
|
+
next if album.start_with?(".")
|
73
|
+
|
74
|
+
info "\tindexing '#{album}'..."
|
75
|
+
|
76
|
+
index_hash["artists"][artist]["albums"][album] = {}
|
77
|
+
index_hash["artists"][artist]["albums"][album]["songs"] = []
|
78
|
+
index_hash["artists"][artist]["albums"][album]["deep-songs"] = []
|
79
|
+
|
80
|
+
Dir.glob(File.join(tree, artist, album, "**")) do |file|
|
81
|
+
index_hash["artists"][artist]["albums"][album]["cover"] = file if Muzak::Utils.album_art?(file)
|
82
|
+
|
83
|
+
if Muzak::Utils.music?(file)
|
84
|
+
index_hash["artists"][artist]["albums"][album]["songs"] << file
|
85
|
+
if OPTS[:deep]
|
86
|
+
index_hash["artists"][artist]["albums"][album]["deep-songs"] << Muzak::Song.new(file)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
index_hash["artists"][artist]["albums"][album]["songs"].sort!
|
92
|
+
|
93
|
+
# if any of the track numbers in the album are > 0 (the fallback),
|
94
|
+
# sort by ID3 track numbers. otherwise, hope that the song
|
95
|
+
# paths contain track numbers (e.g, "01 song.mp3").
|
96
|
+
if index_hash["artists"][artist]["albums"][album]["deep-songs"].any? { |s| s.track > 0 }
|
97
|
+
index_hash["artists"][artist]["albums"][album]["deep-songs"].sort_by!(&:track)
|
98
|
+
else
|
99
|
+
index_hash["artists"][artist]["albums"][album]["deep-songs"].sort_by!(&:path)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
File.open(index_file, "w") { |io| io.write Marshal.dump index_hash }
|
105
|
+
|
106
|
+
info "all done."
|
data/lib/muzak/const.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: muzak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Woodruff
|
@@ -30,6 +30,7 @@ executables:
|
|
30
30
|
- muzakd
|
31
31
|
- muzak-cmd
|
32
32
|
- muzak-dmenu
|
33
|
+
- muzak-index
|
33
34
|
extensions: []
|
34
35
|
extra_rdoc_files: []
|
35
36
|
files:
|
@@ -40,6 +41,7 @@ files:
|
|
40
41
|
- README.md
|
41
42
|
- bin/muzak-cmd
|
42
43
|
- bin/muzak-dmenu
|
44
|
+
- bin/muzak-index
|
43
45
|
- bin/muzakd
|
44
46
|
- lib/muzak.rb
|
45
47
|
- lib/muzak/album.rb
|