muzak 0.2.7 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b64a222cbd2a691404714a63b195ee2a78bb82b3
4
- data.tar.gz: 8d5547a8facf37798f822e53c97d9070dd29b6aa
3
+ metadata.gz: 917b86d06294801e33561fe181e64fd755f09828
4
+ data.tar.gz: 3aebb78550918a276f0cefc7fc11e57d277759a3
5
5
  SHA512:
6
- metadata.gz: 999969bedb0fb6d2ea42fa856266702f2464207d6e3480eaccf8cad09f69b260e7981e8c7dc119cf0e02dfba0a9bf821230c1f8eb199137f9739e1d8866fa772
7
- data.tar.gz: db562a2611427925e9c2a1621b5d294f6597dba8813647d9035ef7ecc57d8293b90f4f30c53f055b5b22a684ba418e0e2ecf9a5606c1a3268af47bb0d3144cf6
6
+ metadata.gz: 2f9bcb70833ce12b36e14e2f56e6042cdbfef39dc88362b8e9908a255f1eaad19d185956ebde3dbf8608f562e41a3e52151390a9c49b6afb2b38435646c53e77
7
+ data.tar.gz: 817a120b22297d8f3ba64afa8fe11a42452914c628de0f4b1a5f64d4d701b44c371024b2cdba0e9191cb9555ed4a0bd7d84fd8cadc2f8921c2e0e3e7f231e1fd
@@ -8,8 +8,8 @@ For the developer documentation, see {Muzak::Config}.
8
8
  ## General behavior
9
9
 
10
10
  All of muzak's configuration is kept in {Muzak::Config}, which is read
11
- during load-time (i.e., during `require`) from {Muzak::CONFIG_FILE}, which
12
- is YAML-formatted.
11
+ during load-time (i.e., during `require`) from {Muzak::Config::CONFIG_FILE},
12
+ which is YAML-formatted.
13
13
 
14
14
  Muzak loads configuration keys just like commands, translating them from
15
15
  `kebab-case` to `snake_case`. For example, take the following configuration:
@@ -1,6 +1,5 @@
1
- require_relative "muzak/const"
2
- require_relative "muzak/utils"
3
1
  require_relative "muzak/config"
2
+ require_relative "muzak/utils"
4
3
  require_relative "muzak/plugin"
5
4
  require_relative "muzak/song"
6
5
  require_relative "muzak/album"
@@ -10,3 +9,8 @@ require_relative "muzak/cmd"
10
9
  require_relative "muzak/player"
11
10
  require_relative "muzak/instance"
12
11
 
12
+ # The primary namespace for muzak.
13
+ module Muzak
14
+ # Muzak's current version
15
+ VERSION = "0.3.0".freeze
16
+ end
@@ -5,12 +5,12 @@ module Muzak
5
5
  # @see file:COMMANDS.md User Commands
6
6
  module Cmd
7
7
  # load commands included by the user
8
- Dir.glob(File.join(USER_COMMAND_DIR, "*")) { |file| require file }
8
+ Dir.glob(File.join(Config::USER_COMMAND_DIR, "*")) { |file| require file }
9
9
 
10
10
  # @return [Array<String>] all valid muzak commands
11
11
  def self.commands
12
12
  commands = instance_methods.map(&:to_s).reject { |m| m.start_with?("_") }
13
- commands.map { |c| Utils.resolve_method c }
13
+ commands.map { |c| Config.resolve_method c }
14
14
  end
15
15
  end
16
16
  end
@@ -6,7 +6,7 @@ module Muzak
6
6
  # @command `config-get <key>`
7
7
  # @cmdexample `muzak> config-get player`
8
8
  def config_get(key)
9
- value = Config.send Utils.resolve_command(key)
9
+ value = Config.send Config.resolve_command(key)
10
10
 
11
11
  build_response data: { key => value }
12
12
  end
@@ -10,6 +10,81 @@ module Muzak
10
10
  # Config.art_geometry # => "300x300"
11
11
  # @see file:CONFIGURATION.md User Configuration
12
12
  class Config
13
+ # The root directory for all user configuration, data, etc
14
+ CONFIG_DIR = File.expand_path("~/.config/muzak").freeze
15
+
16
+ # Muzak's primary configuration file
17
+ # @see Muzak::Config
18
+ CONFIG_FILE = File.join(CONFIG_DIR, "muzak.yml").freeze
19
+
20
+ # Muzak's music index
21
+ INDEX_FILE = File.join(CONFIG_DIR, "index.dat").freeze
22
+
23
+ # The directory for all user playlists
24
+ PLAYLIST_DIR = File.join(CONFIG_DIR, "playlists").freeze
25
+
26
+ # The directory for all user plugins
27
+ USER_PLUGIN_DIR = File.join(CONFIG_DIR, "plugins").freeze
28
+
29
+ # The directory for all user commands
30
+ USER_COMMAND_DIR = File.join(CONFIG_DIR, "commands").freeze
31
+
32
+ # All filename suffixes that muzak recognizes as music.
33
+ MUSIC_SUFFIXES = [
34
+ ".mp3",
35
+ ".flac",
36
+ ".m4a",
37
+ ".wav",
38
+ ".ogg",
39
+ ".oga",
40
+ ".opus",
41
+ ].freeze
42
+
43
+ # The regular expression that muzak uses to find album art.
44
+ ALBUM_ART_REGEX = /(cover)|(folder).(jpg)|(png)/i.freeze
45
+
46
+ # All events currently propagated by {Muzak::Instance#event}
47
+ PLUGIN_EVENTS = [
48
+ :instance_started,
49
+ :player_activated,
50
+ :player_deactivated,
51
+ :song_loaded,
52
+ :song_unloaded,
53
+ :playlist_enqueued,
54
+ ].freeze
55
+
56
+ # The default configuration keys and values.
57
+ DEFAULT_CONFIG = {
58
+ # core defaults
59
+ "debug" => false,
60
+ "verbose" => true,
61
+ "music" => File.expand_path("~/music"),
62
+ "player" => "mpv",
63
+ "jukebox-size" => 100,
64
+
65
+ # client/daemon defaults
66
+ "daemon-port" => 2669,
67
+ "daemon-host" => "localhost",
68
+ }.freeze
69
+
70
+ # Convert the given command into a method (kebab to camel case).
71
+ # @param cmd [String] the command to convert
72
+ # @return [String] the method corresponding to the command
73
+ # @example
74
+ # resolve_command "do-something" # => "do_something"
75
+ def self.resolve_command(cmd)
76
+ cmd.tr "-", "_"
77
+ end
78
+
79
+ # Convert the given method into a command (camel to kebab case).
80
+ # @param meth [String, Symbol] the method to convert
81
+ # @return [String] the command corresponding to the method
82
+ # @example
83
+ # resolve_method "do_something" # => "do-something"
84
+ def self.resolve_method(meth)
85
+ meth.to_s.tr "_", "-"
86
+ end
87
+
13
88
  # Catches all undefined configuration keys and defaults them to false.
14
89
  # @return [false]
15
90
  def self.method_missing(method, *args)
@@ -29,19 +104,6 @@ module Muzak
29
104
  respond_to? "plugin_#{pname}"
30
105
  end
31
106
 
32
- DEFAULT_CONFIG = {
33
- # core defaults
34
- "debug" => false,
35
- "verbose" => true,
36
- "music" => File.expand_path("~/music"),
37
- "player" => "mpv",
38
- "jukebox-size" => 100,
39
-
40
- # client/daemon defaults
41
- "daemon-port" => 2669,
42
- "daemon-host" => "localhost",
43
- }.freeze
44
-
45
107
  if File.exist?(CONFIG_FILE)
46
108
  user_config = YAML::load_file(CONFIG_FILE)
47
109
  else
@@ -57,11 +119,11 @@ module Muzak
57
119
  @config = DEFAULT_CONFIG.merge(user_config)
58
120
 
59
121
  @config.each do |key, _|
60
- define_singleton_method Utils.resolve_command(key) do
122
+ define_singleton_method resolve_command(key) do
61
123
  @config[key]
62
124
  end
63
125
 
64
- define_singleton_method "#{Utils.resolve_command(key)}=" do |value|
126
+ define_singleton_method "#{resolve_command(key)}=" do |value|
65
127
  @config[key] = value
66
128
  sync!
67
129
  end
@@ -3,11 +3,12 @@ module Muzak
3
3
  class Index
4
4
  include Utils
5
5
 
6
+ # @return [Index] a {Index} instance instantiated with {Config::INDEX_FILE}
6
7
  def self.load_index!
7
- if File.exist?(INDEX_FILE)
8
+ if File.exist?(Config::INDEX_FILE)
8
9
  Index.new
9
10
  else
10
- error! "#{INDEX_FILE} missing, did you forget to run muzak-index?"
11
+ error! "#{Config::INDEX_FILE} missing, did you forget to run muzak-index?"
11
12
  end
12
13
  end
13
14
 
@@ -17,9 +18,9 @@ module Muzak
17
18
  # @return [Hash] the index hash
18
19
  attr_accessor :hash
19
20
 
20
- # @param index_file [String] the path of the index data file
21
- def initialize(file: INDEX_FILE)
22
- debug "loading index from '#{INDEX_FILE}'..."
21
+ # @param file [String] the path of the index data file
22
+ def initialize(file: Config::INDEX_FILE)
23
+ debug "loading index from '#{Config::INDEX_FILE}'..."
23
24
 
24
25
  @hash = Marshal.load(File.read file)
25
26
  end
@@ -12,7 +12,7 @@ module Muzak
12
12
  # instance.command "pause"
13
13
  def command(cmd, *args)
14
14
  if Cmd.commands.include?(cmd)
15
- meth = method(Utils.resolve_command(cmd))
15
+ meth = method(Config.resolve_command(cmd))
16
16
  if meth.arity == args.size || meth.arity <= -1
17
17
  meth.call *args
18
18
  else
@@ -57,9 +57,9 @@ module Muzak
57
57
  # Dispatch an event to all plugins.
58
58
  # @param type [Symbol] the type of event to dispatch
59
59
  # @param args [Array] the event's arguments
60
- # @note {Muzak::PLUGIN_EVENTS} contains all valid events.
60
+ # @note {Config::PLUGIN_EVENTS} contains all valid events.
61
61
  def event(type, *args)
62
- return unless PLUGIN_EVENTS.include?(type)
62
+ return unless Config::PLUGIN_EVENTS.include?(type)
63
63
 
64
64
  plugins.each do |plugin|
65
65
  Thread.new do
@@ -1,4 +1,5 @@
1
1
  module Muzak
2
+ # Represents a sequential list of songs for muzak.
2
3
  class Playlist
3
4
  # @return [String] the absolute path to the playlist on disk
4
5
  attr_accessor :filename
@@ -9,7 +10,7 @@ module Muzak
9
10
  # @param pname [String] the playlist's name
10
11
  # @return [String] the absolute path to the given playlist name
11
12
  def self.path_for(pname)
12
- File.join(PLAYLIST_DIR, pname) + ".yml"
13
+ File.join(Config::PLAYLIST_DIR, pname) + ".yml"
13
14
  end
14
15
 
15
16
  # @param pname [String] the playlist's name
@@ -29,7 +30,7 @@ module Muzak
29
30
 
30
31
  # @return [Array<String>] the names of all currently available playlists
31
32
  def self.playlist_names
32
- Dir.entries(PLAYLIST_DIR).reject do |ent|
33
+ Dir.entries(Config::PLAYLIST_DIR).reject do |ent|
33
34
  ent.start_with?(".")
34
35
  end.map do |ent|
35
36
  File.basename(ent, File.extname(ent))
@@ -8,7 +8,7 @@ module Muzak
8
8
  # The namespace for muzak plugins.
9
9
  module Plugin
10
10
  # load plugins included by the user
11
- Dir.glob(File.join(USER_PLUGIN_DIR, "*")) { |file| require file }
11
+ Dir.glob(File.join(Config::USER_PLUGIN_DIR, "*")) { |file| require file }
12
12
 
13
13
  # @return [Array<Class>] all plugin classes visible under Plugin
14
14
  def self.plugin_classes
@@ -14,7 +14,7 @@ module Muzak
14
14
  debug "loading #{self.class}"
15
15
  end
16
16
 
17
- PLUGIN_EVENTS.each do |event|
17
+ Config::PLUGIN_EVENTS.each do |event|
18
18
  define_method(event) do |*args|
19
19
  nil # do nothing.
20
20
  end
@@ -1,36 +1,18 @@
1
1
  module Muzak
2
2
  # A collection of convenience utilities for use throughout muzak.
3
3
  module Utils
4
- # Convert the given command into a method (kebab to camel case).
5
- # @param cmd [String] the command to convert
6
- # @return [String] the method corresponding to the command
7
- # @example
8
- # resolve_command "do-something" # => "do_something"
9
- def self.resolve_command(cmd)
10
- cmd.tr "-", "_"
11
- end
12
-
13
- # Convert the given method into a command (camel to kebab case).
14
- # @param meth [String, Symbol] the method to convert
15
- # @return [String] the command corresponding to the method
16
- # @example
17
- # resolve_method "do_something" # => "do-something"
18
- def self.resolve_method(meth)
19
- meth.to_s.tr "_", "-"
20
- end
21
-
22
4
  # Tests whether the given filename is likely to be music.
23
5
  # @param filename [String] the filename to test
24
6
  # @return [Boolean] whether or not the file is a music file
25
7
  def self.music?(filename)
26
- [".mp3", ".flac", ".m4a", ".wav", ".ogg", ".oga", ".opus"].include?(File.extname(filename.downcase))
8
+ Config::MUSIC_SUFFIXES.include?(File.extname(filename.downcase))
27
9
  end
28
10
 
29
11
  # Tests whether the given filename is likely to be album art.
30
12
  # @param filename [String] the filename to test
31
13
  # @return [Boolean] whether or not the file is an art file
32
14
  def self.album_art?(filename)
33
- File.basename(filename) =~ /(cover)|(folder).(jpg)|(png)/i
15
+ File.basename(filename) =~ Config::ALBUM_ART_REGEX
34
16
  end
35
17
 
36
18
  # Tests whether the given utility is available in the system path.
@@ -80,7 +62,7 @@ module Muzak
80
62
  # Outputs a boxed warning message.
81
63
  # @param args [Array<String>] the message(s)
82
64
  # @return [void]
83
- def warn(*args)
65
+ def danger(*args)
84
66
  output pretty(:yellow, "warn"), args
85
67
  end
86
68
 
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.7
4
+ version: 0.3.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-20 00:00:00.000000000 Z
11
+ date: 2017-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: taglib-ruby
@@ -72,7 +72,6 @@ files:
72
72
  - lib/muzak/cmd/player.rb
73
73
  - lib/muzak/cmd/playlist.rb
74
74
  - lib/muzak/config.rb
75
- - lib/muzak/const.rb
76
75
  - lib/muzak/index.rb
77
76
  - lib/muzak/instance.rb
78
77
  - lib/muzak/player.rb
@@ -1,33 +0,0 @@
1
- module Muzak
2
- # Muzak's current version
3
- VERSION = "0.2.7".freeze
4
-
5
- # The root directory for all user configuration, data, etc
6
- CONFIG_DIR = File.expand_path("~/.config/muzak").freeze
7
-
8
- # Muzak's primary configuration file
9
- # @see Muzak::Config
10
- CONFIG_FILE = File.join(CONFIG_DIR, "muzak.yml").freeze
11
-
12
- # Muzak's music index
13
- INDEX_FILE = File.join(CONFIG_DIR, "index.dat").freeze
14
-
15
- # The directory for all user playlists
16
- PLAYLIST_DIR = File.join(CONFIG_DIR, "playlists").freeze
17
-
18
- # The directory for all user plugins
19
- USER_PLUGIN_DIR = File.join(CONFIG_DIR, "plugins").freeze
20
-
21
- # The directory for all user commands
22
- USER_COMMAND_DIR = File.join(CONFIG_DIR, "commands").freeze
23
-
24
- # All events currently propagated by {Muzak::Instance#event}
25
- PLUGIN_EVENTS = [
26
- :instance_started,
27
- :player_activated,
28
- :player_deactivated,
29
- :song_loaded,
30
- :song_unloaded,
31
- :playlist_enqueued
32
- ]
33
- end