dhun 0.5.5 → 0.5.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.
data/FIX.md CHANGED
@@ -1,4 +1,6 @@
1
1
  ## Fixes/Improvements required
2
2
 
3
3
  * Refactor multiple calls to result.to_json
4
- * Refactor handler calls by converting it from module to subclass of EventMachine::Connection object
4
+ * Refactor handler calls by converting it from module to subclass of EventMachine::Connection object
5
+ * Put querying code in play and enqueue methods inside the player
6
+ * Clean up parser to avoid any SQL-injection style errors in args
data/README.md CHANGED
@@ -76,6 +76,13 @@ your queue. To append files to queue, use `enqueue`.
76
76
  /Users/deepak/Music/iTunes/iTunes Media/Music/Edward Sharpe & The Magnetic Zeros/Here Comes/01 40 Day Dream.mp3
77
77
  /Users/deepak/Music/iTunes/iTunes Media/Music/Edward Sharpe & The Magnetic Zeros/Here Comes/02 Janglin.mp3
78
78
  /Users/deepak/Music/iTunes/iTunes Media/Music/Edward Sharpe & The Magnetic Zeros/Here Comes/03 Carries On.mp3
79
+
80
+ Enqueuing more files.
81
+
82
+ $ dhun enqueue chup
83
+ 1 files queued for playing.
84
+ /Users/deepak/Dropbox/shared/music/Coke Studio/Chup.mp3
85
+
79
86
 
80
87
  ### Controlling Playback
81
88
 
@@ -94,6 +101,27 @@ Skipping to next file
94
101
  $ dhun next
95
102
  Dhun is playing /Users/deepak/Music/iTunes/iTunes Media/Music/Edward Sharpe & The Magnetic Zeros/Here Comes/03 Carries On.mp3
96
103
 
104
+ You can use a numeric argument to specify the number of tracks to skip ahead,
105
+ like `dhun next 2`.
106
+
107
+ Skipping to previous file in history.
108
+
109
+ $ dhun prev
110
+ Dhun is playing /Users/deepak/Music/iTunes/iTunes Media/Music/Edward Sharpe & The Magnetic Zeros/Here Comes/02 Janglin.mp3
111
+
112
+ You can use a numeric argument to specify the number of tracks to skip ahead,
113
+ like `dhun prev 2`.
114
+
115
+ Shuffling the queue
116
+
117
+ $ dhun shuffle
118
+ Queue is shuffled
119
+ /Users/deepak/Dropbox/shared/music/3 idiots/35634_Give Me Some Sunshine.mp3
120
+ /Users/deepak/Dropbox/shared/music/Aao Wish Karen/35612_Kuch Aisa.mp3
121
+ /Users/deepak/Dropbox/shared/music/Coke Studio/Jo-Meray.mp3
122
+
123
+ ### Other commands
124
+
97
125
  Status
98
126
 
99
127
  $ dhun status
@@ -108,11 +136,13 @@ Status
108
136
  /Users/deepak/Dropbox/shared/music/Here Comes/01 - 40 Day Dream.mp3
109
137
  /Users/deepak/Dropbox/shared/music/Here Comes/03 - Carries On.mp3
110
138
 
111
- Enqueuing more files.
139
+ History
112
140
 
113
- $ dhun enqueue chup
114
- 1 files queued for playing.
115
- /Users/deepak/Dropbox/shared/music/Coke Studio/Chup.mp3
141
+ $ dhun history
142
+ 3 files in history
143
+ /Users/deepak/Dropbox/shared/music/Coke Studio/Bari-Barsi.mp3
144
+ /Users/deepak/Dropbox/shared/music/Coke Studio/Aankhon-Kay-Sagar.mp3
145
+ /Users/deepak/Dropbox/shared/music/Coke Studio/Paimona.mp3
116
146
 
117
147
  ### Stopping Dhun
118
148
 
@@ -122,10 +152,11 @@ This will exit the process.
122
152
 
123
153
  ## Coming Soon
124
154
 
125
- These features are planned in the next few releases
155
+ There are some features planned in the short run. Please file an issue with a
156
+ feature request, if you have one.
126
157
 
127
- * Playing previous song, using something like `dhun prev`
128
- * Skipping ahead by more than one file, like `dhun next 2` or `dhun prev 2`
158
+ * Saving/Loading playlists
159
+ * Growl Notifications using `growlnotify`
129
160
 
130
161
  And someday..
131
162
 
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'dhun'
3
- s.version = '0.5.5'
3
+ s.version = '0.5.6'
4
4
  s.summary = "Minimalist music player for OS X"
5
- s.date = '2009-12-14'
5
+ s.date = '2009-12-18'
6
6
  s.email = 'deepak.jois@gmail.com'
7
7
  s.homepage = 'http://github.com/deepakjois/dhun'
8
8
  s.has_rdoc = false
@@ -1,5 +1,5 @@
1
1
  module Dhun
2
- VERSION = '0.5.5'
2
+ VERSION = '0.5.6'
3
3
 
4
4
  autoload :Runner, 'dhun/runner'
5
5
  autoload :Controller, 'dhun/controller'
@@ -3,7 +3,7 @@ module Dhun
3
3
  class Controller
4
4
 
5
5
  attr_accessor :options,:logger
6
-
6
+
7
7
  def initialize(options)
8
8
  @options = options
9
9
  @logger = Logger.instance
@@ -17,11 +17,11 @@ module Dhun
17
17
  server.start
18
18
  end
19
19
  end
20
-
20
+
21
21
  def stop
22
22
  send_command("stop")
23
23
  end
24
-
24
+
25
25
  def query(*args)
26
26
  abort_if_empty_args(args)
27
27
  q = Query.new(args)
@@ -71,9 +71,9 @@ module Dhun
71
71
  now_playing = resp[:now_playing]
72
72
  queue = resp[:queue]
73
73
  puts "Now playing #{now_playing}" if now_playing
74
- if queue.empty?
75
- puts "Queue is empty"
76
- else
74
+ if queue.empty?
75
+ puts "Queue is empty"
76
+ else
77
77
  print_list(queue)
78
78
  end
79
79
  end
@@ -86,11 +86,27 @@ module Dhun
86
86
  print_list(resp[:history]) unless resp[:history].empty?
87
87
  end
88
88
 
89
- def next(*args)
90
- resp = get_json_response("next")
89
+ def next(skip_length=1)
90
+ begin
91
+ skip_length = Integer(skip_length)
92
+ rescue ArgumentError => ex # Not a valid integer
93
+ abort ex.message
94
+ end
95
+ resp = get_json_response("next",[skip_length])
91
96
  puts resp[:message] if resp
92
97
  end
93
98
 
99
+ def prev(skip_length=1)
100
+ begin
101
+ skip_length = Integer(skip_length)
102
+ rescue ArgumentError => ex # Not a valid integer
103
+ abort ex.message
104
+ end
105
+ resp = get_json_response("prev",[skip_length])
106
+ puts resp[:message] if resp
107
+ end
108
+
109
+
94
110
  def pause
95
111
  resp = get_json_response("pause")
96
112
  puts resp[:message] if resp
@@ -123,10 +139,10 @@ module Dhun
123
139
  end
124
140
 
125
141
  def get_json_response(command,args=[])
126
- begin
142
+ begin
127
143
  resp = send_command(command,args)
128
144
  return Result.from_json_str(resp)
129
- rescue
145
+ rescue
130
146
  puts "Invalid Response From Server"
131
147
  logger.debug $!
132
148
  return nil
@@ -134,7 +150,7 @@ module Dhun
134
150
  end
135
151
 
136
152
  def abort_if_empty_args(args)
137
- abort "You must pass in atleast one argument" if args.empty?
153
+ abort "You must pass in atleast one argument" if args.empty?
138
154
  end
139
155
 
140
156
  def print_list(list)
@@ -50,7 +50,7 @@ module Dhun
50
50
  status_msg = case @player.status
51
51
  when :playing then "Dhun is running"
52
52
  when :paused then "Dhun is paused"
53
- when :stopped then "Dhun is stopped"
53
+ when :stopped then "Dhun has stopped"
54
54
  end
55
55
  now_playing = @player.current
56
56
  queue = @player.queue
@@ -65,10 +65,19 @@ module Dhun
65
65
  result.to_json
66
66
  end
67
67
 
68
- def next(*args)
68
+ def next(skip_length=1)
69
69
  @player = Player.instance
70
- next_track = @player.next
71
- result = Result.new :success, (next_track ? "Dhun is playing #{next_track}" : "No More Tracks")
70
+ next_track = @player.next skip_length
71
+ msg = next_track ? "Dhun is playing #{next_track}" : "Not enough tracks in queue"
72
+ result = Result.new :success, msg
73
+ return result.to_json
74
+ end
75
+
76
+ def prev(skip_length=1)
77
+ @player = Player.instance
78
+ prev_track = @player.prev skip_length
79
+ msg = prev_track ? "Dhun is playing #{prev_track}" : "Not enough tracks in history"
80
+ result = Result.new :success, msg
72
81
  return result.to_json
73
82
  end
74
83
 
@@ -79,7 +88,7 @@ module Dhun
79
88
  when :paused
80
89
  result = Result.new :success, "Dhun is paused at #{@player.current}"
81
90
  when :stopped
82
- result = Result.new :error, "Dhun is already stopped"
91
+ result = Result.new :error, "Dhun has already stopped"
83
92
  end
84
93
  return result.to_json
85
94
  end
@@ -91,7 +100,7 @@ module Dhun
91
100
  when :playing
92
101
  result = Result.new :success, "Dhun is playing #{@player.current}"
93
102
  when :stopped
94
- result = Result.new :error, "Dhun is already stopped"
103
+ result = Result.new :error, "Dhun has already stopped"
95
104
  end
96
105
  return result.to_json
97
106
  end
@@ -23,7 +23,7 @@ module Dhun
23
23
  @queue.clear
24
24
  end
25
25
 
26
-
26
+
27
27
  def play_files(files)
28
28
  if files.empty?
29
29
  logger.log "Empty Queue"
@@ -44,14 +44,13 @@ module Dhun
44
44
  return unless self.status == :stopped
45
45
  @status = :playing
46
46
  @player_thread = Thread.new do
47
- while @status == :playing and !queue.empty?
47
+ while @status == :playing and !queue.empty?
48
48
  @current = @queue.shift
49
49
  logger.log "Playing #{@current}"
50
50
  DhunExt.play_file @current
51
51
  @history.unshift @current
52
52
  end
53
53
  @status = :stopped
54
- logger.log "Finished playing #{@current}"
55
54
  @current = nil
56
55
  end
57
56
  end
@@ -78,14 +77,34 @@ module Dhun
78
77
  logger.debug "Stopped"
79
78
  end
80
79
 
81
- def next
80
+ def next(skip_length = 1)
82
81
  logger.debug "Switching to next"
83
- stop # stops current track
84
- next_track = @queue.first
85
- play # start playing with the next track
82
+ unless @queue.size < skip_length
83
+ stop # stops current track
84
+ @queue.shift skip_length-1 # Remove skip_length-1 tracks
85
+ next_track = @queue.first
86
+ play # start playing with the next track
87
+ end
86
88
  return next_track
87
89
  end
88
90
 
91
+ def prev(skip_length = 1)
92
+ logger.debug "Switching to prev"
93
+ unless @history.size < skip_length
94
+ unless @status == :stopped
95
+ stop
96
+ # history has increased by one
97
+ skip_length = skip_length + 1
98
+ end
99
+ tracks = @history.shift skip_length
100
+ logger.debug tracks
101
+ tracks.each { |t| @queue.unshift t }
102
+ prev_track = @queue.first
103
+ play # start playing with the next track
104
+ end
105
+ return prev_track
106
+ end
107
+
89
108
  def shuffle
90
109
  return if @queue.empty?
91
110
  s = @queue.size
@@ -5,7 +5,7 @@ module Dhun
5
5
  # Heavily lifted from Thin codebase
6
6
  class Runner
7
7
  COMMANDS = %w(start query)
8
- CLIENT_COMMANDS = %w(stop play pause resume next enqueue status shuffle history)
8
+ CLIENT_COMMANDS = %w(stop play pause resume next prev enqueue status shuffle history)
9
9
  # Parsed options
10
10
  attr_accessor :options
11
11
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dhun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Deepak Jois
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-14 00:00:00 -08:00
12
+ date: 2009-12-18 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency