xmfun 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.hound.yml +4 -0
- data/.ruby-version +1 -0
- data/.travis.yml +16 -0
- data/Gemfile +2 -0
- data/README.md +21 -11
- data/Rakefile +9 -3
- data/bin/xmfun +1 -12
- data/lib/xmfun.rb +3 -18
- data/lib/xmfun/cli.rb +50 -0
- data/lib/xmfun/mp3/mp3_tagger.rb +15 -3
- data/lib/xmfun/util/decoder.rb +3 -1
- data/lib/xmfun/util/downloader.rb +80 -0
- data/lib/xmfun/util/helper.rb +40 -0
- data/lib/xmfun/version.rb +1 -1
- metadata +67 -12
- data/.rspec +0 -2
- data/lib/xmfun/downloader.rb +0 -78
- data/spec/spec_helper.rb +0 -19
- data/spec/xmfun/decode_spec.rb +0 -26
- data/xmfun.gemspec +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de89583de84a2110acc2701dd3db6fbd0d3ca430
|
4
|
+
data.tar.gz: 6dd726088e668911d797cdd1123b51d369ed6469
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e94f58c108707782a0ad8f33ab730cfeae0439a8323c14b09342e8794025b11a0c3dc6a20c6723ce0c23924b34131d5f005a1b0432a8c95d68568b906d40ef36
|
7
|
+
data.tar.gz: 9332f94f499ce495d44c1b536d1aaf6b50006d48c7e2b2ab3f19fbf06f4bfa3f4d1a4ccbab2925c2632bbe577f44b2069f18d4a692bef570d2fb291d9bc74475
|
data/.gitignore
CHANGED
data/.hound.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.2
|
data/.travis.yml
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
+
- ruby-head
|
3
4
|
- 2.1.2
|
4
5
|
- 2.0.0
|
5
6
|
- 1.9.3
|
7
|
+
- jruby
|
8
|
+
- rbx
|
9
|
+
matrix:
|
10
|
+
allow_failures:
|
11
|
+
- rvm: jruby
|
12
|
+
- rvm: rbx
|
13
|
+
- rvm: ruby-head
|
14
|
+
notifications:
|
15
|
+
webhooks:
|
16
|
+
urls:
|
17
|
+
- https://webhooks.gitter.im/e/2a376ca4981aeb2a81ca
|
18
|
+
on_success: change # options: [always|never|change] default: always
|
19
|
+
on_failure: always # options: [always|never|change] default: always
|
20
|
+
on_start: false # default: false
|
21
|
+
script: CODECLIMATE_REPO_TOKEN=d819a1100b1567adf763b9f6b0e1af83dcb59a4bf5c3534748ed32e3bb6818f4 bundle exec rake
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# XMfun
|
2
|
-
[![Gem
|
3
|
-
|
4
|
-
[![
|
5
|
-
|
6
|
-
[![
|
7
|
-
Climate](https://codeclimate.com/github/ipmsteven/xmfun/badges/gpa.svg)](https://codeclimate.com/github/ipmsteven/xmfun)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/xmfun.svg)](http://badge.fury.io/rb/xmfun)
|
3
|
+
[![Build Status](https://travis-ci.org/xmfun/xmfun.svg?branch=master)](https://travis-ci.org/xmfun/xmfun)
|
4
|
+
[![Test Coverage](https://codeclimate.com/github/ipmsteven/xmfun/badges/coverage.svg)](https://codeclimate.com/github/ipmsteven/xmfun)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/ipmsteven/xmfun/badges/gpa.svg)](https://codeclimate.com/github/ipmsteven/xmfun)
|
6
|
+
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/ipmsteven/xmfun?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
8
7
|
|
9
8
|
Yet Another Xiami Music Downloader
|
10
9
|
|
@@ -27,11 +26,22 @@ Or install it yourself as:
|
|
27
26
|
## Usage
|
28
27
|
|
29
28
|
```
|
30
|
-
xmfun
|
31
|
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
|
29
|
+
Usage: xmfun <command> [<args>]
|
30
|
+
|
31
|
+
-v, --version Print the version
|
32
|
+
-h, --help Print this help
|
33
|
+
|
34
|
+
Common commands:
|
35
|
+
download Download the mp3 files given an arg of url
|
36
|
+
update Update xmfun to the newest version
|
37
|
+
version Print the version
|
38
|
+
help Print this help
|
39
|
+
|
40
|
+
Example:
|
41
|
+
xmfun download http://www.xiami.com/song/3378080
|
42
|
+
|
43
|
+
More info:
|
44
|
+
xmfun <command> -h
|
35
45
|
```
|
36
46
|
|
37
47
|
## Contributing
|
data/Rakefile
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'cucumber'
|
4
|
+
require 'cucumber/rake/task'
|
3
5
|
|
4
6
|
RSpec::Core::RakeTask.new(:spec)
|
5
7
|
|
6
|
-
|
8
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
9
|
+
t.cucumber_opts = "--format pretty"
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => [:spec, :features]
|
7
13
|
|
8
14
|
task :console do
|
9
15
|
exec "pry -r xmfun -I ./lib"
|
data/bin/xmfun
CHANGED
@@ -1,15 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'clap'
|
4
2
|
require 'xmfun'
|
5
3
|
|
6
|
-
|
7
|
-
dst = '.'
|
8
|
-
|
9
|
-
Clap.run ARGV,
|
10
|
-
"-u" => lambda { |xm_url| url = Xmfun::Util::UrlParser.parse(xm_url) },
|
11
|
-
"-d" => lambda { |d| dst = d },
|
12
|
-
"-v" => lambda { puts Xmfun::VERSION },
|
13
|
-
"-h" => lambda { puts Xmfun.help }
|
14
|
-
|
15
|
-
Xmfun::Downloader.download(url, dst) unless url.empty?
|
4
|
+
Xmfun::CLI.start(ARGV)
|
data/lib/xmfun.rb
CHANGED
@@ -5,21 +5,6 @@ require 'xmfun/mp3/track'
|
|
5
5
|
require 'xmfun/mp3/mp3_tagger'
|
6
6
|
require 'xmfun/util/url_parser'
|
7
7
|
require 'xmfun/util/decoder'
|
8
|
-
require 'xmfun/downloader'
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
module Xmfun
|
13
|
-
def self.help
|
14
|
-
<<-HELP
|
15
|
-
Usage: ruby xmfun.rb
|
16
|
-
-u url -- url on xiami website
|
17
|
-
-d path -- path to save your music
|
18
|
-
-v -- show version
|
19
|
-
-h -- show help message
|
20
|
-
|
21
|
-
Example: Download song from "http://www.xiami.com/song/383221" and save to 'xuwei' folder
|
22
|
-
xmfun -u http://www.xiami.com/song/383221 -d xuwei
|
23
|
-
HELP
|
24
|
-
end
|
25
|
-
end
|
8
|
+
require 'xmfun/util/downloader'
|
9
|
+
require 'xmfun/util/helper'
|
10
|
+
require 'xmfun/cli'
|
data/lib/xmfun/cli.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
require 'clap'
|
4
|
+
|
5
|
+
module Xmfun
|
6
|
+
class CLI
|
7
|
+
extend Xmfun::Util::Helper
|
8
|
+
|
9
|
+
def self.start(argv)
|
10
|
+
if argv.empty?
|
11
|
+
puts main_help
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
|
15
|
+
url = ''
|
16
|
+
dst = '.'
|
17
|
+
|
18
|
+
download_proc = lambda do |option|
|
19
|
+
if option == '-h'
|
20
|
+
puts download_help
|
21
|
+
else
|
22
|
+
unless(url = Xmfun::Util::UrlParser.parse(option))
|
23
|
+
puts "\e[31mPlease provide valid URL\e[0m"
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
Clap.run argv,
|
31
|
+
"download" => download_proc,
|
32
|
+
"update" => lambda { system("gem update xmfun") },
|
33
|
+
"help" => lambda { puts main_help; exit },
|
34
|
+
"--help" => lambda { puts main_help; exit },
|
35
|
+
"version" => lambda { puts Xmfun::VERSION; exit },
|
36
|
+
"--version" => lambda { puts Xmfun::VERSION; exit },
|
37
|
+
|
38
|
+
"-u" => lambda { |xmurl| url = Xmfun::Util::UrlParser.parse(xm_url) },
|
39
|
+
"-v" => lambda { puts Xmfun::VERSION; exit},
|
40
|
+
"-h" => lambda { puts main_help; exit},
|
41
|
+
"-d" => lambda { |d| dst = d }
|
42
|
+
rescue ArgumentError
|
43
|
+
puts "\e[31mInvalid Usage\e[0m"
|
44
|
+
puts main_help
|
45
|
+
end
|
46
|
+
|
47
|
+
Xmfun::Util::Downloader.download(url, dst) unless url.empty?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/xmfun/mp3/mp3_tagger.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "open-uri"
|
4
|
+
require "mp3info"
|
5
|
+
require "cgi"
|
5
6
|
|
6
7
|
module Xmfun
|
7
8
|
module Mp3
|
@@ -12,10 +13,21 @@ module Xmfun
|
|
12
13
|
m.tag.title = track.title
|
13
14
|
m.tag.album = track.album
|
14
15
|
|
16
|
+
m.tag2["USLT"] = get_lyric(track.lyric)
|
15
17
|
m.tag2.remove_pictures
|
16
|
-
m.tag2.add_picture(
|
18
|
+
m.tag2.add_picture(get_data(track.album_pic))
|
17
19
|
end
|
18
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def self.get_lyric(url)
|
25
|
+
CGI.unescapeHTML(get_data(url)).force_encoding("UTF-8")
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.get_data(url)
|
29
|
+
open(url).read rescue ''
|
30
|
+
end
|
19
31
|
end
|
20
32
|
end
|
21
33
|
end
|
data/lib/xmfun/util/decoder.rb
CHANGED
@@ -0,0 +1,80 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
require 'open-uri'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'nori'
|
6
|
+
require 'parallel'
|
7
|
+
require 'ruby-progressbar'
|
8
|
+
|
9
|
+
module Xmfun
|
10
|
+
module Util
|
11
|
+
class Downloader
|
12
|
+
def self.download(url, dst = ".")
|
13
|
+
make_dst(dst)
|
14
|
+
|
15
|
+
tracks = Nokogiri::XML(open(url, "Client-IP" => "220.181.111.168")).css("track")
|
16
|
+
|
17
|
+
if tracks.size > 1
|
18
|
+
download_collect(tracks)
|
19
|
+
else
|
20
|
+
download_song(tracks[0])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def self.make_dst(dst)
|
26
|
+
if Dir.exist?(dst)
|
27
|
+
Dir.chdir(dst)
|
28
|
+
else
|
29
|
+
Dir.mkdir(dst)
|
30
|
+
Dir.chdir(dst)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.make_progress_bar(size)
|
35
|
+
ProgressBar.create( :title => "Progress",
|
36
|
+
:total => size,
|
37
|
+
:format => '%a %bᗧ%i %p%% %t',
|
38
|
+
:progress_mark => ' ',
|
39
|
+
:remainder_mark => '・' )
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.download_collect(collect)
|
43
|
+
progress = make_progress_bar(collect.size)
|
44
|
+
|
45
|
+
Parallel.map( collect, :in_threads => Parallel.processor_count, :finish => lambda { |item, i, result| progress.increment } ) do |track|
|
46
|
+
|
47
|
+
track = Xmfun::Mp3::Track.new(Nori.new.parse(track.to_s)['track'])
|
48
|
+
|
49
|
+
URI.parse(track.location).open do |f|
|
50
|
+
File.open(track.file_name, 'w') { |mp3| mp3.write(f.read) }
|
51
|
+
end
|
52
|
+
|
53
|
+
Xmfun::Mp3::Mp3Tagger.tag(track)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.download_song(song)
|
58
|
+
track = Xmfun::Mp3::Track.new(Nori.new.parse(song.to_s)['track'])
|
59
|
+
progress = nil
|
60
|
+
|
61
|
+
content_length_lambda = lambda do |content_length|
|
62
|
+
if content_length && 0 < content_length
|
63
|
+
progress = make_progress_bar content_length
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
progress_lambda = lambda { |size| progress.progress = size if progress }
|
68
|
+
|
69
|
+
uri = URI.parse(track.location)
|
70
|
+
|
71
|
+
uri.open( :content_length_proc => content_length_lambda,
|
72
|
+
:progress_proc => progress_lambda ) do |f|
|
73
|
+
File.open(track.file_name, 'w') { |mp3| mp3.write(f.read) }
|
74
|
+
end
|
75
|
+
|
76
|
+
Xmfun::Mp3::Mp3Tagger.tag(track)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module Xmfun
|
4
|
+
module Util
|
5
|
+
module Helper
|
6
|
+
def main_help
|
7
|
+
<<-EOS
|
8
|
+
Usage: xmfun <command> [<args>]
|
9
|
+
|
10
|
+
-v, --version Print the version
|
11
|
+
-h, --help Print this help
|
12
|
+
|
13
|
+
Common commands:
|
14
|
+
download Download the mp3 files given an arg of url
|
15
|
+
update Update xmfun to the newest version
|
16
|
+
version Print the version
|
17
|
+
help Print this help
|
18
|
+
|
19
|
+
Example:
|
20
|
+
xmfun download http://www.xiami.com/song/3378080
|
21
|
+
|
22
|
+
More info:
|
23
|
+
xmfun <command> -h
|
24
|
+
EOS
|
25
|
+
end
|
26
|
+
|
27
|
+
def download_help
|
28
|
+
<<-EOS
|
29
|
+
Usage:
|
30
|
+
xmfun download URL
|
31
|
+
xmfun download URL -d DESINATION_FOLDER
|
32
|
+
|
33
|
+
Example:
|
34
|
+
xmfun download http://www.xiami.com/song/3378080
|
35
|
+
xmfun download http://www.xiami.com/song/3378080 -d pink
|
36
|
+
EOS
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/xmfun/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xmfun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ipmsteven
|
8
|
+
- Polo
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-
|
12
|
+
date: 2014-10-03 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: clap
|
@@ -72,14 +73,14 @@ dependencies:
|
|
72
73
|
requirements:
|
73
74
|
- - "~>"
|
74
75
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.8.
|
76
|
+
version: 0.8.5
|
76
77
|
type: :runtime
|
77
78
|
prerelease: false
|
78
79
|
version_requirements: !ruby/object:Gem::Requirement
|
79
80
|
requirements:
|
80
81
|
- - "~>"
|
81
82
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.8.
|
83
|
+
version: 0.8.5
|
83
84
|
- !ruby/object:Gem::Dependency
|
84
85
|
name: activesupport
|
85
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +165,62 @@ dependencies:
|
|
164
165
|
- - "~>"
|
165
166
|
- !ruby/object:Gem::Version
|
166
167
|
version: 0.10.0
|
168
|
+
- !ruby/object:Gem::Dependency
|
169
|
+
name: webmock
|
170
|
+
requirement: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - "~>"
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: 1.18.0
|
175
|
+
type: :development
|
176
|
+
prerelease: false
|
177
|
+
version_requirements: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - "~>"
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: 1.18.0
|
182
|
+
- !ruby/object:Gem::Dependency
|
183
|
+
name: vcr
|
184
|
+
requirement: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - "~>"
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: 2.9.3
|
189
|
+
type: :development
|
190
|
+
prerelease: false
|
191
|
+
version_requirements: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - "~>"
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: 2.9.3
|
196
|
+
- !ruby/object:Gem::Dependency
|
197
|
+
name: aruba
|
198
|
+
requirement: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - "~>"
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: 0.6.1
|
203
|
+
type: :development
|
204
|
+
prerelease: false
|
205
|
+
version_requirements: !ruby/object:Gem::Requirement
|
206
|
+
requirements:
|
207
|
+
- - "~>"
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: 0.6.1
|
210
|
+
- !ruby/object:Gem::Dependency
|
211
|
+
name: cucumber
|
212
|
+
requirement: !ruby/object:Gem::Requirement
|
213
|
+
requirements:
|
214
|
+
- - "~>"
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: 1.3.17
|
217
|
+
type: :development
|
218
|
+
prerelease: false
|
219
|
+
version_requirements: !ruby/object:Gem::Requirement
|
220
|
+
requirements:
|
221
|
+
- - "~>"
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
version: 1.3.17
|
167
224
|
- !ruby/object:Gem::Dependency
|
168
225
|
name: pry-byebug
|
169
226
|
requirement: !ruby/object:Gem::Requirement
|
@@ -187,7 +244,8 @@ extensions: []
|
|
187
244
|
extra_rdoc_files: []
|
188
245
|
files:
|
189
246
|
- ".gitignore"
|
190
|
-
- ".
|
247
|
+
- ".hound.yml"
|
248
|
+
- ".ruby-version"
|
191
249
|
- ".travis.yml"
|
192
250
|
- Gemfile
|
193
251
|
- LICENSE.txt
|
@@ -195,15 +253,14 @@ files:
|
|
195
253
|
- Rakefile
|
196
254
|
- bin/xmfun
|
197
255
|
- lib/xmfun.rb
|
198
|
-
- lib/xmfun/
|
256
|
+
- lib/xmfun/cli.rb
|
199
257
|
- lib/xmfun/mp3/mp3_tagger.rb
|
200
258
|
- lib/xmfun/mp3/track.rb
|
201
259
|
- lib/xmfun/util/decoder.rb
|
260
|
+
- lib/xmfun/util/downloader.rb
|
261
|
+
- lib/xmfun/util/helper.rb
|
202
262
|
- lib/xmfun/util/url_parser.rb
|
203
263
|
- lib/xmfun/version.rb
|
204
|
-
- spec/spec_helper.rb
|
205
|
-
- spec/xmfun/decode_spec.rb
|
206
|
-
- xmfun.gemspec
|
207
264
|
homepage: https://github.com/ipmsteven/xmfun
|
208
265
|
licenses:
|
209
266
|
- MIT
|
@@ -228,6 +285,4 @@ rubygems_version: 2.2.2
|
|
228
285
|
signing_key:
|
229
286
|
specification_version: 4
|
230
287
|
summary: Yet another xiami music downloader
|
231
|
-
test_files:
|
232
|
-
- spec/spec_helper.rb
|
233
|
-
- spec/xmfun/decode_spec.rb
|
288
|
+
test_files: []
|
data/.rspec
DELETED
data/lib/xmfun/downloader.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
|
3
|
-
require 'open-uri'
|
4
|
-
require 'nokogiri'
|
5
|
-
require 'nori'
|
6
|
-
require 'parallel'
|
7
|
-
require 'ruby-progressbar'
|
8
|
-
|
9
|
-
module Xmfun
|
10
|
-
class Downloader
|
11
|
-
def self.download(url, dst)
|
12
|
-
make_dst(dst)
|
13
|
-
|
14
|
-
tracks = Nokogiri::XML(open(url, "Client-IP" => "220.181.111.168")).css("track")
|
15
|
-
|
16
|
-
if tracks.size > 1
|
17
|
-
download_collect(tracks)
|
18
|
-
else
|
19
|
-
download_song(tracks[0])
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
def self.make_dst(dst)
|
25
|
-
if Dir.exist?(dst)
|
26
|
-
Dir.chdir(dst)
|
27
|
-
else
|
28
|
-
Dir.mkdir(dst)
|
29
|
-
Dir.chdir(dst)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.make_progress_bar(size)
|
34
|
-
ProgressBar.create( :title => "Progress",
|
35
|
-
:total => size,
|
36
|
-
:format => '%a %bᗧ%i %p%% %t',
|
37
|
-
:progress_mark => ' ',
|
38
|
-
:remainder_mark => '・' )
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.download_collect(collect)
|
42
|
-
progress = make_progress_bar(collect.size)
|
43
|
-
|
44
|
-
Parallel.map( collect, :in_threads => Parallel.processor_count, :finish => lambda { |item, i, result| progress.increment } ) do |track|
|
45
|
-
|
46
|
-
track = Xmfun::Mp3::Track.new(Nori.new.parse(track.to_s)['track'])
|
47
|
-
|
48
|
-
URI.parse(track.location).open do |f|
|
49
|
-
File.open(track.file_name, 'w') { |mp3| mp3.write(f.read) }
|
50
|
-
end
|
51
|
-
|
52
|
-
Xmfun::Mp3::Mp3Tagger.tag(track)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.download_song(song)
|
57
|
-
track = Xmfun::Mp3::Track.new(Nori.new.parse(song.to_s)['track'])
|
58
|
-
progress = nil
|
59
|
-
|
60
|
-
content_length_lambda = lambda do |content_length|
|
61
|
-
if content_length && 0 < content_length
|
62
|
-
progress = make_progress_bar content_length
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
progress_lambda = lambda { |size| progress.progress = size if progress }
|
67
|
-
|
68
|
-
uri = URI.parse(track.location)
|
69
|
-
|
70
|
-
uri.open( :content_length_proc => content_length_lambda,
|
71
|
-
:progress_proc => progress_lambda ) do |f|
|
72
|
-
File.open(track.file_name, 'w') { |mp3| mp3.write(f.read) }
|
73
|
-
end
|
74
|
-
|
75
|
-
Xmfun::Mp3::Mp3Tagger.tag(track)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require 'xmfun'
|
3
|
-
|
4
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
5
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
6
|
-
# Require this file using `require "spec_helper"` to ensure that it is only
|
7
|
-
# loaded once.
|
8
|
-
#
|
9
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
10
|
-
RSpec.configure do |config|
|
11
|
-
config.run_all_when_everything_filtered = true
|
12
|
-
config.filter_run :focus
|
13
|
-
|
14
|
-
# Run specs in random order to surface order dependencies. If you find an
|
15
|
-
# order dependency and want to debug it, you can fix the order by providing
|
16
|
-
# the seed, which is printed after each run.
|
17
|
-
# --seed 1234
|
18
|
-
config.order = 'random'
|
19
|
-
end
|
data/spec/xmfun/decode_spec.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
module Xmfun
|
5
|
-
describe Util::Decoder do
|
6
|
-
before do
|
7
|
-
@decoder = Xmfun::Util::Decoder
|
8
|
-
end
|
9
|
-
|
10
|
-
it "#should return a decoded url" do
|
11
|
-
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"
|
12
|
-
url = "http://m5.file.xiami.com/1/169/7169/320390/3562717_365342_l.mp3?auth_key=30dc8ee47200ee626fdc2eadac2e3fb8-1407888000-0-null"
|
13
|
-
expect(@decoder.decode(location)).to eq(url)
|
14
|
-
|
15
|
-
location = "10h%i5F1t2.%18tFn23.pfeF2m%1t11p3.%183Ax23_%iF312a3%3Fm522"
|
16
|
-
url = "http://f1.xiami.net/355/1133/13218_13218.mp3"
|
17
|
-
expect(@decoder.decode(location)).to eq(url)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "#should raise an error when decoding an invalid url" do
|
21
|
-
location = "this_is_invalid_url"
|
22
|
-
expect_msg = "invalid input #{location}"
|
23
|
-
expect { @decoder.decode(location) }.to raise_error(ArgumentError, expect_msg)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/xmfun.gemspec
DELETED
@@ -1,36 +0,0 @@
|
|
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 "nori", "~> 2.4.0"
|
23
|
-
spec.add_dependency "nokogiri", "~> 1.6.3.1"
|
24
|
-
spec.add_dependency "parallel", "~> 1.2.2"
|
25
|
-
spec.add_dependency "ruby-mp3info", "~> 0.8.4"
|
26
|
-
spec.add_dependency "activesupport", "~> 4.1.5"
|
27
|
-
spec.add_dependency "ruby-progressbar", "~> 1.5.1"
|
28
|
-
|
29
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
30
|
-
spec.add_development_dependency "rake", "~> 10.3.2"
|
31
|
-
spec.add_development_dependency "rspec", "~> 3.0.0"
|
32
|
-
spec.add_development_dependency "pry", "~> 0.10.0"
|
33
|
-
if RUBY_VERSION =~ /^2\./
|
34
|
-
spec.add_development_dependency "pry-byebug", "~> 1.3.3"
|
35
|
-
end
|
36
|
-
end
|