xmfun 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +10 -0
- data/bin/xmfun +16 -0
- data/lib/xmfun.rb +21 -0
- data/lib/xmfun/decoder.rb +34 -0
- data/lib/xmfun/downloader.rb +48 -0
- data/lib/xmfun/version.rb +3 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/xmfun/decode_spec.rb +15 -0
- data/xmfun.gemspec +31 -0
- metadata +187 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dc921b2d64b591315ce9b88105e859b3bf335423
|
4
|
+
data.tar.gz: b7fffd8bf10c34c3cb85ecc217d2ff138d61a8a3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d69e949c50bd95c4ba5514170f530fdbe75be3d24e2a69956a839a2670807abc27e72e31a94da0b8ffc5cb39caf2005384efc8cda5af7b5549e2a4b95de294e3
|
7
|
+
data.tar.gz: 26d013a9edfef57fe389764de991f4c144bc316f557b3883a96f36f529e1803b7b39e7b951825a402eb4e21698be1c43979ff29cd048be5d9b26e2ead9924958
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 ipmsteven
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# XMfun
|
2
|
+
|
3
|
+
Yet Another Xiami Music Downloader
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'xmfun'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install xmfun
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```
|
24
|
+
xmfun
|
25
|
+
-c cid -- download a music collect
|
26
|
+
-s sid -- download a single song
|
27
|
+
-d path -- path to save your music
|
28
|
+
-v -- show version
|
29
|
+
-h -- show help message
|
30
|
+
```
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it ( https://github.com/ipmsteven/xmfun/fork )
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/xmfun
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'clap'
|
4
|
+
require 'xmfun'
|
5
|
+
|
6
|
+
url = ''
|
7
|
+
dst = '.'
|
8
|
+
|
9
|
+
Clap.run ARGV,
|
10
|
+
"-c" => lambda { |collect_id| url = "http://www.xiami.com/song/playlist/id/#{collect_id}/type/3" },
|
11
|
+
"-s" => lambda { |song_id| url = "http://www.xiami.com/song/playlist/id/#{song_id}/object_name/default/object_id/0" },
|
12
|
+
"-d" => lambda { |d| dst = d },
|
13
|
+
"-v" => lambda { puts Xmfun::VERSION },
|
14
|
+
"-h" => lambda { puts Xmfun.help }
|
15
|
+
|
16
|
+
Xmfun::Downloader.download(url, dst) unless url.empty?
|
data/lib/xmfun.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'xmfun/version'
|
2
|
+
require 'xmfun/decoder'
|
3
|
+
require 'xmfun/downloader'
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
module Xmfun
|
8
|
+
def self.help
|
9
|
+
<<-HELP
|
10
|
+
Usage: ruby xmfun.rb
|
11
|
+
-c cid -- download a music collect
|
12
|
+
-s sid -- download a single song
|
13
|
+
-d path -- path to save your music
|
14
|
+
-v -- show version
|
15
|
+
-h -- show help message
|
16
|
+
|
17
|
+
Example: Download Collect with ID 10181268 and save to current path
|
18
|
+
xmfun -c 10181268 -d .
|
19
|
+
HELP
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
module Xmfun
|
4
|
+
class Decoder
|
5
|
+
def self.decode(input)
|
6
|
+
text = input[1..-1]
|
7
|
+
row = input[0].to_i
|
8
|
+
col = text.size / row - 1
|
9
|
+
reminder = text.size % row
|
10
|
+
result = []
|
11
|
+
start = 0
|
12
|
+
|
13
|
+
row.times do |r|
|
14
|
+
if reminder == 0
|
15
|
+
result << text[start..(start+col)]
|
16
|
+
start = start + col + 1
|
17
|
+
else
|
18
|
+
result << text[start..(start+col+1)]
|
19
|
+
start = start + col + 2
|
20
|
+
end
|
21
|
+
if reminder != 0
|
22
|
+
reminder = reminder - 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
tmp = (0..(result[0].size-1)).to_a.map do |n|
|
27
|
+
result.map{|i| i[n]}.join
|
28
|
+
end.join
|
29
|
+
|
30
|
+
CGI::unescape(tmp).gsub('^', '0')
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'clap'
|
4
|
+
require 'mp3info'
|
5
|
+
require 'parallel'
|
6
|
+
require 'ruby-progressbar'
|
7
|
+
require 'xmfun/decoder'
|
8
|
+
|
9
|
+
module Xmfun
|
10
|
+
class Downloader
|
11
|
+
def self.download(url, dst)
|
12
|
+
|
13
|
+
if Dir.exist?(dst)
|
14
|
+
Dir.chdir(dst)
|
15
|
+
else
|
16
|
+
Dir.mkdir(dst)
|
17
|
+
Dir.chdir(dst)
|
18
|
+
end
|
19
|
+
|
20
|
+
f = Nokogiri::XML(open(url, "Client-IP" => "220.181.111.168"))
|
21
|
+
progress = ProgressBar.create(:title => "The Progress", :total => f.css("track").size )
|
22
|
+
Parallel.map(f.css("track"), :finish => lambda { |item, i, result| progress.increment }) do |track|
|
23
|
+
album = track.css('album_name').text
|
24
|
+
artist = track.css('artist').text
|
25
|
+
lyric = track.css('lyric').text
|
26
|
+
title = track.css('title').text
|
27
|
+
location = track.css('location').text
|
28
|
+
album_pic = track.css('album_pic').text
|
29
|
+
mp3 = Decoder.decode(location)
|
30
|
+
|
31
|
+
URI.parse(mp3).open do |f|
|
32
|
+
File.open("#{title}_#{artist}.mp3", 'w') { |mp3| mp3.write(f.read) }
|
33
|
+
end
|
34
|
+
|
35
|
+
# add mp3 meta info
|
36
|
+
Mp3Info.open "#{title}_#{artist}.mp3" do |m|
|
37
|
+
m.tag.artist = artist
|
38
|
+
m.tag.title = title
|
39
|
+
m.tag.album = album
|
40
|
+
|
41
|
+
m.tag2.remove_pictures
|
42
|
+
m.tag2.add_picture(open(album_pic).read)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'xmfun'
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
6
|
+
# loaded once.
|
7
|
+
#
|
8
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.run_all_when_everything_filtered = true
|
11
|
+
config.filter_run :focus
|
12
|
+
|
13
|
+
# Run specs in random order to surface order dependencies. If you find an
|
14
|
+
# order dependency and want to debug it, you can fix the order by providing
|
15
|
+
# the seed, which is printed after each run.
|
16
|
+
# --seed 1234
|
17
|
+
config.order = 'random'
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Xmfun
|
4
|
+
describe Decoder do
|
5
|
+
before do
|
6
|
+
@decoder = Xmfun::Decoder
|
7
|
+
@location = "8h2fmF%2956mtDe%fc185utFii12F%65ph3e5d24%Elt%l.%F35233_%4Ece%5-lp2ec272E74%k57e235E%%F.oF1%%123eE2eefE%53mxm16527_Fyd%6ab75EA5i%69EF_la%c52d88E-%.a29%333.u38E6a-8%n"
|
8
|
+
@url = "http://m5.file.xiami.com/1/169/7169/320390/3562717_365342_l.mp3?auth_key=30dc8ee47200ee626fdc2eadac2e3fb8-1407888000-0-null"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "#should return a decoded url" do
|
12
|
+
expect(@decoder.decode(@location)).to eq(@url)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/xmfun.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'xmfun/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "xmfun"
|
8
|
+
spec.version = Xmfun::VERSION
|
9
|
+
spec.authors = ["ipmsteven"]
|
10
|
+
spec.email = ["steven.lyl147@gmail.com"]
|
11
|
+
spec.description = %q{Yet another xiami music downloader}
|
12
|
+
spec.summary = %q{Yet another xiami music downloader}
|
13
|
+
spec.homepage = "https://github.com/ipmsteven/xmfun"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "clap", "~> 1.0.0"
|
22
|
+
spec.add_dependency "nokogiri", "~> 1.6.3.1"
|
23
|
+
spec.add_dependency "parallel", "~> 1.2.2"
|
24
|
+
spec.add_dependency "ruby-mp3info", "~> 0.8.4"
|
25
|
+
spec.add_dependency "ruby-progressbar", "~> 1.5.1"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.3.2"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0.0"
|
30
|
+
spec.add_development_dependency "pry", "~> 0.10.0"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xmfun
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ipmsteven
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: clap
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.6.3.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.6.3.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: parallel
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.2.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.2.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruby-mp3info
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.8.4
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.8.4
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: ruby-progressbar
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.5.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.5.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 10.3.2
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 10.3.2
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 3.0.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 3.0.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.10.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.10.0
|
139
|
+
description: Yet another xiami music downloader
|
140
|
+
email:
|
141
|
+
- steven.lyl147@gmail.com
|
142
|
+
executables:
|
143
|
+
- xmfun
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- ".gitignore"
|
148
|
+
- ".rspec"
|
149
|
+
- Gemfile
|
150
|
+
- LICENSE.txt
|
151
|
+
- README.md
|
152
|
+
- Rakefile
|
153
|
+
- bin/xmfun
|
154
|
+
- lib/xmfun.rb
|
155
|
+
- lib/xmfun/decoder.rb
|
156
|
+
- lib/xmfun/downloader.rb
|
157
|
+
- lib/xmfun/version.rb
|
158
|
+
- spec/spec_helper.rb
|
159
|
+
- spec/xmfun/decode_spec.rb
|
160
|
+
- xmfun.gemspec
|
161
|
+
homepage: https://github.com/ipmsteven/xmfun
|
162
|
+
licenses:
|
163
|
+
- MIT
|
164
|
+
metadata: {}
|
165
|
+
post_install_message:
|
166
|
+
rdoc_options: []
|
167
|
+
require_paths:
|
168
|
+
- lib
|
169
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
requirements: []
|
180
|
+
rubyforge_project:
|
181
|
+
rubygems_version: 2.2.2
|
182
|
+
signing_key:
|
183
|
+
specification_version: 4
|
184
|
+
summary: Yet another xiami music downloader
|
185
|
+
test_files:
|
186
|
+
- spec/spec_helper.rb
|
187
|
+
- spec/xmfun/decode_spec.rb
|