muzak 0.0.5 → 0.0.6

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: 2083f3ba445039c9dea5b52f8bd2383238eb4ea7
4
- data.tar.gz: c3b1aaca1e968d7da6c104549c63cd8adfb23a3c
3
+ metadata.gz: 66effe9b1b141471424f8fb07923b88ecf87da80
4
+ data.tar.gz: a79283a7dd22bbb754ba3a7ed5b9db7ba32aa99b
5
5
  SHA512:
6
- metadata.gz: 62a18069ad690e2c07fe3a87840a32b3d02c0f82f041c05dca890db1a0637c0d5c935d06665c03276f2878f2eadbda1fec7bd0a2db0173cfa1fc94cde522fda6
7
- data.tar.gz: 7f147ea2f6002c33e3e8fd6a996b0d4a136408e7dc556ca8d44510befd67514cbdae541bd98f5c64142d3ede5370d0fe5e38a72e74d4f0b7d1fa238c9a8c125e
6
+ metadata.gz: 80990917d255f3dc96570cf9389ed1238701382b9c096ceac2de8ee6cfce606b90808ebe253ce1764dda18b880eed4b05c11b75d244008ff855f20643c22fca9
7
+ data.tar.gz: 4f1bf3964aef17d1a060590162bf5ca16cfcef1f733423c20116e7b3b972bb7df363d12f38b0ada0cb31286ba49c0933823d98de704c9f845e8def882bbdfba2
data/README.md CHANGED
@@ -33,8 +33,8 @@ $ ruby -Ilib bin/muzak-cmd "command"
33
33
  ### TODO
34
34
 
35
35
  * GUI "frontend"?
36
- * optional "deep" index containing ID3 tags
37
36
  * isolation of art and music output (`Muzak::ArtProvider`?)
38
37
  * current indexing/sorting logic is terrible
39
38
  * all the documentation
40
39
  * readline's tab complete is terrible with spaces (maybe use `bond`?)
40
+ * replace YAML index with a more space/time efficient format (JSON, msgpack, Marshal?)
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "muzak"
4
+
5
+ def fatal(msg)
6
+ puts "Fatal: #{msg}"
7
+ exit 1
8
+ end
9
+
10
+ def dmenu(options)
11
+ opts = options.join("\n")
12
+ `printf "#{opts}" | dmenu`
13
+ end
14
+
15
+ fifo_path = File.join(Muzak::CONFIG_DIR, "muzak.fifo")
16
+
17
+ fatal "Is muzakd running?" unless File.exist?(fifo_path)
18
+
19
+ command = dmenu Muzak::Cmd.commands
20
+
21
+ File.open(fifo_path, "w") do |io|
22
+ io.puts command unless command.empty?
23
+ end
@@ -2,10 +2,18 @@ module Muzak
2
2
  class Album
3
3
  attr_reader :title, :songs, :cover_art
4
4
 
5
+ # instead of passing an album hash directly from the index,
6
+ # this should really just take a title and an array of Song
7
+ # objects.
5
8
  def initialize(title, album_hash)
6
9
  @title = title
7
- @songs = album_hash["songs"].map { |s| Song.new(s) }
8
10
  @cover_art = album_hash["cover"]
11
+
12
+ if album_hash["deep-songs"]
13
+ @songs = album_hash["deep-songs"]
14
+ else
15
+ @songs = album_hash["songs"].map { |s| Song.new(s) }
16
+ end
9
17
  end
10
18
  end
11
19
  end
@@ -21,7 +21,8 @@ module Muzak
21
21
  @config = {
22
22
  "music" => File.expand_path("~/music"),
23
23
  "player" => "mpv",
24
- "index-autobuild" => 86400
24
+ "index-autobuild" => 86400,
25
+ "deep-index" => false
25
26
  }
26
27
 
27
28
  Dir.mkdir(CONFIG_DIR) unless Dir.exist?(CONFIG_DIR)
@@ -18,7 +18,7 @@ module Muzak
18
18
  end
19
19
 
20
20
  def index_load
21
- debug "loading index from #{INDEX_FILE}"
21
+ verbose "loading index from #{INDEX_FILE}"
22
22
 
23
23
  @index = Index.load_index(INDEX_FILE)
24
24
 
@@ -33,7 +33,9 @@ module Muzak
33
33
  def index_build(*args)
34
34
  warn_arity(args, 0)
35
35
 
36
- @index = Index.new(@config["music"])
36
+ verbose "building a new index, this may take a while"
37
+
38
+ @index = Index.new(@config["music"], deep: !!@config["deep-index"])
37
39
  _index_sync
38
40
  end
39
41
 
@@ -59,7 +61,7 @@ module Muzak
59
61
  artist = args.join(" ")
60
62
  return if artist.nil?
61
63
 
62
- puts @index.albums_by(artist).keys
64
+ puts @index.albums_by(artist).map(&:title)
63
65
  end
64
66
 
65
67
  def songs_by_artist(*args)
@@ -68,7 +70,7 @@ module Muzak
68
70
  artist = args.join(" ")
69
71
  return if artist.nil?
70
72
 
71
- puts @index.songs_by(artist)
73
+ puts @index.songs_by(artist).map(&:title)
72
74
  end
73
75
  end
74
76
  end
@@ -44,12 +44,8 @@ module Muzak
44
44
  artist = args.join(" ")
45
45
  return if artist.nil?
46
46
 
47
- album_hashes = @index.albums_by(artist)
48
- return if album_hashes.empty?
49
-
50
- albums = album_hashes.map do |album_name, album_hash|
51
- Album.new(album_name, album_hash)
52
- end
47
+ albums = @index.albums_by(artist)
48
+ return if albums.empty?
53
49
 
54
50
  albums.each do |album|
55
51
  @player.enqueue_album album
@@ -60,10 +56,10 @@ module Muzak
60
56
  album_name = args.join(" ")
61
57
  return if album_name.nil?
62
58
 
63
- album_hash = @index.albums[album_name]
64
- return if album_hash.nil?
65
-
66
- album = Album.new(album_name, album_hash)
59
+ debug album_name
60
+ album = @index.albums[album_name]
61
+ debug album.to_s
62
+ return if album.nil?
67
63
 
68
64
  @player.enqueue_album album
69
65
  end
@@ -71,7 +67,7 @@ module Muzak
71
67
  def jukebox(*args)
72
68
  count = args.shift || @config["jukebox-size"]
73
69
 
74
- songs = @index.jukebox(count.to_i).map { |s| Song.new(s) }
70
+ songs = @index.jukebox(count.to_i)
75
71
 
76
72
  songs.each { |s| @player.enqueue_song s }
77
73
  end
@@ -67,10 +67,8 @@ module Muzak
67
67
  album_name = args.join(" ")
68
68
  return if album_name.nil?
69
69
 
70
- album_hash = @index.albums[album_name]
71
- return if album_hash.nil?
72
-
73
- album = Album.new(album_name, album_hash)
70
+ album = @index.albums[album_name]
71
+ return if album.nil?
74
72
 
75
73
  album.songs.each { |song| @playlist.add song }
76
74
 
@@ -1,5 +1,5 @@
1
1
  module Muzak
2
- VERSION = "0.0.5".freeze
2
+ VERSION = "0.0.6".freeze
3
3
 
4
4
  CONFIG_DIR = File.expand_path("~/.config/muzak").freeze
5
5
  CONFIG_FILE = File.join(CONFIG_DIR, "muzak.yml").freeze
@@ -10,10 +10,11 @@ module Muzak
10
10
  instance
11
11
  end
12
12
 
13
- def initialize(tree)
13
+ def initialize(tree, deep: false)
14
14
  @hash = {
15
15
  "timestamp" => Time.now.to_i,
16
- "artists" => {}
16
+ "artists" => {},
17
+ "deep" => deep
17
18
  }
18
19
 
19
20
  Dir.entries(tree).each do |artist|
@@ -28,17 +29,27 @@ module Muzak
28
29
 
29
30
  @hash["artists"][artist]["albums"][album] = {}
30
31
  @hash["artists"][artist]["albums"][album]["songs"] = []
32
+ @hash["artists"][artist]["albums"][album]["deep-songs"] = []
31
33
 
32
34
  Dir.glob(File.join(tree, artist, album, "**")) do |file|
33
35
  @hash["artists"][artist]["albums"][album]["cover"] = file if album_art?(file)
34
- @hash["artists"][artist]["albums"][album]["songs"] << file if music?(file)
36
+
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
35
41
  end
36
42
 
37
43
  @hash["artists"][artist]["albums"][album]["songs"].sort!
44
+ @hash["artists"][artist]["albums"][album]["deep-songs"].sort_by!(&:track)
38
45
  end
39
46
  end
40
47
  end
41
48
 
49
+ def deep?
50
+ !!@hash["deep"]
51
+ end
52
+
42
53
  def artists
43
54
  @hash["artists"].keys
44
55
  end
@@ -47,8 +58,8 @@ module Muzak
47
58
  albums_hash = {}
48
59
 
49
60
  artists.each do |a|
50
- @hash["artists"][a]["albums"].keys.each do |ak|
51
- albums_hash[ak] = @hash["artists"][a]["albums"][ak]
61
+ @hash["artists"][a]["albums"].each do |title, album_hash|
62
+ albums_hash[title] = Album.new(title, album_hash)
52
63
  end
53
64
  end
54
65
 
@@ -62,25 +73,27 @@ module Muzak
62
73
  def albums_by(artist)
63
74
  error "no such artist: '#{artist}'" unless @hash["artists"].key?(artist)
64
75
 
65
- begin
66
- @hash["artists"][artist]["albums"]
67
- rescue Exception => e
68
- {}
69
- end
76
+ @hash["artists"][artist]["albums"].map { |title, album| Album.new(title, album) }
70
77
  end
71
78
 
72
79
  def jukebox(count = 50)
73
80
  @all_albums ||= @hash["artists"].map { |_, a| a["albums"] }.flatten
74
- @all_songs ||= @all_albums.map { |aa| aa.map { |_, a| a["songs"] } }.flatten
75
- @all_songs.sample(count)
81
+
82
+ if deep?
83
+ @all_deep_songs ||= @all_albums.map { |aa| aa.map { |_, a| a["deep-songs"] } }.flatten
84
+ @all_deep_songs.sample(count)
85
+ else
86
+ @all_songs ||= @all_albums.map { |aa| aa.map { |_, a| a["songs"] } }.flatten
87
+ @all_songs.sample(count).map { |s| Song.new(s) }
88
+ end
76
89
  end
77
90
 
78
91
  def songs_by(artist)
79
92
  error "no such artist: '#{artist}'" unless @hash["artists"].key?(artist)
80
93
 
81
94
  begin
82
- albums_by(artist).map do |_, album|
83
- album["songs"].map { |s| File.basename(s) }.sort
95
+ albums_by(artist).map do |album|
96
+ album.songs
84
97
  end.flatten
85
98
  rescue Exception => e
86
99
  []
@@ -11,7 +11,7 @@ module Muzak
11
11
 
12
12
  TagLib::FileRef.open(path) do |ref|
13
13
  break if ref.null?
14
- @title = ref.tag.title || File.basename(path, File.extname(path))
14
+ @title = ref.tag.title
15
15
  @artist = ref.tag.artist
16
16
  @album = ref.tag.album
17
17
  @year = ref.tag.year
@@ -20,6 +20,10 @@ module Muzak
20
20
  @comment = ref.tag.comment
21
21
  @length = ref.audio_properties.length
22
22
  end
23
+
24
+ # provide some sane fallbacks
25
+ @title ||= File.basename(path, File.extname(path))
26
+ @track ||= 0 # we'll need to sort by track number
23
27
  end
24
28
 
25
29
  def best_guess_album_art
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.5
4
+ version: 0.0.6
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-09 00:00:00.000000000 Z
11
+ date: 2016-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: taglib-ruby
@@ -30,6 +30,7 @@ executables:
30
30
  - muzak
31
31
  - muzakd
32
32
  - muzak-cmd
33
+ - muzak-dmenu
33
34
  extensions: []
34
35
  extra_rdoc_files: []
35
36
  files:
@@ -37,6 +38,7 @@ files:
37
38
  - README.md
38
39
  - bin/muzak
39
40
  - bin/muzak-cmd
41
+ - bin/muzak-dmenu
40
42
  - bin/muzakd
41
43
  - lib/muzak.rb
42
44
  - lib/muzak/album.rb