muzak 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dde0b299d121d7389c4ffc2e24c5239a6320ba92
4
- data.tar.gz: bab3a86df140ae8b470d5781fb075b189ba7bc14
3
+ metadata.gz: 171a96f96d977d9cb964db7e1e14643117921dbe
4
+ data.tar.gz: 9cea9f8e1f6f229b24e6974b2efc698c3a9d5cd9
5
5
  SHA512:
6
- metadata.gz: 9244e21c503e122501659f1dcc58531f4b1ccc4764ac52a075b68be8c155d8e54ca3ce7e0e83043a368112e8dd4d4ec8a51f39a177a0b58678dd52f6dd570b2e
7
- data.tar.gz: 274799ee46ae741ec52a36e2ddeba7072469f3503f297c887844091a62ad347a96673d42cc3b9df51ba6fccc352748df24f73fb780bfc1a5a81312bb976d867a
6
+ metadata.gz: dae34d10b94fb1f44e689209edef9e72e78ad42f1dcfb0ea50abf56f0e53f95c1317b25b20d964f89bdb7d4e41b974489535831da9a1e414a8de1a53965a72b9
7
+ data.tar.gz: 9283f7fa57a368be217d41c8b30e18385481bc4cc08b5a75d9427f5ede6522233f777014299cf7d935ecfb0b6ddaf2ef22aaebff24eef027f8e9f4dc688a594d
@@ -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
- index_hash["artists"][artist]["albums"][album] = {}
77
- index_hash["artists"][artist]["albums"][album]["songs"] = []
78
- index_hash["artists"][artist]["albums"][album]["deep-songs"] = []
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
- index_hash["artists"][artist]["albums"][album]["cover"] = file if Muzak::Utils.album_art?(file)
81
+ album_hash["cover"] = file if Muzak::Utils.album_art?(file)
82
82
 
83
83
  if Muzak::Utils.music?(file)
84
- index_hash["artists"][artist]["albums"][album]["songs"] << file
84
+ album_hash["songs"] << file
85
85
  if OPTS[:deep]
86
- index_hash["artists"][artist]["albums"][album]["deep-songs"] << Muzak::Song.new(file)
86
+ album_hash["deep-songs"] << Muzak::Song.new(file)
87
87
  end
88
88
  end
89
89
  end
90
90
 
91
- index_hash["artists"][artist]["albums"][album]["songs"].sort!
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 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)
96
+ if album_hash["deep-songs"].any? { |s| s.track > 0 }
97
+ album_hash["deep-songs"].sort_by!(&:track)
98
98
  else
99
- index_hash["artists"][artist]["albums"][album]["deep-songs"].sort_by!(&:path)
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
 
@@ -1,6 +1,6 @@
1
1
  module Muzak
2
2
  # Muzak's current version
3
- VERSION = "0.2.1".freeze
3
+ VERSION = "0.2.2".freeze
4
4
 
5
5
  # The root directory for all user configuration, data, etc
6
6
  CONFIG_DIR = File.expand_path("~/.config/muzak").freeze
@@ -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
@@ -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].new(instance)
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
@@ -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
@@ -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
- output pretty(:red, "error"), "[#{self.class.name}]", args
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"), "[#{self.class.name}]", args
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.1
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-09 00:00:00.000000000 Z
11
+ date: 2017-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: taglib-ruby