douban.fm 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/douban.fm +21 -12
- data/lib/douban.fm/douban_fm.rb +2 -2
- data/lib/douban.fm/version.rb +1 -1
- metadata +6 -6
data/bin/douban.fm
CHANGED
@@ -83,9 +83,9 @@ class DoubanFMCLI
|
|
83
83
|
end
|
84
84
|
|
85
85
|
if options.list
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
@douban_fm = DoubanFM::DoubanFM.new(logger)
|
87
|
+
@douban_fm.fetch_channels
|
88
|
+
@douban_fm.channels['channels'].sort_by { |i| i['channel_id'] }.each do |channel|
|
89
89
|
channel_id = channel['channel_id']
|
90
90
|
puts "#{channel_id}.#{' ' * (4 - channel_id.to_s.length)}#{channel['name']}"
|
91
91
|
end
|
@@ -98,7 +98,7 @@ class DoubanFMCLI
|
|
98
98
|
end
|
99
99
|
|
100
100
|
if options.email.nil?
|
101
|
-
|
101
|
+
@douban_fm = DoubanFM::DoubanFM.new(logger)
|
102
102
|
|
103
103
|
logger.log('play anonymous playlist')
|
104
104
|
else
|
@@ -107,13 +107,13 @@ class DoubanFMCLI
|
|
107
107
|
options.password = ask("Enter password: ") { |q| q.echo = false }
|
108
108
|
end
|
109
109
|
|
110
|
-
|
111
|
-
|
110
|
+
@douban_fm = DoubanFM::DoubanFM.new(logger, options.email, options.password)
|
111
|
+
@douban_fm.login
|
112
112
|
|
113
113
|
logger.log("login as user [#{options.email}]")
|
114
114
|
end
|
115
115
|
|
116
|
-
|
116
|
+
@douban_fm.select_channel(options.channel)
|
117
117
|
|
118
118
|
logger.log("select channel #{options.channel}")
|
119
119
|
|
@@ -123,20 +123,20 @@ class DoubanFMCLI
|
|
123
123
|
begin
|
124
124
|
logger.log('fetch next playlist')
|
125
125
|
|
126
|
-
|
126
|
+
@douban_fm.fetch_next_playlist
|
127
127
|
rescue
|
128
128
|
logger.log('session expired, relogin')
|
129
129
|
|
130
|
-
|
130
|
+
@douban_fm.login
|
131
131
|
|
132
132
|
logger.log('fetch next playlist')
|
133
133
|
|
134
|
-
|
134
|
+
@douban_fm.fetch_next_playlist
|
135
135
|
end
|
136
136
|
|
137
137
|
logger.log('play current playlist')
|
138
138
|
|
139
|
-
|
139
|
+
@douban_fm.play do |waiting|
|
140
140
|
play_proc.call(waiting)
|
141
141
|
end
|
142
142
|
end
|
@@ -158,9 +158,15 @@ class DoubanFMCLI
|
|
158
158
|
def remote_port=(port)
|
159
159
|
@@remote_port = port
|
160
160
|
end
|
161
|
+
|
162
|
+
def douban_fm=(fm)
|
163
|
+
@@douban_fm = fm
|
164
|
+
end
|
161
165
|
end
|
166
|
+
|
162
167
|
@@remote_host = nil
|
163
168
|
@@remote_port = nil
|
169
|
+
@@douban_fm = nil
|
164
170
|
|
165
171
|
def do_GET request, response
|
166
172
|
path = request.path[1..-1].split('/')
|
@@ -178,6 +184,8 @@ class DoubanFMCLI
|
|
178
184
|
else
|
179
185
|
raise WEBrick::HTTPStatus::NotFound
|
180
186
|
end
|
187
|
+
when 'now'
|
188
|
+
response.body = JSON.generate({'channel' => @@douban_fm.current_channel})
|
181
189
|
else
|
182
190
|
raise WEBrick::HTTPStatus::NotFound
|
183
191
|
end
|
@@ -186,6 +194,7 @@ class DoubanFMCLI
|
|
186
194
|
|
187
195
|
servletClass.remote_host = options.remote_host
|
188
196
|
servletClass.remote_port = options.remote_port
|
197
|
+
servletClass.douban_fm = @douban_fm
|
189
198
|
|
190
199
|
Thread.new do
|
191
200
|
server = WEBrick::HTTPServer.new(:Port => 3000)
|
@@ -205,7 +214,7 @@ class DoubanFMCLI
|
|
205
214
|
# there are a lot more chances to get stack overflow in this mode,
|
206
215
|
# so can't use the proc way
|
207
216
|
while true
|
208
|
-
|
217
|
+
@douban_fm.add_to_mpd(options.remote_host, options.remote_port)
|
209
218
|
sleep 10
|
210
219
|
end
|
211
220
|
end
|
data/lib/douban.fm/douban_fm.rb
CHANGED
@@ -7,7 +7,7 @@ module DoubanFM
|
|
7
7
|
# DOUBAN_FM_MPD_PLAYLIST = 'douban.fm'
|
8
8
|
MIN_SONGS_IN_DOUBAN_FM_MPD_PLAYLIST = 10
|
9
9
|
|
10
|
-
attr_reader :waiting, :channels, :
|
10
|
+
attr_reader :waiting, :channels, :current_channel
|
11
11
|
|
12
12
|
def initialize(logger = DummyLogger.new, email = '', password = '')
|
13
13
|
@logger = logger
|
@@ -61,7 +61,7 @@ module DoubanFM
|
|
61
61
|
|
62
62
|
@current_playlist = JSON.parse(res.body)
|
63
63
|
|
64
|
-
@logger.log("raw playlist #{current_playlist}")
|
64
|
+
@logger.log("raw playlist #{@current_playlist}")
|
65
65
|
|
66
66
|
unless @current_playlist['err'].nil?
|
67
67
|
raise @current_playlist
|
data/lib/douban.fm/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: douban.fm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby-mpd
|
16
|
-
requirement: &
|
16
|
+
requirement: &70325203484360 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - =
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.1.5
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70325203484360
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: highline
|
27
|
-
requirement: &
|
27
|
+
requirement: &70325203482940 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - =
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 1.6.15
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70325203482940
|
36
36
|
description: douban.fm
|
37
37
|
email:
|
38
38
|
- hxliang1982@gmail.com
|