muzak 0.0.6 → 0.0.7

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: 66effe9b1b141471424f8fb07923b88ecf87da80
4
- data.tar.gz: a79283a7dd22bbb754ba3a7ed5b9db7ba32aa99b
3
+ metadata.gz: 9a2a198cce10bc3f66a9c3c532433f30c4264b30
4
+ data.tar.gz: 2e021ffbcbc1d2b16696f010690389c1854b5890
5
5
  SHA512:
6
- metadata.gz: 80990917d255f3dc96570cf9389ed1238701382b9c096ceac2de8ee6cfce606b90808ebe253ce1764dda18b880eed4b05c11b75d244008ff855f20643c22fca9
7
- data.tar.gz: 4f1bf3964aef17d1a060590162bf5ca16cfcef1f733423c20116e7b3b972bb7df363d12f38b0ada0cb31286ba49c0933823d98de704c9f845e8def882bbdfba2
6
+ metadata.gz: 6fe05e1fb8c85576a9b270144447f45e6c03d7b499f6569290f42c047a878d58c637ae36b8adcad3c8176c048136670ecf1079c6ccc4fa0dd2b09e67c77f17e2
7
+ data.tar.gz: cb384c8a927cd5ef336f6eb113c115d7a1d5a7f6e1adf66c16de2fe1559b056192b51d7f63f23478a01ffcf55b9cc67a57cb05981b272b2564906a71cabaadff
data/bin/muzak CHANGED
@@ -45,5 +45,7 @@ trap("INT", "SIG_IGN")
45
45
  while line = Readline.readline("muzak> ", true)
46
46
  cmd_argv = Shellwords.split(line) rescue next
47
47
  next if cmd_argv.empty? || cmd_argv.any?(&:empty?)
48
- muzak.command cmd_argv.shift, *cmd_argv
48
+ cmd = cmd_argv.shift
49
+ muzak.command cmd, *cmd_argv
50
+ break if cmd == "quit"
49
51
  end
data/bin/muzakd CHANGED
@@ -17,15 +17,14 @@ fifo_path = File.join(Muzak::CONFIG_DIR, "muzak.fifo")
17
17
  File.delete(fifo_path) if File.exist?(fifo_path) # just in case a previous session died
18
18
  File.mkfifo(fifo_path)
19
19
 
20
- File.open(fifo_path, "r") do |fifo|
20
+ File.open(fifo_path, "r+") do |fifo|
21
21
  loop do
22
22
  cmd_argv = Shellwords.split(fifo.readline) rescue next
23
23
  next if cmd_argv.empty? || cmd_argv.any?(&:empty?)
24
- muzak.command cmd_argv.shift, *cmd_argv
24
+ cmd = cmd_argv.shift
25
+ muzak.command cmd, *cmd_argv
26
+ break if cmd == "quit"
25
27
  end
26
28
  end
27
29
 
28
- # there is definitely a cleaner way to do this.
29
- at_exit do
30
- File.delete(fifo_path) if File.exist?(fifo_path)
31
- end
30
+ File.delete(fifo_path) if File.exist?(fifo_path)
@@ -22,7 +22,8 @@ module Muzak
22
22
  "music" => File.expand_path("~/music"),
23
23
  "player" => "mpv",
24
24
  "index-autobuild" => 86400,
25
- "deep-index" => false
25
+ "deep-index" => false,
26
+ "jukebox-size" => 100
26
27
  }
27
28
 
28
29
  Dir.mkdir(CONFIG_DIR) unless Dir.exist?(CONFIG_DIR)
@@ -13,7 +13,6 @@ module Muzak
13
13
  def quit
14
14
  debug "muzak is quitting..."
15
15
  @player.deactivate!
16
- exit
17
16
  end
18
17
  end
19
18
  end
@@ -1,18 +1,10 @@
1
1
  module Muzak
2
2
  module Cmd
3
- def _playlist_file(pname)
4
- File.join(PLAYLIST_DIR, pname) + ".yml"
5
- end
6
-
7
- def _playlist_available?(pname)
8
- File.exist?(_playlist_file(pname))
9
- end
10
-
11
3
  def _playlist_loaded?
12
4
  !!@playlist
13
5
  end
14
6
 
15
- def list_playlists
7
+ def list_playlists(*args)
16
8
  Playlist.playlist_names.each do |playlist|
17
9
  info playlist
18
10
  end
@@ -22,14 +14,8 @@ module Muzak
22
14
  fail_arity(args, 1)
23
15
  pname = args.shift
24
16
 
25
- if _playlist_available?(pname)
26
- info "loading playlist '#{pname}'"
27
- @playlist = Playlist.load_playlist(_playlist_file(pname))
28
- else
29
- info "creating playlist '#{pname}'"
30
- @playlist = Playlist.new(pname, [])
31
- playlist_sync
32
- end
17
+ info "loading playlist '#{pname}'"
18
+ @playlist = Playlist.new(pname)
33
19
 
34
20
  event :playlist_loaded, @playlist
35
21
  end
@@ -40,21 +26,11 @@ module Muzak
40
26
 
41
27
  debug "deleting playist '#{pname}'"
42
28
 
43
- File.delete(_playlist_file(pname)) if _playlist_available?(pname)
29
+ Playlist.delete!(pname)
44
30
  @playlist = nil
45
31
  end
46
32
 
47
- def playlist_sync(*args)
48
- return unless _playlist_loaded?
49
- fail_arity(args, 0)
50
-
51
- debug "syncing playlist '#{@playlist.name}'"
52
-
53
- Dir.mkdir(PLAYLIST_DIR) unless Dir.exist?(PLAYLIST_DIR)
54
- File.open(_playlist_file(@playlist.name), "w") { |io| io.write @playlist.to_hash.to_yaml }
55
- end
56
-
57
- def enqueue_playlist
33
+ def enqueue_playlist(*args)
58
34
  return unless _playlist_loaded?
59
35
 
60
36
  @player.enqueue_playlist(@playlist)
@@ -70,33 +46,34 @@ module Muzak
70
46
  album = @index.albums[album_name]
71
47
  return if album.nil?
72
48
 
73
- album.songs.each { |song| @playlist.add song }
49
+ @playlist.add(album.songs)
50
+ end
51
+
52
+ def playlist_add_artist(*args)
53
+ return unless _playlist_loaded?
54
+
55
+ artist = args.join(" ")
56
+ return if artist.nil?
74
57
 
75
- playlist_sync
58
+ @playlist.add(@index.songs_by(artist))
76
59
  end
77
60
 
78
- def playlist_add_current
61
+ def playlist_add_current(*args)
79
62
  return unless @player.running? && _playlist_loaded?
80
63
 
81
64
  @playlist.add @player.now_playing
82
-
83
- playlist_sync
84
65
  end
85
66
 
86
- def playlist_del_current
67
+ def playlist_del_current(*args)
87
68
  return unless @player.running? && _playlist_loaded?
88
69
 
89
- @playlist.delete(@player.now_playing)
90
-
91
- playlist_sync
70
+ @playlist.delete @player.now_playing
92
71
  end
93
72
 
94
- def playlist_shuffle
73
+ def playlist_shuffle(*args)
95
74
  return unless _playlist_loaded?
96
75
 
97
76
  @playlist.shuffle!
98
-
99
- playlist_sync
100
77
  end
101
78
  end
102
79
  end
@@ -1,5 +1,5 @@
1
1
  module Muzak
2
- VERSION = "0.0.6".freeze
2
+ VERSION = "0.0.7".freeze
3
3
 
4
4
  CONFIG_DIR = File.expand_path("~/.config/muzak").freeze
5
5
  CONFIG_FILE = File.join(CONFIG_DIR, "muzak.yml").freeze
@@ -22,6 +22,10 @@ module Muzak
22
22
  @sock_path = Dir::Tmpname.make_tmpname("/tmp/mpv", ".sock")
23
23
  mpv_args = [
24
24
  "--idle",
25
+ # if i get around to separating album art from playback,
26
+ # these two flags disable mpv's video output entirely
27
+ # "--no-force-window",
28
+ # "--no-video",
25
29
  "--no-osc",
26
30
  "--no-osd-bar",
27
31
  "--no-input-default-bindings",
@@ -151,7 +155,7 @@ module Muzak
151
155
 
152
156
  def load_song(song, art)
153
157
  cmds = ["loadfile", song.path, "append-play"]
154
- cmds << "external-file=#{art}" if art
158
+ cmds << "external-file=\"#{art}\"" if art
155
159
  command *cmds
156
160
  end
157
161
 
@@ -1,6 +1,18 @@
1
1
  module Muzak
2
2
  class Playlist
3
- attr_accessor :name, :songs
3
+ attr_accessor :filename, :songs
4
+
5
+ def self.path_for(pname)
6
+ File.join(PLAYLIST_DIR, pname) + ".yml"
7
+ end
8
+
9
+ def self.exist?(pname)
10
+ File.exist?(path_for(pname))
11
+ end
12
+
13
+ def self.delete!(pname)
14
+ File.delete(path_for(pname)) if exist? pname
15
+ end
4
16
 
5
17
  def self.playlist_names
6
18
  Dir.entries(PLAYLIST_DIR).reject do |ent|
@@ -10,36 +22,47 @@ module Muzak
10
22
  end
11
23
  end
12
24
 
13
- def self.load_playlist(path)
14
- instance = allocate
15
- playlist_hash = YAML.load_file(path)
16
-
17
- instance.name = File.basename(path, File.extname(path))
18
- instance.songs = playlist_hash["songs"]
25
+ def initialize(pname)
26
+ @filename = self.class.path_for pname
19
27
 
20
- instance
28
+ if File.exist?(@filename)
29
+ phash = YAML.load_file(@filename)
30
+ @songs = phash["songs"]
31
+ else
32
+ @songs = []
33
+ end
21
34
  end
22
35
 
23
- def initialize(name, songs)
24
- @name = name
25
- @songs = songs
36
+ def name
37
+ File.basename(@filename, File.extname(@filename))
26
38
  end
27
39
 
28
- def add(song)
29
- return if @songs.include?(song)
30
- @songs << song
40
+ def add(songs)
41
+ # coerce a single song into an array
42
+ [*songs].each do |song|
43
+ next if @songs.include?(song)
44
+ @songs << song
45
+ end
46
+
47
+ sync!
31
48
  end
32
49
 
33
- def delete(song)
34
- @songs.delete(song)
50
+ def delete(songs)
51
+ [*songs].each { |song| @songs.delete(song) }
52
+
53
+ sync!
35
54
  end
36
55
 
37
56
  def shuffle!
38
57
  @songs.shuffle!
39
58
  end
40
59
 
60
+ def sync!
61
+ File.open(@filename, "w") { |io| io.write to_hash.to_yaml }
62
+ end
63
+
41
64
  def to_hash
42
- { "songs" => songs }
65
+ { "songs" => @songs }
43
66
  end
44
67
  end
45
68
  end
@@ -22,7 +22,7 @@ module Muzak
22
22
  end
23
23
 
24
24
  # provide some sane fallbacks
25
- @title ||= File.basename(path, File.extname(path))
25
+ @title ||= File.basename(path, File.extname(path)) rescue ""
26
26
  @track ||= 0 # we'll need to sort by track number
27
27
  end
28
28
 
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.6
4
+ version: 0.0.7
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-10 00:00:00.000000000 Z
11
+ date: 2016-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: taglib-ruby