douban.fm 0.4.0 → 0.4.4

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjAxNmM3NzU1ODc3N2ZjMzc4NDJjMTdmM2Q4Y2VmY2I4NmY3NTJjNg==
5
+ data.tar.gz: !binary |-
6
+ NzIzM2NiY2IyNjUxOWEyZjRlNGZkNTczMDJhZTllZTRhNTQzZDMzZg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OGI2MGUxZjFkMWVhODA2NTIwODJjYTdiMjQ3Y2I3MzRkNTBhN2Y5NGRkZGJm
10
+ MWY1OTZjMDA5NjVlMjc3MDI1NjY1N2U2YzY0MmY3MTFlN2FkZDEwYWFjZjAy
11
+ OGY3ZTBiNmE1N2RmZmUwYTNiMDBlMDExOTM0Y2IyYTY4YzRmMDg=
12
+ data.tar.gz: !binary |-
13
+ YTAzMmY5Yzk0MWUyOWM2NjlkZmQ5OWZmOGIzYjYwZGY4OTg1MTg2OGUyZDdk
14
+ M2UwOWM2MDQ1OWI3ODkyOWI2OWUzOWFlMjVkMjZhNGQ5OTIyNzVmMTMzYzRi
15
+ MGFjNDBhOWIzYTk5YmZiYzNmNjRjODJkNGM4ZGQxMmNmZjg1MmE=
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .idea/*
data/README.md CHANGED
@@ -36,6 +36,7 @@ Usage: douban.fm [OPTIONS]
36
36
  if not provided, 64kbps will be used as default
37
37
  for non-pro user this option simply does not work
38
38
  -l, --list list all available channels
39
+ -f, --favor [count] list favorites songs
39
40
  -i, --interaction [port] start an http server for interaction
40
41
  if omit port, 3000 will be used by default
41
42
  GET /channels to get all available channels
@@ -56,6 +56,11 @@ class DoubanFMCLI
56
56
  options.list = true
57
57
  end
58
58
 
59
+ opts.on('-f', '--favor [count]', 'list favorites songs') do |count|
60
+ options.favor = true
61
+ options.liked = count.to_i
62
+ end
63
+
59
64
  opts.on('-i', '--interaction [port]',
60
65
  'start an http server for interaction',
61
66
  'if omit port, 3000 will be used by default',
@@ -135,6 +140,15 @@ class DoubanFMCLI
135
140
  logger.log("login as user [#{options.email}]")
136
141
  end
137
142
 
143
+ if options.favor
144
+ @douban_fm.fetch_liked_songs(options.liked)
145
+ @douban_fm.liked_songs['songs'].each_with_index do |song, index|
146
+ puts "#{index}#{' '*(4 - index.to_s.length)}#{song['title']} - #{song['artist']}"
147
+ end
148
+
149
+ exit
150
+ end
151
+
138
152
  @douban_fm.select_channel(options.channel)
139
153
 
140
154
  logger.log("select channel #{options.channel}")
data/index.html CHANGED
@@ -8,7 +8,7 @@
8
8
  <meta name="author" content="@honnix,@jihao">
9
9
 
10
10
  <!-- CSS -->
11
- <link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
11
+ <link href="http://twitter.github.io/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
12
12
  <style type="text/css">
13
13
 
14
14
  /* Sticky footer styles
@@ -66,7 +66,7 @@
66
66
  padding: 2px 2px;
67
67
  }
68
68
  </style>
69
- <link href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet">
69
+ <link href="http://twitter.github.io/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet">
70
70
 
71
71
  <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
72
72
  <!--[if lt IE 9]>
@@ -121,7 +121,7 @@
121
121
  ================================================== -->
122
122
  <!-- Placed at the end of the document so the pages load faster -->
123
123
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
124
- <script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-button.js"></script>
124
+ <script src="http://twitter.github.io/bootstrap/assets/js/bootstrap-button.js"></script>
125
125
  <script type="text/javascript">
126
126
  $(function(){
127
127
  $('a#now').button('loading');
@@ -10,7 +10,7 @@ module DoubanFM
10
10
 
11
11
  RANDOM_CHANNEL_ID = -1
12
12
 
13
- attr_reader :waiting, :channels, :current_channel, :kbps
13
+ attr_reader :waiting, :channels, :current_channel, :kbps, :liked_songs
14
14
 
15
15
  def initialize(logger = DummyLogger.new, email = '', password = '')
16
16
  @logger = logger
@@ -23,7 +23,7 @@ module DoubanFM
23
23
 
24
24
  def login
25
25
  uri = URI('http://www.douban.com/j/app/login')
26
- res = Net::HTTP.post_form(uri,
26
+ res = get_http_client().post_form(uri,
27
27
  'email' => @email,
28
28
  'password' => @password,
29
29
  'app_name' => 'radio_desktop_mac',
@@ -38,7 +38,7 @@ module DoubanFM
38
38
  today = Date.new
39
39
  if today != @last_fetching_channels_date
40
40
  uri = URI('http://www.douban.com/j/app/radio/channels')
41
- res = Net::HTTP.get(uri)
41
+ res = get_http_client().get(uri)
42
42
  @channels = JSON.parse(res)
43
43
 
44
44
  @last_fetching_channels_date = today
@@ -49,6 +49,27 @@ module DoubanFM
49
49
  @logger.log("raw channel list #{channels}")
50
50
  end
51
51
 
52
+ def fetch_liked_songs(count)
53
+ uri = URI('http://www.douban.com/j/app/radio/liked_songs')
54
+ params = {
55
+ :app_name => 'radio_desktop_mac',
56
+ :version => '100',
57
+ :user_id => @user_info['user_id'],
58
+ :expire => @user_info['expire'],
59
+ :token => @user_info['token'],
60
+ :count => count,
61
+ :exclude => ''
62
+ }
63
+ uri.query = URI.encode_www_form(params)
64
+ res = get_http_client().get_response(uri)
65
+ @liked_songs = JSON.parse(res.body)
66
+ @logger.log("liked songs #{@liked_songs}")
67
+
68
+ unless @liked_songs['err'].nil?
69
+ raise @liked_songs
70
+ end
71
+ end
72
+
52
73
  def select_channel(channel_num)
53
74
  @current_channel = channel_num
54
75
  end
@@ -81,7 +102,7 @@ module DoubanFM
81
102
  }
82
103
  @logger.log(params)
83
104
  uri.query = URI.encode_www_form(params)
84
- res = Net::HTTP.get_response(uri)
105
+ res = get_http_client().get_response(uri)
85
106
 
86
107
  @current_playlist = JSON.parse(res.body)
87
108
 
@@ -230,6 +251,15 @@ module DoubanFM
230
251
  end
231
252
 
232
253
  private
254
+ def get_http_client
255
+ proxy = ENV['HTTP_PROXY'] || ENV['HTTPS_PROXY']
256
+ unless proxy.nil?
257
+ m = proxy.match(/(http(s)?:\/\/)?(?<proxy_addr>.*):(?<proxy_port>[0-9]*)/)
258
+ Net::HTTP::Proxy(m['proxy_addr'], m['proxy_port'])
259
+ else
260
+ Net::HTTP
261
+ end
262
+ end
233
263
 
234
264
  def add_current_playlist_to_mpd(mpd)
235
265
  @logger.log("add more songs to mpd")
@@ -1,3 +1,3 @@
1
1
  module DoubanFM
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.4'
3
3
  end
metadata CHANGED
@@ -1,38 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: douban.fm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
5
- prerelease:
4
+ version: 0.4.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - honnix
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-15 00:00:00.000000000 Z
11
+ date: 2013-08-31 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: ruby-mpd
16
- requirement: &70273789925180 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - =
17
+ - - '='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 0.1.5
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70273789925180
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.5
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: highline
27
- requirement: &70273789924420 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - =
31
+ - - '='
31
32
  - !ruby/object:Gem::Version
32
33
  version: 1.6.15
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *70273789924420
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.15
36
41
  description: douban.fm
37
42
  email:
38
43
  - hxliang1982@gmail.com
@@ -55,27 +60,26 @@ files:
55
60
  - lib/douban.fm/version.rb
56
61
  homepage: https://github.com/honnix/douban.fm
57
62
  licenses: []
63
+ metadata: {}
58
64
  post_install_message:
59
65
  rdoc_options: []
60
66
  require_paths:
61
67
  - lib
62
68
  required_ruby_version: !ruby/object:Gem::Requirement
63
- none: false
64
69
  requirements:
65
70
  - - ! '>='
66
71
  - !ruby/object:Gem::Version
67
72
  version: '0'
68
73
  required_rubygems_version: !ruby/object:Gem::Requirement
69
- none: false
70
74
  requirements:
71
75
  - - ! '>='
72
76
  - !ruby/object:Gem::Version
73
77
  version: '0'
74
78
  requirements: []
75
79
  rubyforge_project:
76
- rubygems_version: 1.8.15
80
+ rubygems_version: 2.0.3
77
81
  signing_key:
78
- specification_version: 3
82
+ specification_version: 4
79
83
  summary: douban.fm
80
84
  test_files: []
81
85
  has_rdoc: