hearken 0.0.3 → 0.0.4

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.
data/HISTORY.rdoc CHANGED
@@ -1,6 +1,12 @@
1
- = next
1
+ = 0.0.4
2
2
 
3
- * Fixed bug in setup_scrobbling command
3
+ * Partially fixed bug with growl (correctly escaping characters in message)
4
+ * moved all configuration, queues and index to a .hearken directory
5
+
6
+ = 0.0.3
7
+
8
+ * Fixed bug in setup_scrobbling command (using $stdin directly - 'gets' seems to have been aliased by thor)
9
+ * Added growl notification
4
10
 
5
11
  = 0.0.2
6
12
 
data/README.rdoc CHANGED
@@ -46,5 +46,6 @@ will describe the use and purpose of a particular command
46
46
 
47
47
  = Future plans for world domination
48
48
 
49
+ * Fix or remove 'recent' - it should sort library based on file modification date
49
50
  * Get working on linux
50
51
  * Get working on windows
data/lib/hearken.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hearken
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -28,7 +28,7 @@ module Hearken
28
28
  with :show_properties, 'show'
29
29
  with :restart, 'next'
30
30
  with :enqueue, '+'
31
- with_all *%w{reload search start stop scrobbling shuffle list setup_scrobbling recent flush}
31
+ with_all *%w{reload search start stop scrobbling shuffle list setup_scrobbling recent flush }
32
32
  end
33
33
  end
34
34
  end
@@ -1,6 +1,5 @@
1
1
  module Hearken
2
2
  module Indexing
3
- PATH = File.expand_path('~')+'/.music'
4
3
  end
5
4
  end
6
5
 
@@ -1,14 +1,5 @@
1
1
  require 'hearken/tagged'
2
-
3
- class String
4
- def escape char
5
- gsub(char, "\\#{char}")
6
- end
7
-
8
- def escape2 char
9
- split(char).join("\\#{char}")
10
- end
11
- end
2
+ require 'hearken/monkey_violence'
12
3
 
13
4
  module Hearken::Indexing::Executor
14
5
  include Hearken::Tagged
@@ -18,10 +9,6 @@ module Hearken::Indexing::Executor
18
9
  @timestamp = path.timestamp
19
10
  end
20
11
 
21
- def clean_path path
22
- path.escape(" ").escape2("'").escape("!").escape2("`").escape("(").escape(")").escape2("&").escape2(";")
23
- end
24
-
25
12
  def execute command
26
13
  debug command
27
14
  `#{command} 2>&1`
@@ -1,11 +1,12 @@
1
1
  require 'hearken/indexing/executor'
2
+ require 'hearken/monkey_violence'
2
3
 
3
4
  class Hearken::Indexing::FfmpegFile
4
5
  include Hearken::Indexing::Executor
5
6
 
6
7
  def initialize path
7
8
  extract_file_attributes path
8
- content = execute "ffmpeg -i #{clean_path @path}"
9
+ content = execute "ffmpeg -i #{@path.escape_for_sh}"
9
10
  state = :draining
10
11
  @meta = {}
11
12
  content.each_line do |line|
@@ -1,15 +1,19 @@
1
1
  require 'splat'
2
+ require 'hearken/paths'
2
3
  require 'hearken/indexing/persistant_traverser'
3
4
 
4
5
  class Hearken::Indexing::Indexer
6
+ include Hearken::Paths
7
+
5
8
  def initialize path
9
+ create_paths
6
10
  @path = path
7
11
  end
8
12
 
9
13
  def execute
10
14
  start = Time.now
11
15
  count = 0
12
- traverser = Hearken::Indexing::PersistantTraverser.new @path, Hearken::Indexing::PATH
16
+ traverser = Hearken::Indexing::PersistantTraverser.new @path, index_path
13
17
 
14
18
  traverser.each do |audio_file|
15
19
  count += 1
@@ -1,6 +1,9 @@
1
1
  require 'hearken/track'
2
+ require 'hearken/paths'
2
3
 
3
4
  class Hearken::Library
5
+ include Hearken::Paths
6
+
4
7
  FILE_FIELDS = %w{path timestamp}
5
8
  TAG_FIELDS = %w{album track title artist time date albumartist puid mbartistid mbalbumid mbalbumartistid asin}
6
9
  FIELDS = FILE_FIELDS + TAG_FIELDS
@@ -9,6 +12,7 @@ class Hearken::Library
9
12
  attr_reader :tracks
10
13
 
11
14
  def initialize preferences
15
+ create_paths
12
16
  end
13
17
 
14
18
  def count
@@ -28,10 +32,8 @@ class Hearken::Library
28
32
  end
29
33
 
30
34
  def reload
31
- s = Time.now.to_i
32
- path = File.expand_path('~')+'/.music'
33
35
  @tracks = []
34
- File.open path do |file|
36
+ File.open index_path do |file|
35
37
  id = 0
36
38
  while line = file.gets
37
39
  row = line.chomp.split '<->'
@@ -40,7 +42,6 @@ class Hearken::Library
40
42
  @tracks << track
41
43
  id += 1
42
44
  end
43
- end if File.exist? path
44
- puts "Reloaded db with #{@tracks.size} tracks in #{Time.now.to_i-s} seconds"
45
+ end if File.exist? index_path
45
46
  end
46
47
  end
@@ -0,0 +1,21 @@
1
+ class String
2
+ def from_home
3
+ File.expand_path('~')+'/'+self
4
+ end
5
+
6
+ def escape char
7
+ gsub(char, "\\#{char}")
8
+ end
9
+
10
+ def escape2 char
11
+ split(char).join("\\#{char}")
12
+ end
13
+
14
+ def escape_for_sh
15
+ self.escape2("\`").escape(" ").escape2("&").escape2(";").escape("!").escape("(").escape(")").escape2("'")
16
+ end
17
+
18
+ def escape_for_sh_quoted
19
+ self.escape2("\`")
20
+ end
21
+ end
@@ -1,3 +1,5 @@
1
+ require 'hearken/monkey_violence'
2
+
1
3
  module Hearken::Notification
2
4
  end
3
5
 
@@ -8,6 +10,6 @@ class Hearken::Notification::GrowlNotifier
8
10
  end
9
11
 
10
12
  def started track
11
- `growlnotify -t "Hearken" --image #{@image_path} -m '#{track.to_short_s}'` if @growlnotify
13
+ `growlnotify -t "Hearken unto ..." --image #{@image_path} -m \"#{track.to_short_s.escape_for_sh_quoted}\"` if @growlnotify
12
14
  end
13
15
  end
@@ -0,0 +1,19 @@
1
+ require 'fileutils'
2
+
3
+ module Hearken::Paths
4
+ attr_reader :preferences_path, :queue_path, :index_path
5
+
6
+ def create_paths
7
+ @preferences_path = '.hearken/config'.from_home
8
+ @queue_path = '.hearken/queue'.from_home
9
+ @index_path = '.hearken/music'.from_home
10
+ FileUtils.mv '.hearken'.from_home, '.hearken.tmp'.from_home if File.exist?('.hearken'.from_home) && File.file?('.hearken'.from_home)
11
+ FileUtils.mkdir_p '.hearken/queue'.from_home
12
+ FileUtils.mv '.hearken.tmp'.from_home, @preferences_path if File.exist? '.hearken.tmp'.from_home
13
+ FileUtils.mv '.music'.from_home, @index_path if File.exist? '.music'.from_home
14
+ end
15
+
16
+ def in_queue_dir
17
+ Dir.chdir(queue_path) { yield }
18
+ end
19
+ end
@@ -1,4 +1,5 @@
1
1
  require 'splat'
2
+ require 'fileutils'
2
3
 
3
4
  require 'hearken/queue'
4
5
  require 'hearken/scrobbler'
@@ -17,6 +18,7 @@ module Hearken
17
18
  @notifiers = [@scrobbler, @growl]
18
19
  @library = Library.new preferences
19
20
  @library.reload
21
+ create_paths
20
22
  end
21
23
 
22
24
  def c text,colour
@@ -79,7 +81,7 @@ module Hearken
79
81
  @library.with_track(id) do |track|
80
82
  notify_started track
81
83
  register track
82
- player_pid = path.to_player
84
+ player_pid = path.escape2("\`").to_player
83
85
  Process.wait player_pid
84
86
  notify_finished track
85
87
  end
@@ -1,18 +1,19 @@
1
+ require 'hearken/paths'
2
+ require 'hearken/monkey_violence'
3
+
1
4
  module Hearken
2
5
  class Preferences
6
+ include Hearken::Paths
7
+
3
8
  def initialize
4
- @preference_path = home_path '.hearken'
5
- if File.exists? @preference_path
6
- @preferences = YAML.load File.read(@preference_path)
9
+ create_paths
10
+ if File.exists? preferences_path
11
+ @preferences = YAML.load_file preferences_path
7
12
  else
8
13
  @preferences = {}
9
14
  end
10
15
  end
11
16
 
12
- def home_path *paths
13
- File.join File.expand_path('~'), *paths
14
- end
15
-
16
17
  def [] key
17
18
  @preferences[key]
18
19
  end
@@ -23,7 +24,7 @@ module Hearken
23
24
  end
24
25
 
25
26
  def persist
26
- File.open(@preference_path, 'w') {|f| f.puts @preferences.to_yaml}
27
+ File.open(preferences_path, 'w') {|f| f.puts @preferences.to_yaml}
27
28
  end
28
29
  end
29
30
  end
data/lib/hearken/queue.rb CHANGED
@@ -1,23 +1,31 @@
1
- module Hearken
2
- module Queue
3
- def enqueue id
1
+ require 'hearken/paths'
2
+
3
+ module Hearken::Queue
4
+ include Hearken::Paths
5
+
6
+ def enqueue id
7
+ in_queue_dir do
4
8
  @sequence ||= 0
5
9
  @library.with_track id do |track|
6
10
  File.open("#{Time.now.to_i}-#{@sequence.to_s.rjust(8,'0')}.song", 'w') {|f| f.print track.to_yaml }
7
11
  @sequence += 1
8
12
  end
9
13
  end
14
+ end
10
15
 
11
- def each
16
+ def each
17
+ in_queue_dir do
12
18
  Dir.glob('*.song').sort.each do |file|
13
- yield YAML.load File.read(file)
19
+ yield YAML.load_file file
14
20
  end
15
21
  end
22
+ end
16
23
 
17
- def dequeue
24
+ def dequeue
25
+ in_queue_dir do
18
26
  file = Dir.glob('*.song').sort.first
19
27
  return nil unless file
20
- hash = YAML.load(File.read(file))
28
+ hash = YAML.load_file file
21
29
  id = hash[:id] if hash
22
30
  FileUtils.rm file
23
31
  id
@@ -11,6 +11,7 @@ describe Hearken::Player do
11
11
  Hearken::Scrobbler.stub!(:new).and_return scrobbler
12
12
  Hearken::Library.stub!(:new).and_return library
13
13
  library.stub! :reload
14
+ scrobbler.stub! :enabled=
14
15
  end
15
16
 
16
17
  describe '#current' do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hearken
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mark Ryall
@@ -155,7 +155,9 @@ files:
155
155
  - lib/hearken/indexing/persistant_traverser.rb
156
156
  - lib/hearken/indexing/persisted_traverser.rb
157
157
  - lib/hearken/library.rb
158
+ - lib/hearken/monkey_violence.rb
158
159
  - lib/hearken/notification/growl_notifier.rb
160
+ - lib/hearken/paths.rb
159
161
  - lib/hearken/player.rb
160
162
  - lib/hearken/preferences.rb
161
163
  - lib/hearken/queue.rb