muzak 0.0.12 → 0.0.13

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: cdbf4e0b472fdf7499bbd25915c178c00ea427f2
4
- data.tar.gz: e0b39265673163d195dde538960beb7819e2ebbe
3
+ metadata.gz: b6895336a3fa06db40e63f71d227e36b11a18397
4
+ data.tar.gz: 32f2ad6998993b76b783d9e97d8d91db55db1be0
5
5
  SHA512:
6
- metadata.gz: 18ae7d00640668f375390afc84d2ec0aec1fde26970d9e1636c943a7a29415267b97cf5c433efc2967ad630726525f617493a77e30cc2072646af95406078de1
7
- data.tar.gz: 51f3a12b1e2018fb52c118cbd79afdc47a22a9a0a7feaf724960baffc9604b77042aafd60d3b0e7117e8b37bd9c12475c0653ffc71befc722c43c3289229b5f6
6
+ metadata.gz: bea81c7b13e504c158e9fb6d01beb3431d56b48c578b3f0c659dd059adad4c6cd87d1e3e975c58bf8be6fe1e412dad6508846cb5a98b603fa96a9948a3f0a4ed
7
+ data.tar.gz: 692b0d3ba74454f6c7669156f4cf472932c930bcb29e59399149371db188eaf01442062bd7a8be31af854bbc06f2636d2694505ab46edb1e9848c6e4ed7f78cb
@@ -16,7 +16,7 @@ module Muzak
16
16
  @title = title
17
17
  @cover_art = album_hash["cover"]
18
18
 
19
- if album_hash["deep-songs"]
19
+ unless album_hash["deep-songs"].empty?
20
20
  @songs = album_hash["deep-songs"]
21
21
  else
22
22
  @songs = album_hash["songs"].map { |s| Song.new(s) }
@@ -85,9 +85,7 @@ module Muzak
85
85
  album_name = args.join(" ")
86
86
  return if album_name.nil?
87
87
 
88
- debug album_name
89
88
  album = index.albums[album_name]
90
- debug album.to_s
91
89
  return if album.nil?
92
90
 
93
91
  player.enqueue_album album
@@ -1,4 +1,5 @@
1
1
  require "yaml"
2
+ require "fileutils"
2
3
 
3
4
  module Muzak
4
5
  # Muzak's static configuration dumping ground.
@@ -13,7 +14,7 @@ module Muzak
13
14
  else
14
15
  @config = {
15
16
  "debug" => false,
16
- "verbose" => false,
17
+ "verbose" => true,
17
18
  "music" => File.expand_path("~/music"),
18
19
  "player" => "mpv",
19
20
  "index-autobuild" => 86400,
@@ -21,12 +22,21 @@ module Muzak
21
22
  "jukebox-size" => 100
22
23
  }
23
24
 
24
- File.open(CONFIG_FILE, "w") { |io| io.write @config.to_yaml }
25
+ [CONFIG_DIR, PLAYLIST_DIR, USER_PLUGIN_DIR, USER_COMMAND_DIR].each do |d|
26
+ FileUtils.mkdir_p d
27
+ end
28
+
29
+ sync!
25
30
  end
26
31
 
27
- @config.each do |key, value|
32
+ @config.each do |key, _|
28
33
  define_singleton_method Utils.resolve_command(key) do
29
- value
34
+ @config[key]
35
+ end
36
+
37
+ define_singleton_method "#{Utils.resolve_command(key)}=" do |value|
38
+ @config[key] = value
39
+ sync!
30
40
  end
31
41
  end
32
42
 
@@ -36,6 +46,10 @@ module Muzak
36
46
  false
37
47
  end
38
48
 
49
+ def self.sync!
50
+ File.open(CONFIG_FILE, "w") { |io| io.write @config.to_yaml }
51
+ end
52
+
39
53
  # @return [Boolean] whether or not the given plugin is configured
40
54
  # @note the truth-value of this method is used to determine which
41
55
  # plugins should be loaded.
@@ -1,6 +1,6 @@
1
1
  module Muzak
2
2
  # Muzak's current version
3
- VERSION = "0.0.12".freeze
3
+ VERSION = "0.0.13".freeze
4
4
 
5
5
  # The root directory for all user configuration, data, etc
6
6
  CONFIG_DIR = File.expand_path("~/.config/muzak").freeze
@@ -3,6 +3,10 @@ module Muzak
3
3
  class Index
4
4
  include Utils
5
5
 
6
+ def self.load_index!
7
+ Index.new(Config.music, deep: Config.deep_index)
8
+ end
9
+
6
10
  # @return [String] the path of the root of the music tree
7
11
  attr_accessor :tree
8
12
 
@@ -54,6 +58,7 @@ module Muzak
54
58
  # @note The behavior of this method is affected by the value of
55
59
  # {Muzak::Config.index_autobuild}.
56
60
  def outdated?
61
+ return false unless Config.index_autobuild
57
62
  Time.now.to_i - timestamp >= Config.index_autobuild
58
63
  end
59
64
 
@@ -155,12 +160,22 @@ module Muzak
155
160
 
156
161
  if music?(file)
157
162
  index_hash["artists"][artist]["albums"][album]["songs"] << file
158
- index_hash["artists"][artist]["albums"][album]["deep-songs"] << Song.new(file)
163
+ if deep?
164
+ index_hash["artists"][artist]["albums"][album]["deep-songs"] << Song.new(file)
165
+ end
159
166
  end
160
167
  end
161
168
 
162
169
  index_hash["artists"][artist]["albums"][album]["songs"].sort!
163
- index_hash["artists"][artist]["albums"][album]["deep-songs"].sort_by!(&:track)
170
+
171
+ # if any of the track numbers in the album are > 0 (the fallback),
172
+ # sort by ID3 track numbers. otherwise, hope that the song
173
+ # paths contain track numbers (e.g, "01 song.mp3").
174
+ if index_hash["artists"][artist]["albums"][album]["deep-songs"].any? { |s| s.track > 0 }
175
+ index_hash["artists"][artist]["albums"][album]["deep-songs"].sort_by!(&:track)
176
+ else
177
+ index_hash["artists"][artist]["albums"][album]["deep-songs"].sort_by!(&:path)
178
+ end
164
179
  end
165
180
  end
166
181
 
@@ -34,7 +34,9 @@ module Muzak
34
34
  def initialize(opts = {})
35
35
  verbose "muzak is starting..."
36
36
 
37
- @index = Index.new(Config.music, deep: Config.deep_index)
37
+ error! "#{Config.music} doesn't exist" unless File.exist?(Config.music)
38
+
39
+ @index = Index.load_index!
38
40
 
39
41
  @player = Player.load_player!(self)
40
42
 
@@ -89,6 +89,14 @@ module Muzak
89
89
  output pretty(:red, "error"), "[#{self.class.name}]", args
90
90
  end
91
91
 
92
+ # Outputs a boxed error message and then exits.
93
+ # @param args [Array<String>] the message(s)
94
+ # @return [void]
95
+ def error!(*args)
96
+ error *args
97
+ exit 1
98
+ end
99
+
92
100
  # Outputs a boxed debugging message.
93
101
  # @param args [Array<String>] the message(s)
94
102
  # @return [void]
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.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-21 00:00:00.000000000 Z
11
+ date: 2016-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: taglib-ruby