douban.fm 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 ehonlia
1
+ Copyright (c) 2013 honnix
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -32,6 +32,9 @@ Usage: douban.fm [OPTIONS]
32
32
  -r, --remote remote mpd remote host, in format of <IP>:<Port>
33
33
  -c, --channel channel which channel to play
34
34
  if not provided, channel 0 will be selected but who knows what it is
35
+ -k, --kbps kbps set kbps
36
+ if not provided, 64kbps will be used as default
37
+ for non-pro user this option simply does not work
35
38
  -l, --list list all available channels
36
39
  -i, --interaction [port] start an http server for interaction
37
40
  if omit port, 3000 will be used by default
@@ -70,9 +73,12 @@ Basically there are two ways to play music
70
73
  * `douban.fm -m -u xxx@xx.com -p` will play private playlist but will ask for your password to sign in
71
74
  * if "-m -i" is provided, a web server will start listening on 3000 by default, and you may
72
75
  * GET /channels to get all available channels
73
- * GET /now to get current playing channel
76
+ * GET /channel to get current playing channel
74
77
  * GET /channel/<id> to switch to channel of the specified id, if id is -1, channel will be selected randomly
75
78
  each time fetching playlist
79
+ * GET /kbps to get current kbps
80
+ * GET /kbps/<kbps> to set kbps, for non-pro user this option simply does not work
81
+ * GET / or /index to view channel switch pannel
76
82
 
77
83
  ## Contributing
78
84
 
data/bin/douban.fm CHANGED
@@ -42,7 +42,14 @@ class DoubanFMCLI
42
42
  opts.on('-c', '--channel channel',
43
43
  'which channel to play',
44
44
  'if not provided, channel 0 will be selected but who knows what it is') do |channel|
45
- options.channel = channel
45
+ options.channel = channel.to_i
46
+ end
47
+
48
+ opts.on('-k', '--kbps kbps',
49
+ 'set kbps',
50
+ 'if not provided, 64kbps will be used as default',
51
+ 'for non-pro user this option simply does not work') do |kbps|
52
+ options.kbps = kbps.to_i
46
53
  end
47
54
 
48
55
  opts.on('-l', '--list', 'list all available channels') do
@@ -108,6 +115,10 @@ class DoubanFMCLI
108
115
  options.channel = 0
109
116
  end
110
117
 
118
+ if options.kbps.nil?
119
+ options.kbps = 64
120
+ end
121
+
111
122
  if options.email.nil?
112
123
  @douban_fm = DoubanFM::DoubanFM.new(logger)
113
124
 
@@ -128,6 +139,10 @@ class DoubanFMCLI
128
139
 
129
140
  logger.log("select channel #{options.channel}")
130
141
 
142
+ @douban_fm.set_kbps(options.kbps)
143
+
144
+ logger.log("set kbps #{options.kbps}")
145
+
131
146
  if options.mpd.nil?
132
147
  play_proc = proc do |waiting|
133
148
  if waiting
@@ -193,10 +208,17 @@ class DoubanFMCLI
193
208
  @@douban_fm.clear_mpd_playlist(@@remote_host, @@remote_port)
194
209
  raise WEBrick::HTTPStatus::OK
195
210
  else
196
- raise WEBrick::HTTPStatus::NotFound
211
+ response.body = JSON.generate({'channel' => @@douban_fm.current_channel})
212
+ end
213
+ when 'kbps'
214
+ unless path[1].nil?
215
+ # there is a race but not a big deal
216
+ @@douban_fm.set_kbps(path[1].to_i)
217
+ @@douban_fm.clear_mpd_playlist(@@remote_host, @@remote_port)
218
+ raise WEBrick::HTTPStatus::OK
219
+ else
220
+ response.body = JSON.generate({'kbps' => @@douban_fm.kbps})
197
221
  end
198
- when 'now'
199
- response.body = JSON.generate({'channel' => @@douban_fm.current_channel})
200
222
  when 'index', nil
201
223
  html_path = File.expand_path('../../index.html', __FILE__)
202
224
  response.body = File.readlines(html_path).join('')
data/douban.fm.gemspec CHANGED
@@ -3,18 +3,18 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'douban.fm/version'
4
4
 
5
5
  Gem::Specification.new do |gem|
6
- gem.name = "douban.fm"
6
+ gem.name = 'douban.fm'
7
7
  gem.version = DoubanFM::VERSION
8
- gem.authors = ["honnix"]
9
- gem.email = ["hxliang1982@gmail.com"]
8
+ gem.authors = ['honnix']
9
+ gem.email = ['hxliang1982@gmail.com']
10
10
  gem.description = %q{douban.fm}
11
11
  gem.summary = %q{douban.fm}
12
- gem.homepage = "https://github.com/honnix/douban.fm"
12
+ gem.homepage = 'https://github.com/honnix/douban.fm'
13
13
 
14
14
  gem.files = `git ls-files`.split($/)
15
15
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
- gem.require_paths = ["lib"]
17
+ gem.require_paths = ['lib']
18
18
 
19
19
  gem.add_dependency 'ruby-mpd', '0.1.5'
20
20
  gem.add_dependency 'highline', '1.6.15'
data/index.html CHANGED
@@ -98,7 +98,12 @@
98
98
  <a id="now" class="btn btn-large btn-success" data-loading-text="loading ..." data-complete-text="" href=""><i class="icon-play"></i><i class="icon-music"></i> </a>
99
99
  <hr>
100
100
  <div class="channels">
101
-
101
+ </div>
102
+ <hr>
103
+ <div class="kbps-list">
104
+ <div class="music"><a class="btn kbps" href="#" id="kbps_192"><i class="icon-headphones"></i>192kbps</a></div>
105
+ <div class="music"><a class="btn kbps" href="#" id="kbps_128"><i class="icon-headphones"></i>128kbps</a></div>
106
+ <div class="music"><a class="btn kbps" href="#" id="kbps_64"><i class="icon-headphones"></i>64kbps</a></div>
102
107
  </div>
103
108
  </div>
104
109
  </div>
@@ -121,11 +126,13 @@
121
126
  $(function(){
122
127
  $('a#now').button('loading');
123
128
  // load current play channel
124
- $.getJSON("/now", function(data) {
129
+ $.getJSON('/channel', function(data) {
125
130
  var now_id = data['channel'];
126
131
  var now_name;
127
132
  if (now_id === -1)
128
- now_name = "乱放"
133
+ now_name = '乱放'
134
+ else if (now_id === -3)
135
+ now_name = '红心'
129
136
 
130
137
  // load all the channels
131
138
  $.getJSON('/channels', function(data) {
@@ -136,30 +143,42 @@
136
143
  if(val['channel_id'] == now_id)
137
144
  now_name = val['name'];
138
145
 
139
- items.push('<div class="music"><a class="btn channel" href="#" id="channel_'+val['channel_id']+'"><i class="icon-music"></i> '+val['name']+'</a></div>');
146
+ items.push('<div class="music"><a class="btn channel" href="#" id="channel_'+val['channel_id']+'"><i class="icon-music"></i>' + val['name'] + '</a></div>');
140
147
  });
141
148
  items.push('<div class="music"><a class="btn channel" href="#" id="channel_-1"><i class="icon-music"></i>乱放</a></div>');
149
+ items.push('<div class="music"><a class="btn channel" href="#" id="channel_-3"><i class="icon-heart"></i>红心</a></div>');
142
150
 
143
151
  $('div.channels').html(items.join(''));
144
152
  $('a#now').button('reset');
145
- $('a#now').html($('a#now').html()+now_name);
146
- }); // end of getJSON
147
153
 
154
+ $.getJSON('/kbps', function(data) {
155
+ $('a#now').html($('a#now').html() + now_name + '@' + data['kbps'] + 'kbps');
156
+ });
157
+ }); // end of getJSON
148
158
  });
149
159
 
150
160
  // bind click event to channel buttons
151
- $('body').on('click','a.btn.channel',function(event){
161
+ $('body').on('click', 'a.btn.channel', function(event){
152
162
  $('a#now').button('loading');
153
163
  event.preventDefault();
154
164
  var channel = $(this).attr('id').substr(8);
155
165
  // switch channel
156
- $.get("/channel/"+channel, function(data) {
166
+ $.get('/channel/' + channel, function(data) {
157
167
  window.location.href = window.location.href;
158
168
  });
159
169
  });
160
170
 
171
+ // bind click kbps to kbps buttons
172
+ $('body').on('click', 'a.btn.kbps', function(event){
173
+ $('a#now').button('loading');
174
+ event.preventDefault();
175
+ var kbps = $(this).attr('id').substr(5);
176
+ // set kbps
177
+ $.get('/kbps/'+ kbps, function(data) {
178
+ window.location.href = window.location.href;
179
+ });
180
+ });
161
181
  }); // end of document.ready
162
-
163
182
  </script>
164
183
  </body>
165
184
  </html>
@@ -10,7 +10,7 @@ module DoubanFM
10
10
 
11
11
  RANDOM_CHANNEL_ID = -1
12
12
 
13
- attr_reader :waiting, :channels, :current_channel
13
+ attr_reader :waiting, :channels, :current_channel, :kbps
14
14
 
15
15
  def initialize(logger = DummyLogger.new, email = '', password = '')
16
16
  @logger = logger
@@ -53,6 +53,10 @@ module DoubanFM
53
53
  @current_channel = channel_num
54
54
  end
55
55
 
56
+ def set_kbps(kbps)
57
+ @kbps = kbps
58
+ end
59
+
56
60
  def fetch_next_playlist
57
61
  if @current_channel == RANDOM_CHANNEL_ID
58
62
  channel_id = select_random_channel
@@ -72,8 +76,10 @@ module DoubanFM
72
76
  :sid => '',
73
77
  :h => '',
74
78
  :channel => channel_id,
75
- :type => 'n'
79
+ :type => 'n',
80
+ :kbps => @kbps
76
81
  }
82
+ @logger.log(params)
77
83
  uri.query = URI.encode_www_form(params)
78
84
  res = Net::HTTP.get_response(uri)
79
85
 
@@ -1,3 +1,3 @@
1
1
  module DoubanFM
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.0'
3
3
  end
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.3.1
4
+ version: 0.4.0
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-24 00:00:00.000000000 Z
12
+ date: 2013-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-mpd
16
- requirement: &70313014465400 !ruby/object:Gem::Requirement
16
+ requirement: &70273789925180 !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: *70313014465400
24
+ version_requirements: *70273789925180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: highline
27
- requirement: &70313014464720 !ruby/object:Gem::Requirement
27
+ requirement: &70273789924420 !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: *70313014464720
35
+ version_requirements: *70273789924420
36
36
  description: douban.fm
37
37
  email:
38
38
  - hxliang1982@gmail.com