dhun 0.5.6 → 0.6.0
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/CONTRIBUTORS +1 -0
- data/FIX.md +4 -3
- data/README.md +106 -54
- data/Rakefile +12 -0
- data/TODO.md +0 -9
- data/bin/dhun +2 -1
- data/dhun.gemspec +7 -5
- data/lib/dhun.rb +2 -3
- data/lib/dhun/client.rb +25 -0
- data/lib/dhun/dhun_server.rb +56 -23
- data/lib/dhun/handler.rb +69 -90
- data/lib/dhun/player.rb +90 -65
- data/lib/dhun/query.rb +63 -42
- data/lib/dhun/result.rb +8 -8
- data/lib/dhun/runner.rb +204 -86
- data/lib/dhun/server.rb +6 -48
- metadata +34 -5
- data/lib/dhun/command.rb +0 -15
- data/lib/dhun/controller.rb +0 -160
- data/lib/dhun/dhun_client.rb +0 -30
data/CONTRIBUTORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* achiu - http://github.com/achiu
|
data/FIX.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
## Fixes/Improvements required
|
2
2
|
|
3
|
-
* Refactor multiple calls to result.to_json
|
4
3
|
* Refactor handler calls by converting it from module to subclass of EventMachine::Connection object
|
5
|
-
|
6
|
-
*
|
4
|
+
|
5
|
+
* store the socket information somehow so the runner remembers?
|
6
|
+
|
7
|
+
* have play jump to queue number
|
data/README.md
CHANGED
@@ -19,16 +19,20 @@ put the binaries in the right place. You will need to have XCode installed for
|
|
19
19
|
the `gem` command to compile the native extensions.
|
20
20
|
|
21
21
|
$ gem sources -a http://gemcutter.org
|
22
|
-
$ gem install dhun
|
22
|
+
$ gem install dhun
|
23
23
|
|
24
24
|
### Starting Dhun
|
25
25
|
|
26
|
-
$ dhun
|
26
|
+
$ dhun start_server
|
27
27
|
Starting Dhun
|
28
28
|
|
29
|
-
|
30
|
-
`dhun -h` for more options.
|
29
|
+
this runs the Dhun server as a daemon by default. to not run it as a daemon:
|
31
30
|
|
31
|
+
$ dhun start_server --foreground
|
32
|
+
or
|
33
|
+
$ dhun start_server -f
|
34
|
+
|
35
|
+
See `dhun help start_server for more information`
|
32
36
|
|
33
37
|
### Querying for files
|
34
38
|
|
@@ -38,53 +42,105 @@ will look for files matching that keyword and start playing them.
|
|
38
42
|
You can also query the Spotlight database before playing the files, with the
|
39
43
|
`query` command.
|
40
44
|
|
41
|
-
$ dhun query
|
42
|
-
|
43
|
-
|
44
|
-
/
|
45
|
-
/
|
45
|
+
$ dhun query deadmau5
|
46
|
+
|
47
|
+
Querying: deadmau5 | 6 Results
|
48
|
+
0 : /Volumes/Storage/Music/Grand.Theft.Auto.IV-Radio.Station.Rips-AiTB/Electro-Choc/03 One + One - No Pressure (Deadmau5 Remix).mp3
|
49
|
+
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
|
+
2 : /Volumes/Storage/Music/Deadmau5 - It Sounds Like (MP3, 320bps) [2009]/01 Alone With You.mp3
|
51
|
+
3 : /Volumes/Storage/Music/Deadmau5 - It Sounds Like (MP3, 320bps) [2009]/02 Arguru (EDX's 5un5hine Remix).mp3
|
52
|
+
4 : /Volumes/Storage/Music/Deadmau5 - It Sounds Like (MP3, 320bps) [2009]/03 Bye Friend.mp3
|
53
|
+
5 : /Volumes/Storage/Music/Deadmau5 - It Sounds Like (MP3, 320bps) [2009]/04 Clockwork.mp3
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
you can query based on certain filters such as artist,albums, title, genre and file.
|
58
|
+
|
59
|
+
$ dhun query --artist="Paul van Dyk" --genre=trance --file 'Paul' --title in
|
60
|
+
|
61
|
+
Querying: [nil] | artist:Paul van Dyk title:in genre:trance file:Paul
|
62
|
+
3 Results
|
63
|
+
0 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/08 - Paul van Dyk - Talk In Grey.mp3
|
64
|
+
1 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/09 - Paul van Dyk - In Circles.mp3
|
65
|
+
2 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/10 - Paul van Dyk - In Between.mp3
|
66
|
+
|
46
67
|
|
47
|
-
|
48
|
-
`album`, `artist`, `title`, `genre` and `file` filters are supported.
|
68
|
+
YOu can mix filters with regular queries as well.
|
49
69
|
|
50
|
-
$ dhun query
|
51
|
-
5 results
|
52
|
-
/Users/deepak/Dropbox/shared/music/gypsy/Putumayo - Gypsy Groove - 11 - Eastenders - Vino Iubirea Mea (!DelaDap Remix) (Germany).mp3
|
53
|
-
/Users/deepak/Dropbox/shared/music/gypsy/Putumayo - Gypsy Groove - 10 - Luminescent Orchestrii - Amari Szi, Amari (Amon Remix) (USA).mp3
|
54
|
-
/Users/deepak/Dropbox/shared/music/gypsy/Putumayo - Gypsy Groove - 09 - Kistehén Tánczenekar - Virágok a Réten (Romano Drom Remix) (Hungary).mp3
|
55
|
-
/Users/deepak/Dropbox/shared/music/gypsy/Putumayo - Gypsy Groove - 08 - Anselmo Crew - Süt Ictim Dilim Yandi (Hungary).mp3
|
56
|
-
/Users/deepak/Dropbox/shared/music/gypsy/Putumayo - Gypsy Groove - 07 - Magnifico & Turbolentza - Zh Ne Sui Pa Pur Tua (Slovenia).mp3
|
70
|
+
$ dhun query paul --title=haunted
|
57
71
|
|
58
|
-
|
72
|
+
Querying: paul | title:haunted
|
73
|
+
1 Results
|
74
|
+
0 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/01 - Paul van Dyk - Haunted.mp3
|
59
75
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
76
|
+
You can also pass in multiple regular expressions too. they just need to be seperated by commas (,)
|
77
|
+
|
78
|
+
$ dhun query paul,trance
|
79
|
+
|
80
|
+
Querying: paul,trance | 7 Results
|
81
|
+
0 : /Volumes/Storage/Music/Paul_Van_Dyk-Volume-3CD-2009-TSP/101-paul_van_dyk-volume__the_productions.mp3
|
82
|
+
1 : /Volumes/Storage/Music/Paul_Van_Dyk-Volume-3CD-2009-TSP/201-paul_van_dyk-volume__the_remixes_part_1.mp3
|
83
|
+
2 : /Volumes/Storage/Music/Paul_Van_Dyk-Volume-3CD-2009-TSP/301-paul_van_dyk-volume__the_remixes_part_2.mp3
|
84
|
+
3 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/04 - Paul van Dyk - Complicated (Feat. Ashley Tomberlin).mp3
|
85
|
+
4 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/01 - Paul van Dyk - Haunted.mp3
|
86
|
+
5 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/02 - Paul van Dyk - White Lies (Feat. Jessica Sutta).mp3
|
87
|
+
6 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/03 - Paul van Dyk - Sabotage.mp3
|
88
|
+
|
89
|
+
|
90
|
+
Now lets put it all together and go crazy.
|
91
|
+
|
92
|
+
$ dhun query 'paul van',dyk --genre=trance --title=haunted
|
93
|
+
|
94
|
+
Querying: paul van,dyk | title:haunted genre:trance
|
95
|
+
1 Results
|
96
|
+
0 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/01 - Paul van Dyk - Haunted.mp3
|
64
97
|
|
65
|
-
Note that if you want to pass filters longer than a word, you will need to
|
66
|
-
enclose the argument in double quotes, like `dhun query "artist:akli d"`
|
67
98
|
|
68
99
|
### Playing Files
|
69
100
|
|
70
|
-
|
71
|
-
|
72
|
-
|
101
|
+
To play the files, first enqueue the songs.
|
102
|
+
|
103
|
+
$ dhun play paul,trance
|
73
104
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
105
|
+
this can also be done by
|
106
|
+
|
107
|
+
$ dhun enqueue paul,trance
|
108
|
+
|
109
|
+
Querying: paul,trance | 7 Results
|
110
|
+
0 : /Volumes/Storage/Music/Paul_Van_Dyk-Volume-3CD-2009-TSP/101-paul_van_dyk-volume__the_productions.mp3
|
111
|
+
1 : /Volumes/Storage/Music/Paul_Van_Dyk-Volume-3CD-2009-TSP/201-paul_van_dyk-volume__the_remixes_part_1.mp3
|
112
|
+
2 : /Volumes/Storage/Music/Paul_Van_Dyk-Volume-3CD-2009-TSP/301-paul_van_dyk-volume__the_remixes_part_2.mp3
|
113
|
+
3 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/04 - Paul van Dyk - Complicated (Feat. Ashley Tomberlin).mp3
|
114
|
+
4 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/01 - Paul van Dyk - Haunted.mp3
|
115
|
+
5 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/02 - Paul van Dyk - White Lies (Feat. Jessica Sutta).mp3
|
116
|
+
6 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/03 - Paul van Dyk - Sabotage.mp3
|
117
|
+
Enter index to queue:
|
118
|
+
|
119
|
+
It will prompt you to enter the index of the songs you want queued.(numbers on the left side)
|
120
|
+
You can enter them separated by commas(1,2,3,4) or spaces(1 2 3 4) or a single song if you like.
|
121
|
+
If you leave the prompt blank and enter, it will queue ALL the resulting songs.
|
122
|
+
|
123
|
+
Enter index to queue 4 5
|
124
|
+
selected:
|
125
|
+
0 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/01 - Paul van Dyk - Haunted.mp3
|
126
|
+
1 : /Volumes/Storage/Music/Paul van Dyk - In Between (2007)/02 - Paul van Dyk - White Lies (Feat. Jessica Sutta).mp3
|
127
|
+
2 files queued
|
128
|
+
|
129
|
+
|
130
|
+
Once queued, the songs will begin playing. you can continue to enqueue more songs via enqueue and play.
|
79
131
|
|
80
|
-
|
132
|
+
### Controlling Playback
|
133
|
+
|
81
134
|
|
82
|
-
|
83
|
-
|
84
|
-
|
135
|
+
Starting Playback(needs to have songs in queue)
|
136
|
+
|
137
|
+
$ dhun play
|
138
|
+
resuming playback
|
85
139
|
|
140
|
+
Stopping playback.
|
86
141
|
|
87
|
-
|
142
|
+
$ dhun stop
|
143
|
+
Dhun has stopped
|
88
144
|
|
89
145
|
Pausing playback.
|
90
146
|
|
@@ -126,29 +182,25 @@ Status
|
|
126
182
|
|
127
183
|
$ dhun status
|
128
184
|
Dhun is running
|
129
|
-
|
130
|
-
/
|
131
|
-
|
132
|
-
/
|
133
|
-
/
|
134
|
-
|
135
|
-
/Users/deepak/Dropbox/shared/music/Here Comes/02 - Janglin.mp3
|
136
|
-
/Users/deepak/Dropbox/shared/music/Here Comes/01 - 40 Day Dream.mp3
|
137
|
-
/Users/deepak/Dropbox/shared/music/Here Comes/03 - Carries On.mp3
|
138
|
-
|
185
|
+
Currently Playing:
|
186
|
+
/Volumes/Storage/Music/Hydeout Productions (Second Collection)/02 Sky is Falling (feat. C.L. Smooth).mp3
|
187
|
+
Queue:
|
188
|
+
0 : /Volumes/Storage/Music/Hydeout Productions (Second Collection)/04 Imaginary Folklore.mp3
|
189
|
+
1 : /Volumes/Storage/Music/Hydeout Productions (Second Collection)/05 Hikari(feat. Substantial).mp3
|
190
|
+
|
139
191
|
History
|
140
192
|
|
141
193
|
$ dhun history
|
142
|
-
|
143
|
-
|
144
|
-
/
|
145
|
-
|
194
|
+
1 files in history
|
195
|
+
History:
|
196
|
+
0 : /Volumes/Storage/Music/Hydeout Productions (Second Collection)/04 Imaginary Folklore.mp3
|
197
|
+
|
146
198
|
|
147
199
|
### Stopping Dhun
|
148
200
|
|
149
|
-
This will exit the
|
201
|
+
This will exit the dhun server.
|
150
202
|
|
151
|
-
$ dhun
|
203
|
+
$ dhun stop_server
|
152
204
|
|
153
205
|
## Coming Soon
|
154
206
|
|
data/Rakefile
CHANGED
@@ -81,3 +81,15 @@ end
|
|
81
81
|
desc 'Build the dhun extension'
|
82
82
|
task :build => "lib/dhun_ext.#{DLEXT}"
|
83
83
|
|
84
|
+
# ==========================================================
|
85
|
+
# Riot Testing
|
86
|
+
# ==========================================================
|
87
|
+
|
88
|
+
desc 'Default task: run all tests'
|
89
|
+
task :default => [:test]
|
90
|
+
require 'rake/testtask'
|
91
|
+
Rake::TestTask.new(:test) do |test|
|
92
|
+
test.libs << 'lib' << 'test'
|
93
|
+
test.pattern = 'test/**/*_test.rb'
|
94
|
+
test.verbose = false
|
95
|
+
end
|
data/TODO.md
CHANGED
@@ -1,17 +1,8 @@
|
|
1
1
|
TODO
|
2
2
|
====
|
3
3
|
|
4
|
-
* Daemonizing/Logging of Server
|
5
|
-
|
6
|
-
* Better querying mechanism using a treetop parser
|
7
|
-
|
8
|
-
* Prev, by keeping a history
|
9
|
-
|
10
4
|
* Display info from idv3 tags
|
11
5
|
|
12
|
-
* Advanced Querying Support
|
13
|
-
|
14
6
|
* iTunes support
|
15
7
|
|
16
|
-
* Pause and Skip functionality
|
17
8
|
|
data/bin/dhun
CHANGED
data/dhun.gemspec
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'dhun'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.6.0'
|
4
4
|
s.summary = "Minimalist music player for OS X"
|
5
|
-
s.date = '
|
5
|
+
s.date = '2010-01-12'
|
6
6
|
s.email = 'deepak.jois@gmail.com'
|
7
7
|
s.homepage = 'http://github.com/deepakjois/dhun'
|
8
8
|
s.has_rdoc = false
|
9
|
+
s.add_development_dependency('riot', '>=0.10.11')
|
10
|
+
s.add_development_dependency('rr', '>=0.10.5')
|
9
11
|
s.add_dependency('eventmachine', '>=0.12.10')
|
10
12
|
s.add_dependency('json_pure', '>=1.2.0')
|
11
13
|
s.add_dependency('daemons', '>=1.0.10')
|
14
|
+
s.add_dependency('thor', '>=0.12.0')
|
12
15
|
s.authors = ["Deepak Jois"]
|
13
16
|
# = MANIFEST =
|
14
17
|
s.files = %w[
|
18
|
+
CONTRIBUTORS
|
15
19
|
FIX.md
|
16
20
|
LICENSE.txt
|
17
21
|
README.md
|
@@ -26,9 +30,7 @@ Gem::Specification.new do |s|
|
|
26
30
|
ext/player.c
|
27
31
|
ext/query.c
|
28
32
|
lib/dhun.rb
|
29
|
-
lib/dhun/
|
30
|
-
lib/dhun/controller.rb
|
31
|
-
lib/dhun/dhun_client.rb
|
33
|
+
lib/dhun/client.rb
|
32
34
|
lib/dhun/dhun_server.rb
|
33
35
|
lib/dhun/handler.rb
|
34
36
|
lib/dhun/logger.rb
|
data/lib/dhun.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
module Dhun
|
2
|
-
VERSION = '0.
|
2
|
+
VERSION = '0.6.0'
|
3
3
|
|
4
4
|
autoload :Runner, 'dhun/runner'
|
5
|
-
autoload :Controller, 'dhun/controller'
|
6
5
|
autoload :Server, 'dhun/server'
|
7
6
|
autoload :DhunServer, 'dhun/dhun_server'
|
8
|
-
autoload :
|
7
|
+
autoload :Client, 'dhun/client'
|
9
8
|
autoload :Handler, 'dhun/handler'
|
10
9
|
autoload :Player, 'dhun/player'
|
11
10
|
autoload :Query, 'dhun/query'
|
data/lib/dhun/client.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'json'
|
3
|
+
module Dhun
|
4
|
+
module Client
|
5
|
+
|
6
|
+
def send_message(message,socket)
|
7
|
+
response = nil
|
8
|
+
UNIXSocket.open(socket) do |unix|
|
9
|
+
unix.puts message
|
10
|
+
response = unix.read
|
11
|
+
end
|
12
|
+
response
|
13
|
+
end
|
14
|
+
|
15
|
+
def is_server?(socket)
|
16
|
+
begin
|
17
|
+
UNIXSocket.open(socket) { |socket| }
|
18
|
+
return true
|
19
|
+
rescue StandardError
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
data/lib/dhun/dhun_server.rb
CHANGED
@@ -1,41 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'eventmachine'
|
1
3
|
require 'json'
|
4
|
+
%w[handler logger player query result].each {|lib| require File.dirname(__FILE__) + "/#{lib}"}
|
2
5
|
module Dhun
|
3
6
|
# Handler for commands sent from client
|
4
7
|
module DhunServer
|
8
|
+
@@logger = Dhun::Logger.instance
|
9
|
+
|
5
10
|
def post_init
|
6
11
|
#puts "-- client connected"
|
12
|
+
@data = ""
|
7
13
|
end
|
8
14
|
|
9
|
-
def receive_data
|
10
|
-
@logger ||= Logger.instance
|
15
|
+
def receive_data(data)
|
11
16
|
begin
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
@@logger.debug data
|
18
|
+
@data << data
|
19
|
+
# puts data.inspect.to_s
|
20
|
+
cmd = begin
|
21
|
+
JSON.parse(@data)
|
22
|
+
rescue
|
23
|
+
@@logger.log $!
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
handle_client_request cmd["command"], cmd["arguments"] if cmd
|
17
27
|
rescue StandardError => ex
|
18
|
-
|
19
|
-
|
20
|
-
|
28
|
+
@@logger.log ex.message
|
29
|
+
@@logger.log ex.backtrace
|
30
|
+
send_data Dhun::Result.new(:error,ex.message).to_json
|
21
31
|
close_connection true
|
22
32
|
end
|
23
33
|
end
|
24
34
|
|
25
|
-
def handle_client_request
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
@logger.debug "Sending #{result}"
|
34
|
-
send_data result
|
35
|
-
rescue StandardError => ex
|
36
|
-
@logger.log "-- error : #{ex.message}"
|
37
|
-
@logger.log ex.backtrace
|
35
|
+
def handle_client_request(command,arguments)
|
36
|
+
handler = Dhun::Handler.new
|
37
|
+
raise "No Command!" if command.nil?
|
38
|
+
result =
|
39
|
+
if arguments and arguments != [] # this check is on the sloppy side...
|
40
|
+
handler.send command, arguments
|
41
|
+
else
|
42
|
+
handler.send command
|
38
43
|
end
|
44
|
+
@@logger.debug "Sending #{result}"
|
45
|
+
puts (result ? result.inspect.to_s : 'nil')
|
46
|
+
send_data Dhun::Result.new(*result).to_json
|
47
|
+
close_connection true
|
39
48
|
end
|
40
49
|
|
41
50
|
def unbind
|
@@ -43,3 +52,27 @@ module Dhun
|
|
43
52
|
end
|
44
53
|
end
|
45
54
|
end
|
55
|
+
|
56
|
+
def remove_socket_file(socket)
|
57
|
+
File.delete(socket) if File.exist?(socket)
|
58
|
+
end
|
59
|
+
|
60
|
+
def stop!
|
61
|
+
Dhun::Player.instance.stop
|
62
|
+
Dhun::Logger.instance.log "Stopping Dhun"
|
63
|
+
EventMachine.stop if EventMachine.reactor_running?
|
64
|
+
exit
|
65
|
+
end
|
66
|
+
|
67
|
+
if ARGV
|
68
|
+
Dhun::Logger.instance.file = ARGV[1]
|
69
|
+
Dhun::Logger.instance.log "Starting Dhun"
|
70
|
+
at_exit { remove_socket_file(ARGV[0]); stop! }
|
71
|
+
EventMachine::run do
|
72
|
+
puts "Dhun Server at: #{ARGV[0]}"
|
73
|
+
trap('QUIT') { stop! }
|
74
|
+
trap('INT') { stop! }
|
75
|
+
trap('TERM') { stop! }
|
76
|
+
EventMachine::start_server ARGV[0], Dhun::DhunServer
|
77
|
+
end
|
78
|
+
end
|
data/lib/dhun/handler.rb
CHANGED
@@ -2,118 +2,97 @@ require 'json'
|
|
2
2
|
module Dhun
|
3
3
|
# Handling commands sent by Dhun client
|
4
4
|
class Handler
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
Player.instance
|
9
|
-
return result.to_json
|
5
|
+
attr_reader :player
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@player = Dhun::Player.instance
|
10
9
|
end
|
11
|
-
|
12
|
-
def play
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
result = Result.new :error, "No Results Found"
|
19
|
-
else
|
20
|
-
@player.play_files files
|
21
|
-
result = Result.new :success, "#{files.size} files queued for playing",
|
22
|
-
:files => files
|
23
|
-
end
|
24
|
-
else
|
25
|
-
result = Result.new :error, "Invalid query syntax. See dhun -h for correct syntax"
|
10
|
+
|
11
|
+
def play
|
12
|
+
response =
|
13
|
+
case @player.play
|
14
|
+
when false then [:error,"already playing"]
|
15
|
+
when true then [:success, "resuming playback"]
|
16
|
+
when :empty then [:error, 'no file in queue']
|
26
17
|
end
|
27
|
-
|
18
|
+
response
|
28
19
|
end
|
29
20
|
|
30
|
-
def enqueue(
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
files = q.execute_spotlight_query
|
35
|
-
if files.empty?
|
36
|
-
result = Result.new :error, "No Results Found"
|
37
|
-
else
|
38
|
-
@player.enqueue files
|
39
|
-
result = Result.new :success, "#{files.size} files queued for playing.",
|
40
|
-
:files => files
|
41
|
-
end
|
42
|
-
else
|
43
|
-
result = Result.new :error, "Invalid query syntax. See dhun -h for correct syntax"
|
44
|
-
end
|
45
|
-
result.to_json
|
21
|
+
def enqueue(files)
|
22
|
+
perform_action :enqueue, files,
|
23
|
+
:success => ["#{files.size} files queued", {:files => files}],
|
24
|
+
:error => ["No files queued"]
|
46
25
|
end
|
47
26
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
when :paused then "Dhun is paused"
|
53
|
-
when :stopped then "Dhun has stopped"
|
54
|
-
end
|
55
|
-
now_playing = @player.current
|
56
|
-
queue = @player.queue
|
57
|
-
result = Result.new :success, status_msg, :now_playing => now_playing, :queue => queue
|
58
|
-
result.to_json
|
27
|
+
def pause
|
28
|
+
perform_action :pause,nil,
|
29
|
+
:success => "Dhun is paused at #{@player.current}",
|
30
|
+
:error => "Dhun has already paused or stopped"
|
59
31
|
end
|
60
32
|
|
61
|
-
def
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
33
|
+
def resume
|
34
|
+
perform_action :resume,nil,
|
35
|
+
:success => "Dhun is resumed at #{@player.current}",
|
36
|
+
:error => "Dhun has already resumed or stopped"
|
37
|
+
end
|
38
|
+
|
39
|
+
def stop
|
40
|
+
perform_action :stop,nil,
|
41
|
+
:success => "Dhun has stopped",
|
42
|
+
:error => "Dhun has already stopped"
|
66
43
|
end
|
67
44
|
|
68
45
|
def next(skip_length=1)
|
69
|
-
|
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
|
46
|
+
next_prev :next, 'queue',skip_length
|
74
47
|
end
|
75
48
|
|
76
49
|
def prev(skip_length=1)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
50
|
+
next_prev :prev, 'history',skip_length
|
51
|
+
end
|
52
|
+
|
53
|
+
def shuffle
|
54
|
+
perform_action :shuffle,nil,
|
55
|
+
:success => ['Queue is shuffled', { :queue => @player.queue }],
|
56
|
+
:error => 'Dhun cannot shuffle(queue empty, same songs)'
|
82
57
|
end
|
83
58
|
|
84
|
-
def
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
when :paused
|
89
|
-
result = Result.new :success, "Dhun is paused at #{@player.current}"
|
90
|
-
when :stopped
|
91
|
-
result = Result.new :error, "Dhun has already stopped"
|
92
|
-
end
|
93
|
-
return result.to_json
|
59
|
+
def clear
|
60
|
+
perform_action :clear,nil,
|
61
|
+
:success => "Queue is cleared",
|
62
|
+
:error => "Queue is not cleared"
|
94
63
|
end
|
95
64
|
|
96
|
-
|
97
|
-
|
98
|
-
|
65
|
+
|
66
|
+
def status
|
67
|
+
status_msg =
|
99
68
|
case @player.status
|
100
|
-
when :playing
|
101
|
-
|
102
|
-
when :stopped
|
103
|
-
result = Result.new :error, "Dhun has already stopped"
|
69
|
+
when :playing then "Dhun is running"
|
70
|
+
when :paused then "Dhun is paused"
|
71
|
+
when :stopped then "Dhun has stopped"
|
104
72
|
end
|
105
|
-
|
73
|
+
[:success, status_msg, {:current => @player.current, :queue => @player.queue}]
|
106
74
|
end
|
107
75
|
|
108
|
-
def
|
109
|
-
@player
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
76
|
+
def history
|
77
|
+
return [:success, "#{@player.history.size} files in history",{:history => @player.history}] unless @player.history.empty?
|
78
|
+
return [:error, "No files in history"]
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
# get response
|
84
|
+
def perform_action(action, arg=nil, message={})
|
85
|
+
result = arg.nil? ? @player.send(action) : @player.send(action,arg)
|
86
|
+
return [:error,message[:error]].flatten unless result
|
87
|
+
return [:success,message[:success]].flatten
|
117
88
|
end
|
89
|
+
|
90
|
+
#next and previous method
|
91
|
+
def next_prev(action,message,skip_length)
|
92
|
+
track = @player.send(action,skip_length)
|
93
|
+
return [:success, "Dhun is playing #{track}"] if track
|
94
|
+
return [:error, "Not enough tracks in #{message}"]
|
95
|
+
end
|
96
|
+
|
118
97
|
end
|
119
98
|
end
|