muzak 0.1.8 → 0.2.0
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/COMMANDS.md +0 -33
- data/CONFIGURATION.md +0 -31
- data/lib/muzak/cmd/index.rb +0 -14
- data/lib/muzak/config.rb +0 -2
- data/lib/muzak/const.rb +1 -1
- data/lib/muzak/index.rb +9 -92
- data/lib/muzak/song.rb +1 -1
- data/lib/muzak/utils.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d298ab0d509e9b3cbf82b012a282ab8fe9fe7713
|
4
|
+
data.tar.gz: 1128e587b3f0d81ba2c0cbbd641dfb1e47cd9755
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b12d25d6fc3854b96926b49e78e9e57becd903987f2a4ff9438b91d7a0bb942fae43a7cc3b7b3cec08464672b4017803f20bcecc4f6028ae6f157ec7f637d230
|
7
|
+
data.tar.gz: 99a06151ac245f18e4a03fb9c12dc1dda1a57848c09487b4d7a27b5e7bebdf49bb88a98ecdc982e9fe2681e61a6408f3345c99b4dfdc5708717b3245171e56e8
|
data/COMMANDS.md
CHANGED
@@ -324,39 +324,6 @@ $ muzak-cmd help
|
|
324
324
|
}
|
325
325
|
```
|
326
326
|
|
327
|
-
## `index-build`
|
328
|
-
|
329
|
-
(Re-)builds the index.
|
330
|
-
|
331
|
-
**Note:** This command can take quite some time to run. It's generally a good
|
332
|
-
idea to either set `index-autobuild` in the configuration to do automatic
|
333
|
-
rebuilds or schedule this command via `cron` or a similar tool.
|
334
|
-
|
335
|
-
### Syntax
|
336
|
-
|
337
|
-
`index-build`
|
338
|
-
|
339
|
-
### Example
|
340
|
-
|
341
|
-
```bash
|
342
|
-
$ muzak-cmd index-build
|
343
|
-
```
|
344
|
-
|
345
|
-
### Example Response
|
346
|
-
|
347
|
-
```json
|
348
|
-
{
|
349
|
-
"response" : {
|
350
|
-
"error" : null,
|
351
|
-
"method" : "index_build",
|
352
|
-
"data" : {
|
353
|
-
"artists" : 10,
|
354
|
-
"albums": 100
|
355
|
-
}
|
356
|
-
}
|
357
|
-
}
|
358
|
-
```
|
359
|
-
|
360
327
|
## `jukebox`
|
361
328
|
|
362
329
|
Adds *N* random songs to the player's queue, where *N* is either the optional
|
data/CONFIGURATION.md
CHANGED
@@ -34,7 +34,6 @@ Muzak::Config.music # => "/home/william/mnt/fortuna/music/"
|
|
34
34
|
Muzak::Config.player # => "mpv"
|
35
35
|
Muzak::Config.art_geometry # => "300x300"
|
36
36
|
Muzak::Config.jukebox_size # => 100
|
37
|
-
Muzak::Config.deep_index # => true
|
38
37
|
```
|
39
38
|
|
40
39
|
Since {Muzak::Config} is populated whenever `muzak` is loaded via `require`,
|
@@ -119,36 +118,6 @@ initialize and control.
|
|
119
118
|
The short names of supported players can be found in
|
120
119
|
{Muzak::Player::PLAYER_MAP}.
|
121
120
|
|
122
|
-
### `index-autobuild`
|
123
|
-
|
124
|
-
*Optional.*
|
125
|
-
|
126
|
-
*Default:* `86400`
|
127
|
-
|
128
|
-
`index-autobuild: <span>` should be set to maximum number of seconds before
|
129
|
-
an index is considered outdated (based on its {Muzak::Index#timestamp} field).
|
130
|
-
|
131
|
-
When an outdated index is loaded and this key is set, muzak will automatically
|
132
|
-
rebuild the index.
|
133
|
-
|
134
|
-
**Note:** This is *not* an interval - the outdated index is only rebuilt
|
135
|
-
when a new {Muzak::Instance} or {Muzak::Index} is instantiated.
|
136
|
-
|
137
|
-
### `deep-index`
|
138
|
-
|
139
|
-
*Optional.*
|
140
|
-
|
141
|
-
*Default:* `false`
|
142
|
-
|
143
|
-
If `deep-index: true` is set in the configuration file, then muzak will
|
144
|
-
build a "deep" index. This involves opening each music file and reading metadata
|
145
|
-
from it, which can take substantially longer than just a shallow filesystem
|
146
|
-
index.
|
147
|
-
|
148
|
-
This primary benefit of this is caching - having all the song metadata in the
|
149
|
-
index allows muzak to make fewer disk accesses, which may be expensive over
|
150
|
-
a remote disk.
|
151
|
-
|
152
121
|
### `jukebox-size`
|
153
122
|
|
154
123
|
*Mandatory.*
|
data/lib/muzak/cmd/index.rb
CHANGED
@@ -1,19 +1,5 @@
|
|
1
1
|
module Muzak
|
2
2
|
module Cmd
|
3
|
-
# Rebuild the current instance's index.
|
4
|
-
# @command `index-build`
|
5
|
-
# @cmdexample `muzak> index-build`
|
6
|
-
def index_build(*args)
|
7
|
-
verbose "building a new index, this may take a while"
|
8
|
-
|
9
|
-
index.build!
|
10
|
-
|
11
|
-
build_response data: {
|
12
|
-
artists: index.artists.size,
|
13
|
-
albums: index.albums.size
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
3
|
# List all artists in the index.
|
18
4
|
# @command `list-artists`
|
19
5
|
# @cmdexample `muzak> list-artists`
|
data/lib/muzak/config.rb
CHANGED
data/lib/muzak/const.rb
CHANGED
data/lib/muzak/index.rb
CHANGED
@@ -4,7 +4,11 @@ module Muzak
|
|
4
4
|
include Utils
|
5
5
|
|
6
6
|
def self.load_index!
|
7
|
-
|
7
|
+
if File.exist?(INDEX_FILE)
|
8
|
+
Index.new
|
9
|
+
else
|
10
|
+
error! "#{INDEX_FILE} missing, did you forget to run muzak-index?"
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
# @return [String] the path of the root of the music tree
|
@@ -16,39 +20,10 @@ module Muzak
|
|
16
20
|
# @return [Hash] the index hash
|
17
21
|
attr_accessor :hash
|
18
22
|
|
19
|
-
# @param
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
# outdated, no building is performed.
|
24
|
-
# @see #build!
|
25
|
-
def initialize(tree, deep: false, sync: true)
|
26
|
-
@tree = tree
|
27
|
-
@deep = deep
|
28
|
-
|
29
|
-
if File.exist?(INDEX_FILE)
|
30
|
-
verbose "loading index from #{INDEX_FILE}"
|
31
|
-
@hash = Marshal::load(File.read INDEX_FILE)
|
32
|
-
return unless outdated?
|
33
|
-
end
|
34
|
-
|
35
|
-
build!(sync: sync)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Synchronize the in-memory index hash with {Muzak::INDEX_FILE}.
|
39
|
-
def sync!
|
40
|
-
File.open(INDEX_FILE, "w") { |io| io.write Marshal::dump @hash }
|
41
|
-
end
|
42
|
-
|
43
|
-
# (Re)builds and saves the index ({Muzak::INDEX_FILE}) to disk.
|
44
|
-
# @param sync [Boolean] whether or not to save to {Muzak::INDEX_FILE}
|
45
|
-
# @note This method can be expensive.
|
46
|
-
def build!(sync: true)
|
47
|
-
@hash = build_index_hash!
|
48
|
-
|
49
|
-
debug "indexed #{albums.length} albums by #{artists.length} artists"
|
50
|
-
|
51
|
-
sync! if sync
|
23
|
+
# @param index_file [String] the path of the index data file
|
24
|
+
def initialize(file: INDEX_FILE)
|
25
|
+
@hash = Marshal.load(File.read file)
|
26
|
+
@deep = @hash["deep"]
|
52
27
|
end
|
53
28
|
|
54
29
|
# @return [Boolean] whether or not the current index is deep
|
@@ -61,14 +36,6 @@ module Muzak
|
|
61
36
|
@hash["timestamp"]
|
62
37
|
end
|
63
38
|
|
64
|
-
# @return [Boolean] whether or not the index is currently out of date
|
65
|
-
# @note The behavior of this method is affected by the value of
|
66
|
-
# {Muzak::Config.index_autobuild}.
|
67
|
-
def outdated?
|
68
|
-
return false unless Config.index_autobuild
|
69
|
-
Time.now.to_i - timestamp >= Config.index_autobuild
|
70
|
-
end
|
71
|
-
|
72
39
|
# @return [Array<String>] a list of all artists in the index
|
73
40
|
def artists
|
74
41
|
@artists ||= @hash["artists"].keys
|
@@ -138,55 +105,5 @@ module Muzak
|
|
138
105
|
[]
|
139
106
|
end
|
140
107
|
end
|
141
|
-
|
142
|
-
private
|
143
|
-
|
144
|
-
def build_index_hash!
|
145
|
-
index_hash = {
|
146
|
-
"timestamp" => Time.now.to_i,
|
147
|
-
"artists" => {},
|
148
|
-
"deep" => deep
|
149
|
-
}
|
150
|
-
|
151
|
-
Dir.entries(tree).each do |artist|
|
152
|
-
next unless File.directory?(File.join(tree, artist))
|
153
|
-
next if artist.start_with?(".")
|
154
|
-
|
155
|
-
index_hash["artists"][artist] = {}
|
156
|
-
index_hash["artists"][artist]["albums"] = {}
|
157
|
-
|
158
|
-
Dir.entries(File.join(tree, artist)).each do |album|
|
159
|
-
next if album.start_with?(".")
|
160
|
-
|
161
|
-
index_hash["artists"][artist]["albums"][album] = {}
|
162
|
-
index_hash["artists"][artist]["albums"][album]["songs"] = []
|
163
|
-
index_hash["artists"][artist]["albums"][album]["deep-songs"] = []
|
164
|
-
|
165
|
-
Dir.glob(File.join(tree, artist, album, "**")) do |file|
|
166
|
-
index_hash["artists"][artist]["albums"][album]["cover"] = file if album_art?(file)
|
167
|
-
|
168
|
-
if music?(file)
|
169
|
-
index_hash["artists"][artist]["albums"][album]["songs"] << file
|
170
|
-
if deep?
|
171
|
-
index_hash["artists"][artist]["albums"][album]["deep-songs"] << Song.new(file)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
index_hash["artists"][artist]["albums"][album]["songs"].sort!
|
177
|
-
|
178
|
-
# if any of the track numbers in the album are > 0 (the fallback),
|
179
|
-
# sort by ID3 track numbers. otherwise, hope that the song
|
180
|
-
# paths contain track numbers (e.g, "01 song.mp3").
|
181
|
-
if index_hash["artists"][artist]["albums"][album]["deep-songs"].any? { |s| s.track > 0 }
|
182
|
-
index_hash["artists"][artist]["albums"][album]["deep-songs"].sort_by!(&:track)
|
183
|
-
else
|
184
|
-
index_hash["artists"][artist]["albums"][album]["deep-songs"].sort_by!(&:path)
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
index_hash
|
190
|
-
end
|
191
108
|
end
|
192
109
|
end
|
data/lib/muzak/song.rb
CHANGED
@@ -60,7 +60,7 @@ module Muzak
|
|
60
60
|
def best_guess_album_art
|
61
61
|
album_dir = File.dirname(path)
|
62
62
|
|
63
|
-
art = Dir.entries(album_dir).find { |ent| album_art?(ent) }
|
63
|
+
art = Dir.entries(album_dir).find { |ent| Utils.album_art?(ent) }
|
64
64
|
File.join(album_dir, art) unless art.nil?
|
65
65
|
end
|
66
66
|
|
data/lib/muzak/utils.rb
CHANGED
@@ -22,14 +22,14 @@ module Muzak
|
|
22
22
|
# Tests whether the given filename is likely to be music.
|
23
23
|
# @param filename [String] the filename to test
|
24
24
|
# @return [Boolean] whether or not the file is a music file
|
25
|
-
def music?(filename)
|
25
|
+
def self.music?(filename)
|
26
26
|
[".mp3", ".flac", ".m4a", ".wav", ".ogg", ".oga", ".opus"].include?(File.extname(filename.downcase))
|
27
27
|
end
|
28
28
|
|
29
29
|
# Tests whether the given filename is likely to be album art.
|
30
30
|
# @param filename [String] the filename to test
|
31
31
|
# @return [Boolean] whether or not the file is an art file
|
32
|
-
def album_art?(filename)
|
32
|
+
def self.album_art?(filename)
|
33
33
|
File.basename(filename) =~ /(cover)|(folder).(jpg)|(png)/i
|
34
34
|
end
|
35
35
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: muzak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Woodruff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: taglib-ruby
|