muzak 0.0.1 → 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a171d18242a3650ec6a70d1cedb0bb9e156229c
4
- data.tar.gz: 5e5552a3b45cd2ced07e1ff2a79508bd8820dcd6
3
+ metadata.gz: 8e876cf1c3b780e3df5a034b8bd0b39929d29488
4
+ data.tar.gz: a07901cc1392f0da1a57b5dee944dc3c79cbc800
5
5
  SHA512:
6
- metadata.gz: b02efb2b8ef6f3d2811cf469267c4e4f183459267c8027794a76ce04a2a08738b588ecfbeef8b091aa737b66b6dcea7a7fceadf348a2ae35747c13bb7b0cab50
7
- data.tar.gz: b49dea00fefd160228bedc48e5b133b46ce781e5630052068f4f2d632db6c73f35201075173bdf873027821b2dd4e107e74df219834b01ae7027b056909b053f
6
+ metadata.gz: addec21a1b711fef4737b67a709b042bb9e5418414a9a540b8f28de953294b6758d0cb2fa25d71c65cc037e5fb67e9abe94581167c57cd702e7a16f7f7b18a32
7
+ data.tar.gz: 65d2e9edd5c2698f243bf92ff6d5b79ef6d963b4b4ef898dbc923a0f3fe092ab140740d307f7beddb8ae6e6bdc8be598d6f2ac3dd0c3aad0f0fa052a2a546221
data/bin/muzak CHANGED
@@ -7,7 +7,6 @@ require "shellwords"
7
7
  opts = {
8
8
  debug: ARGV.include?("--debug") || ARGV.include?("-d"),
9
9
  verbose: ARGV.include?("--verbose") || ARGV.include?("-v"),
10
- batch: ARGV.include?("--batch") || ARGV.include?("-b")
11
10
  }
12
11
 
13
12
  Thread.abort_on_exception = opts[:debug]
data/bin/muzakd CHANGED
@@ -6,7 +6,6 @@ require "shellwords"
6
6
  opts = {
7
7
  debug: ARGV.include?("--debug") || ARGV.include?("-d"),
8
8
  verbose: ARGV.include?("--verbose") || ARGV.include?("-v"),
9
- batch: ARGV.include?("--batch") || ARGV.include?("-b")
10
9
  }
11
10
 
12
11
  Process.daemon unless opts[:debug] || opts[:verbose]
@@ -21,6 +21,7 @@ module Muzak
21
21
  @config = {
22
22
  "music" => File.expand_path("~/music"),
23
23
  "player" => "mpv",
24
+ "index-autobuild" => 86400
24
25
  }
25
26
 
26
27
  Dir.mkdir(CONFIG_DIR) unless Dir.exist?(CONFIG_DIR)
@@ -37,32 +38,6 @@ module Muzak
37
38
  @config = YAML::load_file(CONFIG_FILE)
38
39
  end
39
40
 
40
- def config_set(*args)
41
- return unless _config_loaded?
42
-
43
- fail_arity(args, 2)
44
- key, value = args
45
- return if key.nil? || value.nil?
46
-
47
- debug "setting '#{key}' to '#{value}' in config"
48
-
49
- @config[key] = value
50
- _config_sync
51
- end
52
-
53
- def config_del(*args)
54
- return unless _config_loaded?
55
-
56
- fail_arity(args, 1)
57
- key = args.shift
58
- return if key.nil?
59
-
60
- debug "removing '#{key}' from config"
61
-
62
- @config.delete(key)
63
- _config_sync
64
- end
65
-
66
41
  def config_get(*args)
67
42
  return unless _config_loaded?
68
43
 
@@ -8,6 +8,10 @@ module Muzak
8
8
  !!@index
9
9
  end
10
10
 
11
+ def _index_outdated?
12
+ Time.now.to_i - @index["timestamp"] >= @config["index-autobuild"]
13
+ end
14
+
11
15
  def _index_sync
12
16
  debug "syncing index hash with #{INDEX_FILE}"
13
17
  File.open(INDEX_FILE, "w") { |io| io.write @index.hash.to_yaml }
@@ -17,6 +21,13 @@ module Muzak
17
21
  debug "loading index from #{INDEX_FILE}"
18
22
 
19
23
  @index = Index.load_index(INDEX_FILE)
24
+
25
+ # the order is important here, since @config["index-autobuild"]
26
+ # will short-circuit if index-autobuild isn't set
27
+ if @config["index-autobuild"] && _index_outdated?
28
+ verbose "rebuilding outdated index"
29
+ index_build
30
+ end
20
31
  end
21
32
 
22
33
  def index_build(*args)
@@ -30,6 +30,8 @@ module Muzak
30
30
  @playlist = Playlist.new(pname, [])
31
31
  playlist_sync
32
32
  end
33
+
34
+ event :playlist_loaded, @playlist
33
35
  end
34
36
 
35
37
  def playlist_delete(*args)
@@ -56,6 +58,7 @@ module Muzak
56
58
  return unless _playlist_loaded?
57
59
 
58
60
  @player.enqueue_playlist(@playlist)
61
+ event :playlist_enqueued, @playlist
59
62
  end
60
63
 
61
64
  def playlist_add_album(*args)
@@ -1,14 +1,17 @@
1
1
  module Muzak
2
- VERSION = "0.0.1".freeze
2
+ VERSION = "0.0.2".freeze
3
3
 
4
4
  CONFIG_DIR = File.expand_path("~/.config/muzak").freeze
5
5
  CONFIG_FILE = File.join(CONFIG_DIR, "muzak.yml").freeze
6
6
  INDEX_FILE = File.join(CONFIG_DIR, "index.yml").freeze
7
7
  PLAYLIST_DIR = File.join(CONFIG_DIR, "playlists").freeze
8
+ USER_PLUGIN_DIR = File.join(CONFIG_DIR, "plugins").freeze
8
9
 
9
10
  PLUGIN_EVENTS = [
10
11
  :player_activated,
11
12
  :player_deactivated,
12
- :song_loaded
13
+ :song_loaded,
14
+ :playlist_loaded,
15
+ :playlist_enqueued
13
16
  ]
14
17
  end
@@ -24,9 +24,9 @@ module Muzak
24
24
 
25
25
  @player = Player::PLAYER_MAP[@config["player"]].new(self)
26
26
 
27
- playlist_load @config["default-playlist"] if @config["default-playlist"]
28
-
29
27
  @plugins = initialize_plugins!
28
+
29
+ playlist_load @config["default-playlist"] if @config["default-playlist"]
30
30
  end
31
31
 
32
32
  def initialize_plugins!
@@ -1,10 +1,14 @@
1
1
  # we have to require StubPlugin first because ruby's module resolution is bad
2
2
  require_relative "plugin/stub_plugin"
3
3
 
4
+ # load plugins included with muzak
4
5
  Dir.glob(File.join(__dir__, "plugin/*")) { |file| require_relative file }
5
6
 
6
7
  module Muzak
7
8
  module Plugin
9
+ # load plugins included by the user
10
+ Dir.glob(File.join(USER_PLUGIN_DIR, "*")) { |file| require file }
11
+
8
12
  def self.plugin_classes
9
13
  constants.map(&Plugin.method(:const_get)).grep(Class)
10
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muzak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff