muzak 0.2.1 → 0.2.2
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 +16 -14
- data/lib/muzak/const.rb +1 -1
- data/lib/muzak/index.rb +1 -5
- data/lib/muzak/player.rb +11 -1
- data/lib/muzak/player/mpv.rb +5 -0
- data/lib/muzak/player/stub_player.rb +5 -0
- data/lib/muzak/utils.rb +13 -3
- 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: 171a96f96d977d9cb964db7e1e14643117921dbe
|
4
|
+
data.tar.gz: 9cea9f8e1f6f229b24e6974b2efc698c3a9d5cd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dae34d10b94fb1f44e689209edef9e72e78ad42f1dcfb0ea50abf56f0e53f95c1317b25b20d964f89bdb7d4e41b974489535831da9a1e414a8de1a53965a72b9
|
7
|
+
data.tar.gz: 9283f7fa57a368be217d41c8b30e18385481bc4cc08b5a75d9427f5ede6522233f777014299cf7d935ecfb0b6ddaf2ef22aaebff24eef027f8e9f4dc688a594d
|
data/bin/muzak-index
CHANGED
@@ -5,10 +5,10 @@ require "muzak"
|
|
5
5
|
VERSION = 1
|
6
6
|
|
7
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")
|
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
12
|
}
|
13
13
|
|
14
14
|
def help
|
@@ -73,31 +73,33 @@ Dir.entries(tree).each do |artist|
|
|
73
73
|
|
74
74
|
info "\tindexing '#{album}'..."
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
album_hash = {}
|
77
|
+
album_hash["songs"] = []
|
78
|
+
album_hash["deep-songs"] = []
|
79
79
|
|
80
80
|
Dir.glob(File.join(tree, artist, album, "**")) do |file|
|
81
|
-
|
81
|
+
album_hash["cover"] = file if Muzak::Utils.album_art?(file)
|
82
82
|
|
83
83
|
if Muzak::Utils.music?(file)
|
84
|
-
|
84
|
+
album_hash["songs"] << file
|
85
85
|
if OPTS[:deep]
|
86
|
-
|
86
|
+
album_hash["deep-songs"] << Muzak::Song.new(file)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
|
91
|
+
album_hash["songs"].sort!
|
92
92
|
|
93
93
|
# if any of the track numbers in the album are > 0 (the fallback),
|
94
94
|
# sort by ID3 track numbers. otherwise, hope that the song
|
95
95
|
# paths contain track numbers (e.g, "01 song.mp3").
|
96
|
-
if
|
97
|
-
|
96
|
+
if album_hash["deep-songs"].any? { |s| s.track > 0 }
|
97
|
+
album_hash["deep-songs"].sort_by!(&:track)
|
98
98
|
else
|
99
|
-
|
99
|
+
album_hash["deep-songs"].sort_by!(&:path)
|
100
100
|
end
|
101
|
+
|
102
|
+
index_hash["artists"][artist]["albums"][album] = album_hash
|
101
103
|
end
|
102
104
|
end
|
103
105
|
|
data/lib/muzak/const.rb
CHANGED
data/lib/muzak/index.rb
CHANGED
@@ -14,21 +14,17 @@ module Muzak
|
|
14
14
|
# @return [String] the path of the root of the music tree
|
15
15
|
attr_accessor :tree
|
16
16
|
|
17
|
-
# @return [Boolean] whether the index is "deep" (includes metadata) or not
|
18
|
-
attr_accessor :deep
|
19
|
-
|
20
17
|
# @return [Hash] the index hash
|
21
18
|
attr_accessor :hash
|
22
19
|
|
23
20
|
# @param index_file [String] the path of the index data file
|
24
21
|
def initialize(file: INDEX_FILE)
|
25
22
|
@hash = Marshal.load(File.read file)
|
26
|
-
@deep = @hash["deep"]
|
27
23
|
end
|
28
24
|
|
29
25
|
# @return [Boolean] whether or not the current index is deep
|
30
26
|
def deep?
|
31
|
-
deep
|
27
|
+
@hash["deep"]
|
32
28
|
end
|
33
29
|
|
34
30
|
# @return [Integer] the UNIX timestamp from when the index was built
|
data/lib/muzak/player.rb
CHANGED
@@ -6,6 +6,8 @@ Dir.glob(File.join(__dir__, "player/*")) { |file| require_relative file }
|
|
6
6
|
module Muzak
|
7
7
|
# The namespace for muzak players.
|
8
8
|
module Player
|
9
|
+
extend Utils
|
10
|
+
|
9
11
|
# An association of shorthand player "names" to Class objects.
|
10
12
|
PLAYER_MAP = {
|
11
13
|
"stub" => Player::StubPlayer,
|
@@ -15,7 +17,15 @@ module Muzak
|
|
15
17
|
# Returns an instantiated player as specified in `Config.player`.
|
16
18
|
# @return [StubPlayer] the player instance
|
17
19
|
def self.load_player!(instance)
|
18
|
-
PLAYER_MAP[Config.player]
|
20
|
+
klass = PLAYER_MAP[Config.player]
|
21
|
+
|
22
|
+
error! "#{Config.player} isn't a known player" unless klass
|
23
|
+
|
24
|
+
if klass.available?
|
25
|
+
klass.new(instance)
|
26
|
+
else
|
27
|
+
error! "#{Config.player} isn't available, do you need to install it?"
|
28
|
+
end
|
19
29
|
end
|
20
30
|
end
|
21
31
|
end
|
data/lib/muzak/player/mpv.rb
CHANGED
@@ -7,6 +7,11 @@ module Muzak
|
|
7
7
|
module Player
|
8
8
|
# Exposes MPV's IPC to muzak for playback control.
|
9
9
|
class MPV < StubPlayer
|
10
|
+
# @return [Boolean] Whether or not MPV is available for execution
|
11
|
+
def self.available?
|
12
|
+
Utils.which?("mpv")
|
13
|
+
end
|
14
|
+
|
10
15
|
# @return [Boolean] Whether or not the current instance is running.
|
11
16
|
def running?
|
12
17
|
begin
|
@@ -7,6 +7,11 @@ module Muzak
|
|
7
7
|
# @return [Instance] the instance associated with this player
|
8
8
|
attr_reader :instance
|
9
9
|
|
10
|
+
# @return [true] whether or not this type of player is available
|
11
|
+
def self.available?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
10
15
|
# @param instance [Instance] the instance associated with the player
|
11
16
|
def initialize(instance)
|
12
17
|
@instance = instance
|
data/lib/muzak/utils.rb
CHANGED
@@ -33,6 +33,15 @@ module Muzak
|
|
33
33
|
File.basename(filename) =~ /(cover)|(folder).(jpg)|(png)/i
|
34
34
|
end
|
35
35
|
|
36
|
+
# Tests whether the given utility is available in the system path.
|
37
|
+
# @param util [String] the utility to test
|
38
|
+
# @return [Boolean] whether or not the utility is available
|
39
|
+
def self.which?(util)
|
40
|
+
ENV["PATH"].split(File::PATH_SEPARATOR).any? do |path|
|
41
|
+
File.executable?(File.join(path, util))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
36
45
|
# @return [Boolean] whether or not muzak is running in debug mode
|
37
46
|
def debug?
|
38
47
|
Config.debug
|
@@ -79,7 +88,8 @@ module Muzak
|
|
79
88
|
# @param args [Array<String>] the message(s)
|
80
89
|
# @return [void]
|
81
90
|
def error(*args)
|
82
|
-
|
91
|
+
context = self.is_a?(Module) ? name : self.class.name
|
92
|
+
output pretty(:red, "error"), "[#{context}]", args
|
83
93
|
end
|
84
94
|
|
85
95
|
# Outputs a boxed error message and then exits.
|
@@ -95,8 +105,8 @@ module Muzak
|
|
95
105
|
# @return [void]
|
96
106
|
def debug(*args)
|
97
107
|
return unless debug?
|
98
|
-
|
99
|
-
output pretty(:yellow, "debug"), "[#{
|
108
|
+
context = self.is_a?(Module) ? name : self.class.name
|
109
|
+
output pretty(:yellow, "debug"), "[#{context}]", args
|
100
110
|
end
|
101
111
|
|
102
112
|
# Outputs a boxed verbose message.
|
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.2.
|
4
|
+
version: 0.2.2
|
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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: taglib-ruby
|