muzak 0.0.9 → 0.0.10

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: 2004a69f30d2467efb106868ca1882dcc8adcd1c
4
- data.tar.gz: a2af36014644a54b49d3756ca0cf7823442dbea1
3
+ metadata.gz: fea7658ba10597fe2e70ededc6e8b33e179f200c
4
+ data.tar.gz: b320dc1ef8a2b0aa715f336290d1e66fe0771a12
5
5
  SHA512:
6
- metadata.gz: 61fff1242efdd7eccd57a999352c2a58a41cad230b7b29e65bac2cdd8560aae6494dd22078ff9cdb3129aab4b45ad4d241f3f3ae3234a3aa5cbc7fecf933f803
7
- data.tar.gz: de3071c222e36d73e08bdb7f8119552ac92828ffaa90a5d92d8709d60cb3495411e62fb6763327b1fce73f2c483d72e750cc1e9800ff2b5f2268d5c9f44584e2
6
+ metadata.gz: 91fe7be79998568bb9b3727066561eb1fd9f82ce8d0a9be4829c45b13a13d59fb2ae2bce343fd9ab87202eb72862d192c402fe89438b84cf23efb9fd1f3df8e5
7
+ data.tar.gz: 1352f596a7e5a7df41027c62600524faf2352baf7a39d48c9671647e1d01e9c80ca3cdcb6278f7e71b1fa22dd866fe10c933b6f4f394ac66eae789619a9e6e80
@@ -1,76 +1,37 @@
1
1
  module Muzak
2
2
  module Cmd
3
- def _index_available?
4
- File.file?(INDEX_FILE)
5
- end
6
-
7
- def _index_loaded?
8
- !!@index
9
- end
10
-
11
- def _index_outdated?
12
- Time.now.to_i - @index.timestamp >= Config.index_autobuild
13
- end
14
-
15
- def _index_sync
16
- debug "syncing index hash with #{INDEX_FILE}"
17
- File.open(INDEX_FILE, "w") { |io| io.write @index.hash.to_yaml }
18
- end
19
-
20
- def index_load
21
- verbose "loading index from #{INDEX_FILE}"
22
-
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
31
- end
32
-
33
3
  def index_build(*args)
34
4
  warn_arity(args, 0)
35
5
 
36
6
  verbose "building a new index, this may take a while"
37
7
 
38
- @index = Index.new(Config.music, deep: Config.deep_index)
39
- _index_sync
8
+ index.build!
40
9
  end
41
10
 
42
11
  def list_artists(*args)
43
- return unless _index_loaded?
44
-
45
12
  warn_arity(args, 0)
46
13
 
47
- puts @index.artists.join("\n")
14
+ puts index.artists.join("\n")
48
15
  end
49
16
 
50
17
  def list_albums(*args)
51
- return unless _index_loaded?
52
-
53
18
  warn_arity(args, 0)
54
19
 
55
- puts @index.album_names.join("\n")
20
+ puts index.album_names.join("\n")
56
21
  end
57
22
 
58
23
  def albums_by_artist(*args)
59
- return unless _index_loaded?
60
-
61
24
  artist = args.join(" ")
62
25
  return if artist.nil?
63
26
 
64
- puts @index.albums_by(artist).map(&:title)
27
+ puts index.albums_by(artist).map(&:title)
65
28
  end
66
29
 
67
30
  def songs_by_artist(*args)
68
- return unless _index_loaded?
69
-
70
31
  artist = args.join(" ")
71
32
  return if artist.nil?
72
33
 
73
- puts @index.songs_by(artist).map(&:title)
34
+ puts index.songs_by(artist).map(&:title)
74
35
  end
75
36
  end
76
37
  end
@@ -11,8 +11,8 @@ module Muzak
11
11
  end
12
12
 
13
13
  def quit
14
- debug "muzak is quitting..."
15
- @player.deactivate!
14
+ verbose "muzak is quitting..."
15
+ player.deactivate!
16
16
  end
17
17
  end
18
18
  end
@@ -1,54 +1,54 @@
1
1
  module Muzak
2
2
  module Cmd
3
3
  def player_activate
4
- if @player.running?
4
+ if player.running?
5
5
  warn "player is already running"
6
6
  return
7
7
  end
8
8
 
9
- @player.activate!
9
+ player.activate!
10
10
  end
11
11
 
12
12
  def player_deactivate
13
- warn "player is not running" unless @player.running?
13
+ warn "player is not running" unless player.running?
14
14
 
15
15
  # do cleanup even if the player isn't running, just in case
16
- @player.deactivate!
16
+ player.deactivate!
17
17
  end
18
18
 
19
19
  def play
20
- @player.play
20
+ player.play
21
21
  end
22
22
 
23
23
  def pause
24
- @player.pause
24
+ player.pause
25
25
  end
26
26
 
27
27
  def toggle
28
- if @player.playing?
29
- @player.pause
28
+ if player.playing?
29
+ player.pause
30
30
  else
31
- @player.play
31
+ player.play
32
32
  end
33
33
  end
34
34
 
35
35
  def next
36
- @player.next_song
36
+ player.next_song
37
37
  end
38
38
 
39
39
  def previous
40
- @player.previous_song
40
+ player.previous_song
41
41
  end
42
42
 
43
43
  def enqueue_artist(*args)
44
44
  artist = args.join(" ")
45
45
  return if artist.nil?
46
46
 
47
- albums = @index.albums_by(artist)
47
+ albums = index.albums_by(artist)
48
48
  return if albums.empty?
49
49
 
50
50
  albums.each do |album|
51
- @player.enqueue_album album
51
+ player.enqueue_album album
52
52
  end
53
53
  end
54
54
 
@@ -57,37 +57,37 @@ module Muzak
57
57
  return if album_name.nil?
58
58
 
59
59
  debug album_name
60
- album = @index.albums[album_name]
60
+ album = index.albums[album_name]
61
61
  debug album.to_s
62
62
  return if album.nil?
63
63
 
64
- @player.enqueue_album album
64
+ player.enqueue_album album
65
65
  end
66
66
 
67
67
  def jukebox(*args)
68
68
  count = args.shift || Config.jukebox_size
69
69
 
70
- songs = @index.jukebox(count.to_i)
70
+ songs = index.jukebox(count.to_i)
71
71
 
72
- songs.each { |s| @player.enqueue_song s }
72
+ songs.each { |s| player.enqueue_song s }
73
73
  end
74
74
 
75
75
  def list_queue
76
- puts @player.list_queue.map(&:title)
76
+ puts player.list_queue.map(&:title)
77
77
  end
78
78
 
79
79
  def shuffle_queue
80
- @player.shuffle_queue
80
+ player.shuffle_queue
81
81
  end
82
82
 
83
83
  def clear_queue
84
- @player.clear_queue
84
+ player.clear_queue
85
85
  end
86
86
 
87
87
  def now_playing
88
- return unless @player.playing?
88
+ return unless player.playing?
89
89
 
90
- info @player.now_playing.full_title
90
+ info player.now_playing.full_title
91
91
  end
92
92
  end
93
93
  end
@@ -1,7 +1,7 @@
1
1
  module Muzak
2
2
  module Cmd
3
3
  def _playlists_loaded?
4
- !!@playlists
4
+ !!playlists
5
5
  end
6
6
 
7
7
  def list_playlists(*args)
@@ -10,20 +10,6 @@ module Muzak
10
10
  end
11
11
  end
12
12
 
13
- def playlists_load(*args)
14
- # fail_arity(args, 1)
15
- # pname = args.shift
16
- @playlists = {}
17
- @playlists.default_proc = proc { |h, k| h[k] = Playlist.new(k) }
18
-
19
- Playlist.playlist_names.each do |pname|
20
- debug "loading playlist '#{pname}'"
21
- @playlists[pname] = Playlist.new(pname)
22
- end
23
-
24
- event :playlists_loaded, @playlist
25
- end
26
-
27
13
  def playlist_delete(*args)
28
14
  fail_arity(args, 1)
29
15
  pname = args.shift
@@ -31,7 +17,7 @@ module Muzak
31
17
  debug "deleting playist '#{pname}'"
32
18
 
33
19
  Playlist.delete!(pname)
34
- @playlist[pname] = nil
20
+ playlists[pname] = nil
35
21
  end
36
22
 
37
23
  def enqueue_playlist(*args)
@@ -39,8 +25,8 @@ module Muzak
39
25
  fail_arity(args, 1)
40
26
  pname = args.shift
41
27
 
42
- @player.enqueue_playlist(@playlists[pname])
43
- event :playlist_enqueued, @playlists[pname]
28
+ player.enqueue_playlist(playlists[pname])
29
+ event :playlist_enqueued, playlists[pname]
44
30
  end
45
31
 
46
32
  def playlist_add_album(*args)
@@ -52,10 +38,10 @@ module Muzak
52
38
  album_name = args.join(" ")
53
39
  return if album_name.nil?
54
40
 
55
- album = @index.albums[album_name]
41
+ album = index.albums[album_name]
56
42
  return if album.nil?
57
43
 
58
- @playlists[pname].add(album.songs)
44
+ playlists[pname].add(album.songs)
59
45
  end
60
46
 
61
47
  def playlist_add_artist(*args)
@@ -67,25 +53,25 @@ module Muzak
67
53
  artist = args.join(" ")
68
54
  return if artist.nil?
69
55
 
70
- @playlists[pname].add(@index.songs_by(artist))
56
+ playlists[pname].add(index.songs_by(artist))
71
57
  end
72
58
 
73
59
  def playlist_add_current(*args)
74
- return unless @player.running? && _playlists_loaded?
60
+ return unless player.running? && _playlists_loaded?
75
61
 
76
62
  pname = args.shift
77
63
  return if pname.nil?
78
64
 
79
- @playlists[pname].add @player.now_playing
65
+ playlists[pname].add player.now_playing
80
66
  end
81
67
 
82
68
  def playlist_del_current(*args)
83
- return unless @player.running? && _playlists_loaded?
69
+ return unless player.running? && _playlists_loaded?
84
70
 
85
71
  pname = args.shift
86
72
  return if pname.nil?
87
73
 
88
- @playlists[pname].delete @player.now_playing
74
+ playlists[pname].delete player.now_playing
89
75
  end
90
76
 
91
77
  def playlist_shuffle(*args)
@@ -94,7 +80,7 @@ module Muzak
94
80
  pname = args.shift
95
81
  return if pname.nil?
96
82
 
97
- @playlists[pname].shuffle!
83
+ playlists[pname].shuffle!
98
84
  end
99
85
  end
100
86
  end
@@ -1,5 +1,5 @@
1
1
  module Muzak
2
- VERSION = "0.0.9".freeze
2
+ VERSION = "0.0.10".freeze
3
3
 
4
4
  CONFIG_DIR = File.expand_path("~/.config/muzak").freeze
5
5
  CONFIG_FILE = File.join(CONFIG_DIR, "muzak.yml").freeze
@@ -12,7 +12,6 @@ module Muzak
12
12
  :player_activated,
13
13
  :player_deactivated,
14
14
  :song_loaded,
15
- :playlists_loaded,
16
15
  :playlist_enqueued
17
16
  ]
18
17
  end
@@ -1,59 +1,39 @@
1
1
  module Muzak
2
2
  class Index
3
3
  include Utils
4
- attr_accessor :hash
5
-
6
- def self.load_index(file)
7
- instance = allocate
8
- instance.hash = YAML::load_file(file)
9
-
10
- instance
11
- end
4
+ attr_accessor :tree, :deep, :hash
12
5
 
13
6
  def initialize(tree, deep: false)
14
- @hash = {
15
- "timestamp" => Time.now.to_i,
16
- "artists" => {},
17
- "deep" => deep
18
- }
19
-
20
- Dir.entries(tree).each do |artist|
21
- next unless File.directory?(File.join(tree, artist))
22
- next if artist.start_with?(".")
23
-
24
- @hash["artists"][artist] = {}
25
- @hash["artists"][artist]["albums"] = {}
26
-
27
- Dir.entries(File.join(tree, artist)).each do |album|
28
- next if album.start_with?(".")
7
+ @tree = tree
8
+ @deep = deep
29
9
 
30
- @hash["artists"][artist]["albums"][album] = {}
31
- @hash["artists"][artist]["albums"][album]["songs"] = []
32
- @hash["artists"][artist]["albums"][album]["deep-songs"] = []
10
+ if File.exist?(INDEX_FILE)
11
+ verbose "loading index from #{INDEX_FILE}"
12
+ @hash = YAML::load_file(INDEX_FILE)
13
+ return unless outdated?
14
+ end
33
15
 
34
- Dir.glob(File.join(tree, artist, album, "**")) do |file|
35
- @hash["artists"][artist]["albums"][album]["cover"] = file if album_art?(file)
16
+ build!
17
+ end
36
18
 
37
- if music?(file)
38
- @hash["artists"][artist]["albums"][album]["songs"] << file
39
- @hash["artists"][artist]["albums"][album]["deep-songs"] << Song.new(file)
40
- end
41
- end
19
+ def build!
20
+ @hash = build_index_hash!
42
21
 
43
- @hash["artists"][artist]["albums"][album]["songs"].sort!
44
- @hash["artists"][artist]["albums"][album]["deep-songs"].sort_by!(&:track)
45
- end
46
- end
22
+ File.open(INDEX_FILE, "w") { |io| io.write @hash.to_yaml }
47
23
  end
48
24
 
49
25
  def deep?
50
- !!@hash["deep"]
26
+ deep
51
27
  end
52
28
 
53
29
  def timestamp
54
30
  @hash["timestamp"]
55
31
  end
56
32
 
33
+ def outdated?
34
+ Time.now.to_i - timestamp >= Config.index_autobuild
35
+ end
36
+
57
37
  def artists
58
38
  @hash["artists"].keys
59
39
  end
@@ -103,5 +83,45 @@ module Muzak
103
83
  []
104
84
  end
105
85
  end
86
+
87
+ private
88
+
89
+ def build_index_hash!
90
+ index_hash = {
91
+ "timestamp" => Time.now.to_i,
92
+ "artists" => {},
93
+ "deep" => deep
94
+ }
95
+
96
+ Dir.entries(tree).each do |artist|
97
+ next unless File.directory?(File.join(tree, artist))
98
+ next if artist.start_with?(".")
99
+
100
+ index_hash["artists"][artist] = {}
101
+ index_hash["artists"][artist]["albums"] = {}
102
+
103
+ Dir.entries(File.join(tree, artist)).each do |album|
104
+ next if album.start_with?(".")
105
+
106
+ index_hash["artists"][artist]["albums"][album] = {}
107
+ index_hash["artists"][artist]["albums"][album]["songs"] = []
108
+ index_hash["artists"][artist]["albums"][album]["deep-songs"] = []
109
+
110
+ Dir.glob(File.join(tree, artist, album, "**")) do |file|
111
+ index_hash["artists"][artist]["albums"][album]["cover"] = file if album_art?(file)
112
+
113
+ if music?(file)
114
+ index_hash["artists"][artist]["albums"][album]["songs"] << file
115
+ index_hash["artists"][artist]["albums"][album]["deep-songs"] << Song.new(file)
116
+ end
117
+ end
118
+
119
+ index_hash["artists"][artist]["albums"][album]["songs"].sort!
120
+ index_hash["artists"][artist]["albums"][album]["deep-songs"].sort_by!(&:track)
121
+ end
122
+ end
123
+
124
+ index_hash
125
+ end
106
126
  end
107
127
  end
@@ -12,34 +12,29 @@ module Muzak
12
12
  help
13
13
  end
14
14
 
15
- attr_reader :config, :player, :index, :playlist
15
+ attr_reader :index, :player, :plugins, :playlists
16
16
 
17
17
  def initialize(opts = {})
18
18
  $debug = opts[:debug]
19
19
  $verbose = opts[:verbose]
20
20
 
21
- debug "muzak is starting..."
21
+ verbose "muzak is starting..."
22
22
 
23
- index_build unless _index_available?
24
- index_load
23
+ @index = Index.new(Config.music, deep: Config.deep_index)
25
24
 
26
25
  @player = Player::PLAYER_MAP[Config.player].new(self)
27
26
 
28
- @plugins = initialize_plugins!
27
+ @plugins = Plugin.load_plugins!
29
28
 
30
- playlists_load
31
- enqueue_playlist Config.autoplay if Config.autoplay
32
- end
29
+ @playlists = Playlist.load_playlists!
33
30
 
34
- def initialize_plugins!
35
- pks = Plugin.plugin_classes.select { |pk| Config.plugin? pk.plugin_name }
36
- pks.map { |pk| pk.new(self) }
31
+ enqueue_playlist Config.autoplay if Config.autoplay
37
32
  end
38
33
 
39
34
  def event(type, *args)
40
35
  return unless PLUGIN_EVENTS.include?(type)
41
36
 
42
- @plugins.each do |plugin|
37
+ plugins.each do |plugin|
43
38
  Thread.new do
44
39
  plugin.send(type, *args)
45
40
  end.join
@@ -22,6 +22,17 @@ module Muzak
22
22
  end
23
23
  end
24
24
 
25
+ def self.load_playlists!
26
+ playlists = {}
27
+ playlists.default_proc = proc { |h, k| h[k] = Playlist.new(k) }
28
+
29
+ playlist_names.each do |pname|
30
+ playlists[pname] = Playlist.new(pname)
31
+ end
32
+
33
+ playlists
34
+ end
35
+
25
36
  def initialize(pname)
26
37
  @filename = self.class.path_for pname
27
38
 
@@ -19,6 +19,11 @@ module Muzak
19
19
  end
20
20
  end
21
21
 
22
+ def self.load_plugins!
23
+ pks = Plugin.plugin_classes.select { |pk| Config.plugin? pk.plugin_name }
24
+ pks.map { |pk| pk.new(self) }
25
+ end
26
+
22
27
  PLUGIN_MAP = plugin_names.zip(plugin_classes).to_h.freeze
23
28
  end
24
29
  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.0.9
4
+ version: 0.0.10
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-14 00:00:00.000000000 Z
11
+ date: 2016-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: taglib-ruby
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  version: '0'
84
84
  requirements: []
85
85
  rubyforge_project:
86
- rubygems_version: 2.5.1
86
+ rubygems_version: 2.5.2
87
87
  signing_key:
88
88
  specification_version: 4
89
89
  summary: muzak - A metamusic player.