dhun 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +25 -17
- data/dhun.gemspec +2 -2
- data/lib/dhun.rb +1 -1
- data/lib/dhun/handler.rb +3 -3
- data/lib/dhun/player.rb +1 -9
- data/lib/dhun/runner.rb +105 -72
- metadata +2 -2
data/README.md
CHANGED
@@ -29,7 +29,7 @@ the `gem` command to compile the native extensions.
|
|
29
29
|
this runs the Dhun server as a daemon by default. to not run it as a daemon:
|
30
30
|
|
31
31
|
$ dhun start_server --foreground
|
32
|
-
|
32
|
+
or
|
33
33
|
$ dhun start_server -f
|
34
34
|
|
35
35
|
See `dhun help start_server for more information`
|
@@ -44,8 +44,7 @@ You can also query the Spotlight database before playing the files, with the
|
|
44
44
|
|
45
45
|
$ dhun query deadmau5
|
46
46
|
|
47
|
-
Querying: deadmau5 |
|
48
|
-
0 : /Volumes/Storage/Music/Grand.Theft.Auto.IV-Radio.Station.Rips-AiTB/Electro-Choc/03 One + One - No Pressure (Deadmau5 Remix).mp3
|
47
|
+
Querying: deadmau5 | 5 Results
|
49
48
|
1 : /Volumes/Storage/Music/Grand.Theft.Auto.IV-Radio.Station.Rips-AiTB/Electro-Choc/09 Chris Lake vs. Deadmau5 - I Thought Inside Out (Original Mix).mp3
|
50
49
|
2 : /Volumes/Storage/Music/Deadmau5 - It Sounds Like (MP3, 320bps) [2009]/01 Alone With You.mp3
|
51
50
|
3 : /Volumes/Storage/Music/Deadmau5 - It Sounds Like (MP3, 320bps) [2009]/02 Arguru (EDX's 5un5hine Remix).mp3
|
@@ -60,9 +59,9 @@ you can query based on certain filters such as artist,albums, title, genre and f
|
|
60
59
|
|
61
60
|
Querying: [nil] | artist:Paul van Dyk title:in genre:trance file:Paul
|
62
61
|
3 Results
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
1 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/08 - Paul van Dyk - Talk In Grey.mp3
|
63
|
+
2 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/09 - Paul van Dyk - In Circles.mp3
|
64
|
+
3 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/10 - Paul van Dyk - In Between.mp3
|
66
65
|
|
67
66
|
|
68
67
|
YOu can mix filters with regular queries as well.
|
@@ -71,14 +70,13 @@ YOu can mix filters with regular queries as well.
|
|
71
70
|
|
72
71
|
Querying: paul | title:haunted
|
73
72
|
1 Results
|
74
|
-
|
73
|
+
1 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/01 - Paul van Dyk - Haunted.mp3
|
75
74
|
|
76
75
|
You can also pass in multiple regular expressions too. they just need to be seperated by commas (,)
|
77
76
|
|
78
77
|
$ dhun query paul,trance
|
79
78
|
|
80
|
-
Querying: paul,trance |
|
81
|
-
0 : /Volumes/Storage/Music/Paul_Van_Dyk-Volume-3CD-2009-TSP/101-paul_van_dyk-volume__the_productions.mp3
|
79
|
+
Querying: paul,trance | 6 Results
|
82
80
|
1 : /Volumes/Storage/Music/Paul_Van_Dyk-Volume-3CD-2009-TSP/201-paul_van_dyk-volume__the_remixes_part_1.mp3
|
83
81
|
2 : /Volumes/Storage/Music/Paul_Van_Dyk-Volume-3CD-2009-TSP/301-paul_van_dyk-volume__the_remixes_part_2.mp3
|
84
82
|
3 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/04 - Paul van Dyk - Complicated (Feat. Ashley Tomberlin).mp3
|
@@ -93,7 +91,7 @@ Now lets put it all together and go crazy.
|
|
93
91
|
|
94
92
|
Querying: paul van,dyk | title:haunted genre:trance
|
95
93
|
1 Results
|
96
|
-
|
94
|
+
1 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/01 - Paul van Dyk - Haunted.mp3
|
97
95
|
|
98
96
|
|
99
97
|
### Playing Files
|
@@ -106,8 +104,7 @@ this can also be done by
|
|
106
104
|
|
107
105
|
$ dhun enqueue paul,trance
|
108
106
|
|
109
|
-
Querying: paul,trance |
|
110
|
-
0 : /Volumes/Storage/Music/Paul_Van_Dyk-Volume-3CD-2009-TSP/101-paul_van_dyk-volume__the_productions.mp3
|
107
|
+
Querying: paul,trance | 6 Results
|
111
108
|
1 : /Volumes/Storage/Music/Paul_Van_Dyk-Volume-3CD-2009-TSP/201-paul_van_dyk-volume__the_remixes_part_1.mp3
|
112
109
|
2 : /Volumes/Storage/Music/Paul_Van_Dyk-Volume-3CD-2009-TSP/301-paul_van_dyk-volume__the_remixes_part_2.mp3
|
113
110
|
3 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/04 - Paul van Dyk - Complicated (Feat. Ashley Tomberlin).mp3
|
@@ -122,12 +119,12 @@ If you leave the prompt blank and enter, it will queue ALL the resulting songs.
|
|
122
119
|
|
123
120
|
Enter index to queue 4 5
|
124
121
|
selected:
|
125
|
-
|
126
|
-
|
122
|
+
1 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/01 - Paul van Dyk - Haunted.mp3
|
123
|
+
2 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/02 - Paul van Dyk - White Lies (Feat. Jessica Sutta).mp3
|
127
124
|
2 files queued
|
128
125
|
|
129
126
|
|
130
|
-
Once queued, the songs will begin playing.
|
127
|
+
Once queued, the songs will begin playing. You can continue to enqueue more songs using `enqueue` command.
|
131
128
|
|
132
129
|
### Controlling Playback
|
133
130
|
|
@@ -185,8 +182,8 @@ Status
|
|
185
182
|
Currently Playing:
|
186
183
|
/Volumes/Storage/Music/Hydeout Productions (Second Collection)/02 Sky is Falling (feat. C.L. Smooth).mp3
|
187
184
|
Queue:
|
188
|
-
|
189
|
-
|
185
|
+
1 : /Volumes/Storage/Music/Hydeout Productions (Second Collection)/04 Imaginary Folklore.mp3
|
186
|
+
2 : /Volumes/Storage/Music/Hydeout Productions (Second Collection)/05 Hikari(feat. Substantial).mp3
|
190
187
|
|
191
188
|
History
|
192
189
|
|
@@ -195,6 +192,17 @@ History
|
|
195
192
|
History:
|
196
193
|
0 : /Volumes/Storage/Music/Hydeout Productions (Second Collection)/04 Imaginary Folklore.mp3
|
197
194
|
|
195
|
+
Saving Playlist
|
196
|
+
|
197
|
+
$ dhun save_playlist /tmp/playlist.pls
|
198
|
+
created /tmp/playlist
|
199
|
+
|
200
|
+
Loading Playlist
|
201
|
+
|
202
|
+
$ dhun load_playlist /tmp/playlist.pls
|
203
|
+
14 files queued
|
204
|
+
loaded playlist
|
205
|
+
|
198
206
|
|
199
207
|
### Stopping Dhun
|
200
208
|
|
data/dhun.gemspec
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'dhun'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.7.0'
|
4
4
|
s.summary = "Minimalist music player for OS X"
|
5
|
-
s.date = '2010-01-
|
5
|
+
s.date = '2010-01-24'
|
6
6
|
s.email = 'deepak.jois@gmail.com'
|
7
7
|
s.homepage = 'http://github.com/deepakjois/dhun'
|
8
8
|
s.has_rdoc = false
|
data/lib/dhun.rb
CHANGED
data/lib/dhun/handler.rb
CHANGED
@@ -2,10 +2,10 @@ require 'json'
|
|
2
2
|
module Dhun
|
3
3
|
# Handling commands sent by Dhun client
|
4
4
|
class Handler
|
5
|
-
|
5
|
+
attr_accessor :player
|
6
6
|
|
7
|
-
def initialize
|
8
|
-
@player =
|
7
|
+
def initialize(player = Dhun::Player.instance)
|
8
|
+
@player = player
|
9
9
|
end
|
10
10
|
|
11
11
|
def play
|
data/lib/dhun/player.rb
CHANGED
@@ -4,11 +4,10 @@ module Dhun
|
|
4
4
|
class Player
|
5
5
|
include Singleton
|
6
6
|
|
7
|
-
attr_accessor :queue,:history,:status,:current
|
7
|
+
attr_accessor :queue,:history,:status,:current
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
@queue,@history = [],[]
|
11
|
-
@logger = Logger.instance
|
12
11
|
@status = :stopped
|
13
12
|
end
|
14
13
|
|
@@ -41,7 +40,6 @@ module Dhun
|
|
41
40
|
if @status == :playing
|
42
41
|
@status = :paused
|
43
42
|
DhunExt.pause
|
44
|
-
@logger.debug "pause"
|
45
43
|
return true
|
46
44
|
end
|
47
45
|
return false
|
@@ -53,7 +51,6 @@ module Dhun
|
|
53
51
|
if @status == :paused
|
54
52
|
@status = :playing
|
55
53
|
DhunExt.resume
|
56
|
-
@logger.debug "resume"
|
57
54
|
return true
|
58
55
|
end
|
59
56
|
return false
|
@@ -67,7 +64,6 @@ module Dhun
|
|
67
64
|
DhunExt.stop
|
68
65
|
# Wait for @player_thread to exit cleanly
|
69
66
|
@player_thread.join unless @player_thread.nil?
|
70
|
-
@logger.debug "Stopped"
|
71
67
|
return true
|
72
68
|
end
|
73
69
|
return false
|
@@ -77,7 +73,6 @@ module Dhun
|
|
77
73
|
# returns next_track or false if invalid
|
78
74
|
def next(skip_length = 1)
|
79
75
|
unless skip_length > @queue.size
|
80
|
-
@logger.debug "next invoked"
|
81
76
|
stop
|
82
77
|
@queue.shift(skip_length - 1) #skip_length returns starting with first on queue.
|
83
78
|
next_track = @queue.first
|
@@ -97,7 +92,6 @@ module Dhun
|
|
97
92
|
stop ; skip_length += 1
|
98
93
|
end
|
99
94
|
unless skip_length > @history.size
|
100
|
-
@logger.debug "previous invoked"
|
101
95
|
tracks = @history.shift skip_length
|
102
96
|
tracks.each { |track| @queue.unshift track }
|
103
97
|
previous = @queue.first
|
@@ -116,7 +110,6 @@ module Dhun
|
|
116
110
|
while q == @queue
|
117
111
|
@queue.size.downto(1) { |n| @queue.push @queue.delete_at(rand(n)) }
|
118
112
|
end
|
119
|
-
@logger.debug @queue
|
120
113
|
return true
|
121
114
|
end
|
122
115
|
|
@@ -127,7 +120,6 @@ module Dhun
|
|
127
120
|
Thread.new do
|
128
121
|
while @status == :playing and !@queue.empty?
|
129
122
|
@current = @queue.shift
|
130
|
-
@logger.log "Playing #{@current}"
|
131
123
|
DhunExt.play_file @current
|
132
124
|
@history.unshift @current
|
133
125
|
end
|
data/lib/dhun/runner.rb
CHANGED
@@ -11,6 +11,7 @@ module Dhun
|
|
11
11
|
task.formatted_usage(self).gsub("dhun:runner:","dhun ")
|
12
12
|
end
|
13
13
|
|
14
|
+
|
14
15
|
desc "start_server","Starts the Dhun Server."
|
15
16
|
method_option :socket, :type => :string, :default => "/tmp/dhun.sock", :aliases => '-s'
|
16
17
|
method_option :log, :type => :string, :default => "/tmp/dhun.log", :aliases => '-l'
|
@@ -45,7 +46,7 @@ module Dhun
|
|
45
46
|
search = search.nil? ? nil : search.split(',')
|
46
47
|
query = Dhun::Query.new(search,options)
|
47
48
|
if query.is_valid?
|
48
|
-
|
49
|
+
|
49
50
|
#make the prompt pretty. i think.
|
50
51
|
opts = options.collect {|field,value| "#{field}:#{value}" }.join(" ")
|
51
52
|
term = search.nil? ? '[nil]' : search.join(",")
|
@@ -86,29 +87,16 @@ module Dhun
|
|
86
87
|
method_option :file, :type => :string, :aliases => '-f'
|
87
88
|
method_option :title, :type => :string, :aliases => '-t'
|
88
89
|
def enqueue(search=nil)
|
89
|
-
|
90
|
+
|
90
91
|
# invoke query command and return us all the files found.
|
91
92
|
files = invoke :query, [search], options
|
92
93
|
if files and !files.empty?
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
answer = ask "Enter index to queue (ENTER to select all): ",:yellow
|
98
|
-
|
99
|
-
indexes ||=
|
100
|
-
case
|
101
|
-
when answer.include?(',') then answer.split(',')
|
102
|
-
when answer.include?(' ') then answer.split(' ')
|
103
|
-
when answer.size >= 1 then answer.to_a
|
104
|
-
else
|
105
|
-
0..(files.size - 1)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
selected = indexes.map { |index| files[index.to_i] }
|
109
|
-
say "selected:",:green
|
94
|
+
indexes = files.size == 1 ? [1] : enqueue_prompt(files.size)
|
95
|
+
|
96
|
+
selected = indexes.map { |index| files[index.to_i-1] }
|
97
|
+
say "selected:",:magenta
|
110
98
|
say_list selected
|
111
|
-
|
99
|
+
|
112
100
|
return_response(:enqueue,nil,selected)
|
113
101
|
end
|
114
102
|
end
|
@@ -117,7 +105,7 @@ module Dhun
|
|
117
105
|
def next(count=1)
|
118
106
|
return_response(:next,[],count.to_i)
|
119
107
|
end
|
120
|
-
|
108
|
+
|
121
109
|
desc "prev COUNT", "Skips to previous song by COUNT"
|
122
110
|
def prev(count=1)
|
123
111
|
return_response(:prev,[],count.to_i)
|
@@ -125,8 +113,8 @@ module Dhun
|
|
125
113
|
|
126
114
|
desc "status", "Shows the status"
|
127
115
|
def status
|
128
|
-
return unless server_running?
|
129
116
|
response = return_response(:status,[:current,:queue])
|
117
|
+
return false unless response
|
130
118
|
say "Currently Playing:",:magenta
|
131
119
|
say response[:current],:white
|
132
120
|
say "Queue:",:cyan
|
@@ -136,86 +124,131 @@ module Dhun
|
|
136
124
|
desc "history", "Shows the previously played songs"
|
137
125
|
def history
|
138
126
|
response = return_response(:history,[:history])
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
end
|
127
|
+
return false unless response
|
128
|
+
say "History:",:cyan
|
129
|
+
say_list response[:history]
|
143
130
|
end
|
144
|
-
|
131
|
+
|
145
132
|
desc "shuffle", "Shuffles the queue"
|
146
133
|
def shuffle
|
147
134
|
response = return_response(:shuffle,[:queue])
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
end
|
135
|
+
return false unless response
|
136
|
+
say "Queue:",:cyan
|
137
|
+
say_list response[:queue]
|
152
138
|
end
|
153
139
|
|
154
140
|
desc "pause", "Pauses playing"
|
155
141
|
def pause
|
156
142
|
return_response(:pause,[])
|
157
143
|
end
|
158
|
-
|
144
|
+
|
159
145
|
desc "resume", "Resumes playing"
|
160
146
|
def resume
|
161
147
|
return_response(:resume,[])
|
162
148
|
end
|
163
|
-
|
149
|
+
|
164
150
|
desc "stop", "Stops playing"
|
165
151
|
def stop
|
166
152
|
return_response(:stop,[])
|
167
153
|
end
|
168
154
|
|
155
|
+
desc "save_playlist PATH", "saves the playlist"
|
156
|
+
def save_playlist(path=nil)
|
157
|
+
unless path
|
158
|
+
say "Please include a path for the playlist", :red
|
159
|
+
return false
|
160
|
+
end
|
161
|
+
create_file path, playlist_save
|
162
|
+
end
|
163
|
+
|
164
|
+
desc "load_playlist PATH", "loads the playlist"
|
165
|
+
def load_playlist(path=nil)
|
166
|
+
unless File.exists?(path) or path.nil?
|
167
|
+
say "invalid path! please include a valid path.", :red
|
168
|
+
return false
|
169
|
+
end
|
170
|
+
return_response(:enqueue,nil,playlist_load(path))
|
171
|
+
say "loaded playlist", :cyan
|
172
|
+
end
|
169
173
|
|
170
|
-
|
174
|
+
no_tasks do
|
171
175
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
176
|
+
# Writes the queue to the playlist.
|
177
|
+
# This will be overloaded by other playlist modules
|
178
|
+
def playlist_save
|
179
|
+
return_response(:status,[:queue])[:queue].collect { |song| song }.join("\n")
|
180
|
+
end
|
181
|
+
|
182
|
+
# Loads the playlist to the queue.
|
183
|
+
# This will be overloaded by other playlist modules.
|
184
|
+
def playlist_load(path)
|
185
|
+
File.read(path).split("\n")
|
186
|
+
end
|
187
|
+
|
188
|
+
# send out the command to server and see what it has to say.
|
189
|
+
def return_response(action,keys,argument=[])
|
190
|
+
response = get_response(action,argument)
|
191
|
+
if response
|
192
|
+
color = response.success? ? :green : :red
|
193
|
+
say response[:message], color
|
194
|
+
if keys
|
195
|
+
return keys.inject({}) {|base,key| base[key.to_sym] = response[key.to_sym] ; base}
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
177
199
|
|
178
|
-
|
179
|
-
|
180
|
-
|
200
|
+
# send command to the server and retrieve response.
|
201
|
+
def get_response(command,arguments=[])
|
202
|
+
if server_running?
|
181
203
|
resp = send_command(command,arguments)
|
182
204
|
return Dhun::Result.from_json_str(resp)
|
205
|
+
end
|
183
206
|
end
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
list.each_with_index do |item,index|
|
190
|
-
color = index.even? ? :white : :cyan
|
191
|
-
say("#{index} : #{item}",color)
|
207
|
+
|
208
|
+
# sends command to dhun client
|
209
|
+
def send_command(command,arguments=[])
|
210
|
+
cmd = { "command" => command.to_s, "arguments" => arguments }.to_json
|
211
|
+
send_message(cmd,"/tmp/dhun.sock")
|
192
212
|
end
|
193
|
-
end
|
194
213
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
214
|
+
# check to see if Dhun Server is running.
|
215
|
+
# asks to start Dhun server if not
|
216
|
+
# takes argument :silent to quiet its output.
|
217
|
+
# need to make the socket choices more flexible
|
218
|
+
def server_running?(socket = "/tmp/dhun.sock",verbose = :verbose)
|
219
|
+
socket ||= "/tmp/dhun.sock"
|
220
|
+
if is_server?(socket)
|
221
|
+
return true
|
222
|
+
else
|
223
|
+
say("Please start Dhun server first with : dhun start_server", :red) unless verbose == :silent
|
224
|
+
return false
|
225
|
+
end
|
206
226
|
end
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
227
|
+
|
228
|
+
#prompt for enqueue
|
229
|
+
def enqueue_prompt(size)
|
230
|
+
answer = ask "Enter index to queue (ENTER to select all): ",:yellow
|
231
|
+
case
|
232
|
+
when answer.include?(',')
|
233
|
+
return answer.split(',')
|
234
|
+
when answer.include?(' ')
|
235
|
+
return answer.split(' ')
|
236
|
+
when answer.size >= 1
|
237
|
+
return answer.to_a
|
238
|
+
else
|
239
|
+
return 0..(size - 1)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
# prints out list with each index value
|
244
|
+
# in pretty format! (contrasting colors)
|
245
|
+
def say_list(list)
|
246
|
+
list.each_with_index do |item,index|
|
247
|
+
color = index.even? ? :white : :cyan
|
248
|
+
say("#{index+1} : #{item}",color)
|
217
249
|
end
|
218
250
|
end
|
251
|
+
|
219
252
|
end
|
220
253
|
|
221
254
|
end
|
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.
|
4
|
+
version: 0.7.0
|
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: 2010-01-
|
12
|
+
date: 2010-01-24 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|