muzak 0.0.8 → 0.0.9

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: b6b8176c9db706a3a44a3bcdd0531cbf4f4bfc06
4
- data.tar.gz: cc31f821a39863d88a98e3605102e4720e091609
3
+ metadata.gz: 2004a69f30d2467efb106868ca1882dcc8adcd1c
4
+ data.tar.gz: a2af36014644a54b49d3756ca0cf7823442dbea1
5
5
  SHA512:
6
- metadata.gz: b2713fafa4ebd9f793c32a33040d021dd78aa475c283b101a141032de2865ca36423832b19432562bddc64f7699e55b489be40e8d7af4a4faad713d4eb163685
7
- data.tar.gz: 177e33819737a1e629640b721f0540cc9ff7d7f44ebce31bda4acf42d30abaf697b862d2a8afc079c392b1d4b08f79529b631a405f8d5d90a7409c08cf9c3133
6
+ metadata.gz: 61fff1242efdd7eccd57a999352c2a58a41cad230b7b29e65bac2cdd8560aae6494dd22078ff9cdb3129aab4b45ad4d241f3f3ae3234a3aa5cbc7fecf933f803
7
+ data.tar.gz: de3071c222e36d73e08bdb7f8119552ac92828ffaa90a5d92d8709d60cb3495411e62fb6763327b1fce73f2c483d72e750cc1e9800ff2b5f2268d5c9f44584e2
data/README.md CHANGED
@@ -9,7 +9,7 @@ and the state of the player.
9
9
 
10
10
  ### Screenshot
11
11
 
12
- ![screenshot](https://sr.ht/A-oS.png)
12
+ ![screenshot](https://sr.ht/V4mX.gif)
13
13
 
14
14
  ### Usage
15
15
 
@@ -8,8 +8,9 @@ def fatal(msg)
8
8
  end
9
9
 
10
10
  def dmenu(options)
11
+ dmenu = Muzak::Config.dmenu_exec || "dmenu"
11
12
  opts = options.join("\n")
12
- `printf "#{opts}" | dmenu`
13
+ `printf "#{opts}" | #{dmenu}`
13
14
  end
14
15
 
15
16
  fifo_path = File.join(Muzak::CONFIG_DIR, "muzak.fifo")
@@ -1,5 +1,6 @@
1
1
  require_relative "muzak/const"
2
2
  require_relative "muzak/utils"
3
+ require_relative "muzak/config"
3
4
  require_relative "muzak/plugin"
4
5
  require_relative "muzak/song"
5
6
  require_relative "muzak/album"
@@ -5,17 +5,9 @@ module Muzak
5
5
  # load commands included by the user
6
6
  Dir.glob(File.join(USER_COMMAND_DIR, "*")) { |file| require file }
7
7
 
8
- def self.resolve_command(cmd)
9
- cmd.tr "-", "_"
10
- end
11
-
12
- def self.resolve_method(meth)
13
- meth.to_s.tr "_", "-"
14
- end
15
-
16
8
  def self.commands
17
9
  commands = instance_methods.map(&:to_s).reject { |m| m.start_with?("_") }
18
- commands.map { |c| c.tr "_", "-" }
10
+ commands.map { |c| Utils.resolve_method c }
19
11
  end
20
12
  end
21
13
  end
@@ -2,52 +2,12 @@ require "yaml"
2
2
 
3
3
  module Muzak
4
4
  module Cmd
5
- def _config_available?
6
- File.file?(CONFIG_FILE)
7
- end
8
-
9
- def _config_loaded?
10
- !!@config
11
- end
12
-
13
- def _config_sync
14
- debug "syncing config hash with #{CONFIG_FILE}"
15
- File.open(CONFIG_FILE, "w") { |io| io.write @config.to_yaml }
16
- end
17
-
18
- def _config_init
19
- debug "creating a config file in #{CONFIG_FILE}"
20
-
21
- @config = {
22
- "music" => File.expand_path("~/music"),
23
- "player" => "mpv",
24
- "index-autobuild" => 86400,
25
- "deep-index" => false,
26
- "jukebox-size" => 100
27
- }
28
-
29
- Dir.mkdir(CONFIG_DIR) unless Dir.exist?(CONFIG_DIR)
30
- _config_sync
31
- end
32
-
33
- def _config_plugin?(name)
34
- @config.key?("plugin-#{name}")
35
- end
36
-
37
- def config_load
38
- verbose "loading config from #{CONFIG_FILE}"
39
-
40
- @config = YAML::load_file(CONFIG_FILE)
41
- end
42
-
43
5
  def config_get(*args)
44
- return unless _config_loaded?
45
-
46
6
  fail_arity(args, 1)
47
7
  key = args.shift
48
8
  return if key.nil?
49
9
 
50
- info "#{key}: #{@config[key]}"
10
+ info "#{key}: #{Config.send Utils.resolve_method(key)}"
51
11
  end
52
12
  end
53
13
  end
@@ -9,7 +9,7 @@ module Muzak
9
9
  end
10
10
 
11
11
  def _index_outdated?
12
- Time.now.to_i - @index["timestamp"] >= @config["index-autobuild"]
12
+ Time.now.to_i - @index.timestamp >= Config.index_autobuild
13
13
  end
14
14
 
15
15
  def _index_sync
@@ -22,9 +22,9 @@ module Muzak
22
22
 
23
23
  @index = Index.load_index(INDEX_FILE)
24
24
 
25
- # the order is important here, since @config["index-autobuild"]
25
+ # the order is important here, since Config.index_autobuild
26
26
  # will short-circuit if index-autobuild isn't set
27
- if @config["index-autobuild"] && _index_outdated?
27
+ if Config.index_autobuild && _index_outdated?
28
28
  verbose "rebuilding outdated index"
29
29
  index_build
30
30
  end
@@ -35,7 +35,7 @@ module Muzak
35
35
 
36
36
  verbose "building a new index, this may take a while"
37
37
 
38
- @index = Index.new(@config["music"], deep: !!@config["deep-index"])
38
+ @index = Index.new(Config.music, deep: Config.deep_index)
39
39
  _index_sync
40
40
  end
41
41
 
@@ -65,7 +65,7 @@ module Muzak
65
65
  end
66
66
 
67
67
  def jukebox(*args)
68
- count = args.shift || @config["jukebox-size"]
68
+ count = args.shift || Config.jukebox_size
69
69
 
70
70
  songs = @index.jukebox(count.to_i)
71
71
 
@@ -0,0 +1,34 @@
1
+ require "yaml"
2
+
3
+ module Muzak
4
+ class Config
5
+ if File.exist?(CONFIG_FILE)
6
+ @config = YAML::load_file(CONFIG_FILE)
7
+ else
8
+ @config = {
9
+ "music" => File.expand_path("~/music"),
10
+ "player" => "mpv",
11
+ "index-autobuild" => 86400,
12
+ "deep-index" => false,
13
+ "jukebox-size" => 100
14
+ }
15
+
16
+ File.open(CONFIG_FILE, "w") { |io| io.write @config.to_yaml }
17
+ end
18
+
19
+ @config.each do |key, value|
20
+ define_singleton_method Utils.resolve_command(key) do
21
+ value
22
+ end
23
+ end
24
+
25
+ # if a key doesn't exist, assume it's false
26
+ def self.method_missing(method, *args)
27
+ false
28
+ end
29
+
30
+ def self.plugin?(pname)
31
+ respond_to? "plugin_#{pname}"
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
1
  module Muzak
2
- VERSION = "0.0.8".freeze
2
+ VERSION = "0.0.9".freeze
3
3
 
4
4
  CONFIG_DIR = File.expand_path("~/.config/muzak").freeze
5
5
  CONFIG_FILE = File.join(CONFIG_DIR, "muzak.yml").freeze
@@ -50,6 +50,10 @@ module Muzak
50
50
  !!@hash["deep"]
51
51
  end
52
52
 
53
+ def timestamp
54
+ @hash["timestamp"]
55
+ end
56
+
53
57
  def artists
54
58
  @hash["artists"].keys
55
59
  end
@@ -4,11 +4,11 @@ module Muzak
4
4
  include Utils
5
5
 
6
6
  def command(cmd, *args)
7
- send Cmd.resolve_command(cmd), *args
7
+ send Utils.resolve_command(cmd), *args
8
8
  end
9
9
 
10
10
  def method_missing(meth, *args)
11
- warn "unknown command: #{Cmd.resolve_method(meth)}"
11
+ warn "unknown command: #{Utils.resolve_method(meth)}"
12
12
  help
13
13
  end
14
14
 
@@ -20,22 +20,19 @@ module Muzak
20
20
 
21
21
  debug "muzak is starting..."
22
22
 
23
- _config_init unless _config_available?
24
- config_load
25
-
26
23
  index_build unless _index_available?
27
24
  index_load
28
25
 
29
- @player = Player::PLAYER_MAP[@config["player"]].new(self)
26
+ @player = Player::PLAYER_MAP[Config.player].new(self)
30
27
 
31
28
  @plugins = initialize_plugins!
32
29
 
33
30
  playlists_load
34
- enqueue_playlist @config["autoplay"] if @config["autoplay"]
31
+ enqueue_playlist Config.autoplay if Config.autoplay
35
32
  end
36
33
 
37
34
  def initialize_plugins!
38
- pks = Plugin.plugin_classes.select { |pk| _config_plugin? pk.plugin_name }
35
+ pks = Plugin.plugin_classes.select { |pk| Config.plugin? pk.plugin_name }
39
36
  pks.map { |pk| pk.new(self) }
40
37
  end
41
38
 
@@ -35,7 +35,7 @@ module Muzak
35
35
  "--input-ipc-server=%{socket}" % { socket: @sock_path }
36
36
  ]
37
37
 
38
- mpv_args << "--geometry=#{instance.config["art-geometry"]}" if instance.config["art-geometry"]
38
+ mpv_args << "--geometry=#{Config.art_geometry}" if Config.art_geometry
39
39
 
40
40
  @pid = Process.spawn("mpv", *mpv_args)
41
41
 
@@ -7,7 +7,7 @@ module Muzak
7
7
 
8
8
  def initialize(instance)
9
9
  super
10
- @term_args = Shellwords.split instance.config["plugin-cava"]
10
+ @term_args = Shellwords.split Config.plugin_cava
11
11
  @pid = nil
12
12
  end
13
13
 
@@ -8,7 +8,7 @@ module Muzak
8
8
 
9
9
  def initialize(instance)
10
10
  super
11
- @username, @password_hash = instance.config["plugin-scrobble"].split(":")
11
+ @username, @password_hash = Config.plugin_scrobble.split(":")
12
12
  end
13
13
 
14
14
  def song_loaded(song)
@@ -1,5 +1,13 @@
1
1
  module Muzak
2
2
  module Utils
3
+ def self.resolve_command(cmd)
4
+ cmd.tr "-", "_"
5
+ end
6
+
7
+ def self.resolve_method(meth)
8
+ meth.to_s.tr "_", "-"
9
+ end
10
+
3
11
  def music?(filename)
4
12
  [".mp3", ".flac", ".m4a", ".wav", ".ogg", ".oga", ".opus"].include?(File.extname(filename))
5
13
  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.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff
@@ -48,6 +48,7 @@ files:
48
48
  - lib/muzak/cmd/meta.rb
49
49
  - lib/muzak/cmd/player.rb
50
50
  - lib/muzak/cmd/playlist.rb
51
+ - lib/muzak/config.rb
51
52
  - lib/muzak/const.rb
52
53
  - lib/muzak/index.rb
53
54
  - lib/muzak/instance.rb