zhangmen 0.1.0 → 0.1.1

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/Gemfile.lock CHANGED
@@ -3,17 +3,22 @@ GEM
3
3
  specs:
4
4
  diff-lcs (1.1.2)
5
5
  git (1.2.5)
6
- jeweler (1.6.2)
6
+ jeweler (1.6.4)
7
7
  bundler (~> 1.0)
8
8
  git (>= 1.2.5)
9
9
  rake
10
- json (1.5.2)
11
- mechanize (1.0.0)
12
- nokogiri (>= 1.2.1)
13
- nokogiri (1.4.5)
10
+ json (1.5.3)
11
+ mechanize (2.0.1)
12
+ net-http-digest_auth (~> 1.1, >= 1.1.1)
13
+ net-http-persistent (~> 1.8)
14
+ nokogiri (~> 1.4)
15
+ webrobots (~> 0.0, >= 0.0.9)
16
+ net-http-digest_auth (1.1.1)
17
+ net-http-persistent (1.8)
18
+ nokogiri (1.5.0)
14
19
  rake (0.9.2)
15
20
  rcov (0.9.9)
16
- rdoc (3.6.1)
21
+ rdoc (3.8)
17
22
  rspec (2.6.0)
18
23
  rspec-core (~> 2.6.0)
19
24
  rspec-expectations (~> 2.6.0)
@@ -22,6 +27,8 @@ GEM
22
27
  rspec-expectations (2.6.0)
23
28
  diff-lcs (~> 1.1.2)
24
29
  rspec-mocks (2.6.0)
30
+ webrobots (0.0.10)
31
+ nokogiri (>= 1.4.4)
25
32
 
26
33
  PLATFORMS
27
34
  ruby
data/README.rdoc CHANGED
@@ -20,8 +20,26 @@ Or, if you're feeling undecided, grab the entire library.
20
20
 
21
21
  zhangmen all
22
22
 
23
+ Feeling lazy? Download the entire catalog.
24
+
25
+ zhangmen all
26
+
23
27
  The songs will be downloaded in the current directory. One directory will be made for each artist, and all that artist's songs will be saved there.
24
28
 
29
+ If you're not in Mainland China, you can use a proxy to get your music fix.
30
+
31
+ http_proxy=google.for.a.proxy:1234 zhangmen fetch 602
32
+
33
+ == Testing
34
+
35
+ The tests are written in RSpec. Run them like this.
36
+
37
+ rake spec
38
+
39
+ If you're not in Mainland China, set http_proxy so the downloading tests pass.
40
+
41
+ http_proxy=google.for.a.proxy:1234 rake spec
42
+
25
43
  == Known Issues
26
44
 
27
45
  Some songs might not download. The Flash player skips over those songs too, so it seems to be a server issue.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/lib/zhangmen/cli.rb CHANGED
@@ -103,7 +103,11 @@ class Cli
103
103
 
104
104
  # Runs a command.
105
105
  def run(args)
106
- @client = Zhangmen::Client.new
106
+ options = {}
107
+ if proxy_server = ENV['http_proxy'] || ENV['all_proxy']
108
+ options[:proxy] = proxy_server
109
+ end
110
+ @client = Zhangmen::Client.new options
107
111
  @client.cache = client_cache
108
112
 
109
113
  case args[0]
@@ -8,8 +8,12 @@ module Zhangmen
8
8
 
9
9
  # Wraps a client session for accessing Baidu's streaming music service.
10
10
  class Client
11
- def initialize
12
- @mech = mechanizer
11
+ # New client session.
12
+ #
13
+ # The options hash accepts the following keys:
14
+ # :proxy:: "host:port" string
15
+ def initialize(options = {})
16
+ @mech = mechanizer options
13
17
  @cache = {}
14
18
  end
15
19
 
@@ -144,9 +148,14 @@ class Client
144
148
  end
145
149
 
146
150
  # Mechanize instance customized to maximize fetch success.
147
- def mechanizer
151
+ def mechanizer(options = {})
148
152
  mech = Mechanize.new
149
153
  mech.user_agent_alias = 'Linux Firefox'
154
+ if options[:proxy]
155
+ host, _, port_str = *options[:proxy].rpartition(':')
156
+ port_str ||= 80
157
+ mech.set_proxy host, port_str.to_i
158
+ end
150
159
  mech
151
160
  end
152
161
  end # class Zhangmen::Client
@@ -2,7 +2,29 @@
2
2
  require File.expand_path('../../spec_helper', __FILE__)
3
3
 
4
4
  describe Zhangmen::Client do
5
- let(:client) { Zhangmen::Client.new }
5
+ describe 'mechanizer' do
6
+ let(:empty_client) { Zhangmen::Client.new }
7
+
8
+ it 'returns a Mechanize instance' do
9
+ empty_client.mechanizer.should be_kind_of(Mechanize)
10
+ end
11
+
12
+ describe 'with a proxy option' do
13
+ let(:mech) do
14
+ empty_client.mechanizer :proxy => '127.0.0.1:3306'
15
+ end
16
+
17
+ it 'parses the address correctly' do
18
+ mech.proxy_addr.should == '127.0.0.1'
19
+ end
20
+
21
+ it 'parses the port correctly' do
22
+ mech.proxy_port.should == 3306
23
+ end
24
+ end
25
+ end
26
+
27
+ let(:client) { Zhangmen::Client.new :proxy => ENV['http_proxy'] }
6
28
 
7
29
  describe 'op_url' do
8
30
  it 'encodes everything correctly' do
data/zhangmen.gemspec CHANGED
@@ -5,14 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{zhangmen}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Victor Costan}]
12
- s.date = %q{2011-07-09}
11
+ s.authors = ["Victor Costan"]
12
+ s.date = %q{2011-07-17}
13
+ s.default_executable = %q{zhangmen}
13
14
  s.description = %q{CLI and library for downloading music from Baidu}
14
15
  s.email = %q{victor@costan.us}
15
- s.executables = [%q{zhangmen}]
16
+ s.executables = ["zhangmen"]
16
17
  s.extra_rdoc_files = [
17
18
  "LICENSE.txt",
18
19
  "README.rdoc"
@@ -37,9 +38,9 @@ Gem::Specification.new do |s|
37
38
  "zhangmen.gemspec"
38
39
  ]
39
40
  s.homepage = %q{http://github.com/pwnall/zhangmen}
40
- s.licenses = [%q{MIT}]
41
- s.require_paths = [%q{lib}]
42
- s.rubygems_version = %q{1.8.5}
41
+ s.licenses = ["MIT"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.6.2}
43
44
  s.summary = %q{CLI and library for downloading music from Baidu}
44
45
 
45
46
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zhangmen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-09 00:00:00.000000000Z
12
+ date: 2011-07-17 00:00:00.000000000 -04:00
13
+ default_executable: zhangmen
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: json
16
- requirement: &26919700 !ruby/object:Gem::Requirement
17
+ requirement: &23012660 !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
20
  - - ! '>='
@@ -21,10 +22,10 @@ dependencies:
21
22
  version: '0'
22
23
  type: :runtime
23
24
  prerelease: false
24
- version_requirements: *26919700
25
+ version_requirements: *23012660
25
26
  - !ruby/object:Gem::Dependency
26
27
  name: mechanize
27
- requirement: &26919100 !ruby/object:Gem::Requirement
28
+ requirement: &23012160 !ruby/object:Gem::Requirement
28
29
  none: false
29
30
  requirements:
30
31
  - - ! '>='
@@ -32,10 +33,10 @@ dependencies:
32
33
  version: '0'
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *26919100
36
+ version_requirements: *23012160
36
37
  - !ruby/object:Gem::Dependency
37
38
  name: nokogiri
38
- requirement: &26918520 !ruby/object:Gem::Requirement
39
+ requirement: &23011680 !ruby/object:Gem::Requirement
39
40
  none: false
40
41
  requirements:
41
42
  - - ! '>='
@@ -43,10 +44,10 @@ dependencies:
43
44
  version: '0'
44
45
  type: :runtime
45
46
  prerelease: false
46
- version_requirements: *26918520
47
+ version_requirements: *23011680
47
48
  - !ruby/object:Gem::Dependency
48
49
  name: rdoc
49
- requirement: &26917940 !ruby/object:Gem::Requirement
50
+ requirement: &23011200 !ruby/object:Gem::Requirement
50
51
  none: false
51
52
  requirements:
52
53
  - - ! '>='
@@ -54,10 +55,10 @@ dependencies:
54
55
  version: 3.6.0
55
56
  type: :development
56
57
  prerelease: false
57
- version_requirements: *26917940
58
+ version_requirements: *23011200
58
59
  - !ruby/object:Gem::Dependency
59
60
  name: rspec
60
- requirement: &26917340 !ruby/object:Gem::Requirement
61
+ requirement: &23010720 !ruby/object:Gem::Requirement
61
62
  none: false
62
63
  requirements:
63
64
  - - ~>
@@ -65,10 +66,10 @@ dependencies:
65
66
  version: 2.6.0
66
67
  type: :development
67
68
  prerelease: false
68
- version_requirements: *26917340
69
+ version_requirements: *23010720
69
70
  - !ruby/object:Gem::Dependency
70
71
  name: bundler
71
- requirement: &26916760 !ruby/object:Gem::Requirement
72
+ requirement: &23010240 !ruby/object:Gem::Requirement
72
73
  none: false
73
74
  requirements:
74
75
  - - ~>
@@ -76,10 +77,10 @@ dependencies:
76
77
  version: 1.0.0
77
78
  type: :development
78
79
  prerelease: false
79
- version_requirements: *26916760
80
+ version_requirements: *23010240
80
81
  - !ruby/object:Gem::Dependency
81
82
  name: jeweler
82
- requirement: &26916200 !ruby/object:Gem::Requirement
83
+ requirement: &23009740 !ruby/object:Gem::Requirement
83
84
  none: false
84
85
  requirements:
85
86
  - - ~>
@@ -87,10 +88,10 @@ dependencies:
87
88
  version: 1.6.2
88
89
  type: :development
89
90
  prerelease: false
90
- version_requirements: *26916200
91
+ version_requirements: *23009740
91
92
  - !ruby/object:Gem::Dependency
92
93
  name: rcov
93
- requirement: &26915680 !ruby/object:Gem::Requirement
94
+ requirement: &23009220 !ruby/object:Gem::Requirement
94
95
  none: false
95
96
  requirements:
96
97
  - - ! '>='
@@ -98,7 +99,7 @@ dependencies:
98
99
  version: '0'
99
100
  type: :development
100
101
  prerelease: false
101
- version_requirements: *26915680
102
+ version_requirements: *23009220
102
103
  description: CLI and library for downloading music from Baidu
103
104
  email: victor@costan.us
104
105
  executables:
@@ -125,6 +126,7 @@ files:
125
126
  - spec/zhangmen/client_spec.rb
126
127
  - spec/zhangmen_spec.rb
127
128
  - zhangmen.gemspec
129
+ has_rdoc: true
128
130
  homepage: http://github.com/pwnall/zhangmen
129
131
  licenses:
130
132
  - MIT
@@ -140,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
142
  version: '0'
141
143
  segments:
142
144
  - 0
143
- hash: 1290430065827447959
145
+ hash: -1826109697642044863
144
146
  required_rubygems_version: !ruby/object:Gem::Requirement
145
147
  none: false
146
148
  requirements:
@@ -149,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
151
  version: '0'
150
152
  requirements: []
151
153
  rubyforge_project:
152
- rubygems_version: 1.8.5
154
+ rubygems_version: 1.6.2
153
155
  signing_key:
154
156
  specification_version: 3
155
157
  summary: CLI and library for downloading music from Baidu