xmfun 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/README.md +4 -0
- data/bin/xmfun +3 -2
- data/lib/xmfun.rb +5 -4
- data/lib/xmfun/decoder.rb +1 -0
- data/lib/xmfun/downloader.rb +8 -2
- data/lib/xmfun/url_parser.rb +26 -0
- data/lib/xmfun/version.rb +2 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/xmfun/decode_spec.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df82d030462552e3c7a46301507d42156b89637a
|
4
|
+
data.tar.gz: 39ba675bbb2705abe84821eea975a7ee0d79bd5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72e7421684f5b9373b24991f6b25d02deb136bbdc2320c5aa407e9dc9523c69bb3bc7ff7670ff8f806e47b2ee01b73a783bda09a3f7b706d3a23dc440fd2e8dd
|
7
|
+
data.tar.gz: 635a174bd39ee90121e14359384a65f6c66c08288a0b57c6b8dc64bcd12c3de4c73175283bbb1b157b16ee9535c2a02ad02a3b64a77d717747f17931f204c48b
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
# XMfun
|
2
|
+
[![Build
|
3
|
+
Status](https://travis-ci.org/ipmsteven/xmfun.svg?branch=master)](https://travis-ci.org/ipmsteven/xmfun)
|
4
|
+
[![Code
|
5
|
+
Climate](https://codeclimate.com/github/ipmsteven/xmfun/badges/gpa.svg)](https://codeclimate.com/github/ipmsteven/xmfun)
|
2
6
|
|
3
7
|
Yet Another Xiami Music Downloader
|
4
8
|
|
data/bin/xmfun
CHANGED
@@ -7,8 +7,9 @@ url = ''
|
|
7
7
|
dst = '.'
|
8
8
|
|
9
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" },
|
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
|
+
"-u" => lambda { |xm_url| url = Xmfun::UrlParser.parse(xm_url) },
|
12
13
|
"-d" => lambda { |d| dst = d },
|
13
14
|
"-v" => lambda { puts Xmfun::VERSION },
|
14
15
|
"-h" => lambda { puts Xmfun.help }
|
data/lib/xmfun.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require 'xmfun/version'
|
3
|
+
require 'xmfun/url_parser'
|
2
4
|
require 'xmfun/decoder'
|
3
5
|
require 'xmfun/downloader'
|
4
6
|
|
@@ -8,14 +10,13 @@ module Xmfun
|
|
8
10
|
def self.help
|
9
11
|
<<-HELP
|
10
12
|
Usage: ruby xmfun.rb
|
11
|
-
-
|
12
|
-
-s sid -- download a single song
|
13
|
+
-u url -- url on xiami website
|
13
14
|
-d path -- path to save your music
|
14
15
|
-v -- show version
|
15
16
|
-h -- show help message
|
16
17
|
|
17
|
-
Example: Download
|
18
|
-
xmfun -
|
18
|
+
Example: Download song from "http://www.xiami.com/song/383221" and save to 'xuwei' folder
|
19
|
+
xmfun -u http://www.xiami.com/song/383221 -d xuwei
|
19
20
|
HELP
|
20
21
|
end
|
21
22
|
end
|
data/lib/xmfun/decoder.rb
CHANGED
data/lib/xmfun/downloader.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require 'open-uri'
|
2
3
|
require 'nokogiri'
|
3
4
|
require 'clap'
|
@@ -18,8 +19,13 @@ module Xmfun
|
|
18
19
|
end
|
19
20
|
|
20
21
|
f = Nokogiri::XML(open(url, "Client-IP" => "220.181.111.168"))
|
21
|
-
progress = ProgressBar.create(:title => "
|
22
|
-
|
22
|
+
progress = ProgressBar.create( :title => "Progress",
|
23
|
+
:total => f.css("track").size,
|
24
|
+
:format => '%a %bᗧ%i %p%% %t',
|
25
|
+
:progress_mark => ' ',
|
26
|
+
:remainder_mark => '・'
|
27
|
+
)
|
28
|
+
Parallel.map( f.css("track"), :in_threads => Parallel.processor_count, :finish => lambda { |item, i, result| progress.increment } ) do |track|
|
23
29
|
album = track.css('album_name').text
|
24
30
|
artist = track.css('artist').text
|
25
31
|
lyric = track.css('lyric').text
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module Xmfun
|
4
|
+
class UrlParser
|
5
|
+
def self.parse(url)
|
6
|
+
if uri? url
|
7
|
+
url_array = url.split("//").last.split(/(\/|\?)/)
|
8
|
+
type, id = url_array[2], url_array[4]
|
9
|
+
|
10
|
+
case type
|
11
|
+
when "album" then "http://www.xiami.com/song/playlist/id/#{id}/type/1"
|
12
|
+
when "artist" then "http://www.xiami.com/song/playlist/id/#{id}/type/2"
|
13
|
+
when "collect" then "http://www.xiami.com/song/playlist/id/#{id}/type/3"
|
14
|
+
when "song" then "http://www.xiami.com/song/playlist/id/#{id}/object_name/default/object_id/0"
|
15
|
+
else ""
|
16
|
+
end
|
17
|
+
else
|
18
|
+
false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.uri?(uri)
|
23
|
+
uri =~ /\A#{URI::regexp(['http', 'https'])}\z/
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/xmfun/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/xmfun/decode_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ipmsteven
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clap
|
@@ -146,6 +146,7 @@ extra_rdoc_files: []
|
|
146
146
|
files:
|
147
147
|
- ".gitignore"
|
148
148
|
- ".rspec"
|
149
|
+
- ".travis.yml"
|
149
150
|
- Gemfile
|
150
151
|
- LICENSE.txt
|
151
152
|
- README.md
|
@@ -154,6 +155,7 @@ files:
|
|
154
155
|
- lib/xmfun.rb
|
155
156
|
- lib/xmfun/decoder.rb
|
156
157
|
- lib/xmfun/downloader.rb
|
158
|
+
- lib/xmfun/url_parser.rb
|
157
159
|
- lib/xmfun/version.rb
|
158
160
|
- spec/spec_helper.rb
|
159
161
|
- spec/xmfun/decode_spec.rb
|