muzak 0.3.8 → 0.3.9

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: 3338e70c6fa7dc2320227d38b13c944e7041f6a1
4
- data.tar.gz: 38ba81685e38e29ad8bb4ce55897d2aa12d30d98
3
+ metadata.gz: c8e7f564cf871bb52f85bee9f9ce174955f5cb8b
4
+ data.tar.gz: 34f79d424c5d0ff80141d5b7469bbec26a8f2490
5
5
  SHA512:
6
- metadata.gz: ccbf8b59dc56189f0805e8c382f54a91d6a2e646802d2e920402e7a1387622832446415419ca22f73547bca00fe43a3bf41cead6de8feb832df678114f3790b8
7
- data.tar.gz: fb3b416d63a3ea9517b488881d5f94301d2ce9958ff8b00a1fb7dde8e2b5c93a6b1d19f4a6b4d6acad5cef2fc3463fb738395f8c64ab0367962052c6d30c92e8
6
+ metadata.gz: 117f0feb185eed6a940db827d565580a4e274bfe30bc448c7ad54c0aaca8e088b349947be63c6aa3b140ec3366dda053aa525d467ea3245a1557ac5968c2bad5
7
+ data.tar.gz: 65c7640651c2bba52a89499db61da01819911d625ecddf480831cd01db6bdfdc6104467b73c33669c562ddafa466a282511cc01de173dca69670f9f68d1696b4
@@ -938,6 +938,39 @@ $ muzak-cmd quit
938
938
  }
939
939
  ```
940
940
 
941
+ ## `reload-index`
942
+
943
+ Reloads muzak's in-memory index.
944
+
945
+ **Note:** This does *not* rebuild the index file - `muzak-index` is provided
946
+ as a command line utility for that.
947
+
948
+ ### Syntax
949
+
950
+ `reload-index`
951
+
952
+ ### Example
953
+
954
+ ```bash
955
+ $ muzak-cmd reload-index
956
+ ```
957
+
958
+ ### Example Response
959
+
960
+ ```json
961
+ {
962
+ "response" : {
963
+ "error" : null,
964
+ "data" : {
965
+ "artist_count" : 262,
966
+ "album_count" : 1161,
967
+ "deep" : true
968
+ },
969
+ "method" : "reload_index"
970
+ }
971
+ }
972
+ ```
973
+
941
974
  ## `shuffle-queue`
942
975
 
943
976
  Shuffles the player's playback queue.
data/bin/muzakd CHANGED
@@ -7,7 +7,6 @@ require "json"
7
7
  require "thread"
8
8
 
9
9
  Process.daemon unless Muzak::Config.debug || Muzak::Config.verbose
10
- Thread.abort_on_exception = Muzak::Config.debug
11
10
 
12
11
  muzak = Muzak::Instance.new
13
12
 
@@ -12,5 +12,5 @@ require_relative "muzak/instance"
12
12
  # The primary namespace for muzak.
13
13
  module Muzak
14
14
  # Muzak's current version
15
- VERSION = "0.3.8".freeze
15
+ VERSION = "0.3.9".freeze
16
16
  end
@@ -1,5 +1,19 @@
1
1
  module Muzak
2
2
  module Cmd
3
+ # Reload the active index from the index file.
4
+ # @note This does *not* rebuild the index.
5
+ # @command `reload-index`
6
+ # @cmdexample `muzak> reload-index`
7
+ def reload_index
8
+ index.reload!
9
+
10
+ build_response data: {
11
+ artist_count: index.artists.size,
12
+ album_count: index.albums.size,
13
+ deep: index.deep?,
14
+ }
15
+ end
16
+
3
17
  # List all artists in the index.
4
18
  # @command `list-artists`
5
19
  # @cmdexample `muzak> list-artists`
@@ -94,7 +94,7 @@ module Muzak
94
94
  end
95
95
 
96
96
  # @return [Boolean] whether or not the given plugin is configured
97
- # @note the truth-value of this method is used to determine which
97
+ # @note the truth-value of this method is used in part to determine which
98
98
  # plugins should be loaded.
99
99
  def self.plugin?(pname)
100
100
  respond_to? "plugin_#{pname}"
@@ -12,6 +12,9 @@ module Muzak
12
12
  end
13
13
  end
14
14
 
15
+ # @return [String] the path of the index data file
16
+ attr_accessor :file
17
+
15
18
  # @return [String] the path of the root of the music tree
16
19
  attr_accessor :tree
17
20
 
@@ -20,18 +23,22 @@ module Muzak
20
23
 
21
24
  # @param file [String] the path of the index data file
22
25
  def initialize(file: Config::INDEX_FILE)
23
- debug "loading index from '#{Config::INDEX_FILE}'..."
26
+ debug "loading index from '#{file}'..."
27
+
28
+ @file = file
24
29
 
25
30
  @hash = Marshal.load(File.read file)
26
31
 
27
- # create some frequently accessed collections
28
- @all_albums = @hash["artists"].map { |_, a| a["albums"] }.flatten
32
+ memoize_collections!
33
+ end
29
34
 
30
- if deep?
31
- @all_deep_songs = @all_albums.map { |aa| aa.map { |_, a| a["deep-songs"] } }.flatten
32
- else
33
- @all_songs = @all_albums.map { |aa| aa.map { |_, a| a["songs"] } }.flatten
34
- end
35
+ # Refresh the {Index} instance's state from the index data file.
36
+ # @note This method does *not* rebuild the index data file.
37
+ # @return [void]
38
+ def reload!
39
+ debug "reloading index from '#{file}'..."
40
+ @hash = Marshal.load(File.read file)
41
+ memoize_collections!
35
42
  end
36
43
 
37
44
  # @return [Boolean] whether or not the current index is deep
@@ -132,5 +139,18 @@ module Muzak
132
139
  []
133
140
  end
134
141
  end
142
+
143
+ # Create some frequently accessed collections to speed things up a bit.
144
+ # @return [void]
145
+ # @api private
146
+ def memoize_collections!
147
+ @all_albums = @hash["artists"].map { |_, a| a["albums"] }.flatten
148
+
149
+ if deep?
150
+ @all_deep_songs = @all_albums.map { |aa| aa.map { |_, a| a["deep-songs"] } }.flatten
151
+ else
152
+ @all_songs = @all_albums.map { |aa| aa.map { |_, a| a["songs"] } }.flatten
153
+ end
154
+ end
135
155
  end
136
156
  end
@@ -64,12 +64,10 @@ module Muzak
64
64
  return unless Config::PLUGIN_EVENTS.include?(type)
65
65
 
66
66
  plugins.each do |plugin|
67
- Thread.new do
68
- begin
69
- plugin.send(type, *args)
70
- rescue => e
71
- error "something went wrong in #{plugin.class.plugin_name}: #{e}"
72
- end
67
+ begin
68
+ Thread.new { plugin.send(type, *args) }
69
+ rescue => e
70
+ error "something went wrong in #{plugin.class.plugin_name}: #{e}"
73
71
  end
74
72
  end
75
73
  end
@@ -26,7 +26,10 @@ module Muzak
26
26
  # Instantiates all configured plugins and returns them.
27
27
  # @return [Array<StubPlugin>] the instantiated plugins
28
28
  def self.load_plugins!
29
- pks = PLUGIN_CLASSES.select { |pk| Config.plugin? pk.plugin_name }
29
+ pks = PLUGIN_CLASSES.select do |pk|
30
+ Config.plugin?(pk.plugin_name) && pk.available?
31
+ end
32
+
30
33
  pks.map { |pk| pk.new }
31
34
  end
32
35
  end
@@ -12,6 +12,11 @@ module Muzak
12
12
  name.split("::").last.downcase
13
13
  end
14
14
 
15
+ # @return [true] whether or not this plugin is available
16
+ def self.available?
17
+ true
18
+ end
19
+
15
20
  def initialize
16
21
  debug "loading #{self.class}"
17
22
  end
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.3.8
4
+ version: 0.3.9
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-02-20 00:00:00.000000000 Z
11
+ date: 2017-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: taglib-ruby