lizhi-fm 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/README.md +1 -0
- data/bin/lizhi +14 -0
- data/lib/lizhi-fm.rb +1 -0
- data/lib/lizhi-fm/downloader.rb +75 -0
- data/lib/version.rb +3 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 36885e8b301880aaea2c1d39a67528a5662583d6
|
4
|
+
data.tar.gz: 8a364be3b9bdc3f4a79970049bcf0b82130be350
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f0f8c211d801cff1ecf1a4ac3a447e57f7d48ec733ec4238c152fe784e1f6b797c6679db24e76ee7111669cb5230ffc2a341234a37086c338adbcd4c5ef4a855
|
7
|
+
data.tar.gz: 10a714f32bb1c7a130ebfcf47de0497eb4dfad6451f389ea8d6787f7a047420dd41cc296b67970850c8cf4ffc7cdb8d818afa31be9fbb166b610e8d6ecacde0f
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Download music from http://www.lizhi.fm/ in one go!
|
data/bin/lizhi
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'lizhi-fm'
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
class LizhiFmCLI < Thor
|
7
|
+
desc "download <yaml>", "Download the mp3 according to the yaml file"
|
8
|
+
option :yaml
|
9
|
+
def download(yaml)
|
10
|
+
LizhiFm::Downloader.new(yaml).start
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
LizhiFmCLI.start(ARGV)
|
data/lib/lizhi-fm.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'lizhi-fm/downloader'
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'digest'
|
3
|
+
require 'rest-client'
|
4
|
+
|
5
|
+
module LizhiFm
|
6
|
+
class Downloader
|
7
|
+
def initialize(resource)
|
8
|
+
raise "File '#{resource}' doesn't exist!" unless File.exist?(resource)
|
9
|
+
|
10
|
+
@config = YAML::load(File.open(resource))
|
11
|
+
raise "Invalid yaml file: '#{resource}'" unless @config
|
12
|
+
|
13
|
+
if @config['headers'].nil?
|
14
|
+
raise "Invalid format: missing 'headers' section in '#{resource}'"
|
15
|
+
end
|
16
|
+
|
17
|
+
if @config['resources'].nil?
|
18
|
+
raise "Invalid format: missing 'resources' section in '#{resource}'"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def start
|
23
|
+
headers = @config['headers']
|
24
|
+
|
25
|
+
failures = []
|
26
|
+
successes = {}
|
27
|
+
|
28
|
+
threads = []
|
29
|
+
urls = []
|
30
|
+
outputs = {}
|
31
|
+
@config['resources'].each do |resource|
|
32
|
+
destination = resource['name']
|
33
|
+
url = resource['url']
|
34
|
+
urls << url
|
35
|
+
|
36
|
+
threads << Thread.new do
|
37
|
+
outputs[url] = {}
|
38
|
+
|
39
|
+
# The server use 206 during transferring.
|
40
|
+
# Sometimes the response are incomplete.
|
41
|
+
# We download each file up to 10 times and
|
42
|
+
# save it once there are two identical
|
43
|
+
# results.
|
44
|
+
10.times do
|
45
|
+
response = RestClient.get(url, headers=headers)
|
46
|
+
md5 = Digest::SHA256.hexdigest response.body
|
47
|
+
|
48
|
+
if response.code != 200
|
49
|
+
print '-'
|
50
|
+
continue
|
51
|
+
end
|
52
|
+
|
53
|
+
if outputs[url].has_key?(md5)
|
54
|
+
file_name = File.join(Dir.pwd, destination)
|
55
|
+
File.write(file_name, response.body)
|
56
|
+
successes[url] = file_name
|
57
|
+
print '='
|
58
|
+
break
|
59
|
+
else
|
60
|
+
outputs[url][md5] = response.body
|
61
|
+
print '+'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
threads.each { |thr| thr.join }
|
67
|
+
|
68
|
+
urls.each do |url|
|
69
|
+
failures << url unless successes.has_key?(url)
|
70
|
+
end
|
71
|
+
|
72
|
+
{failures: failures, successes: successes}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lizhi-fm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Han
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.19'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.19'
|
41
|
+
description: Comamnd line tool to download your favourite mp3 from lizhi.fm.
|
42
|
+
email: hex0cter@gmail.com
|
43
|
+
executables:
|
44
|
+
- lizhi
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- README.md
|
49
|
+
- bin/lizhi
|
50
|
+
- lib/lizhi-fm.rb
|
51
|
+
- lib/lizhi-fm/downloader.rb
|
52
|
+
- lib/version.rb
|
53
|
+
homepage: http://rubygems.org/gems/lizhi-fm
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 2.1.0
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 2.2.5
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: Download mp3 from Lizhi.fm
|
77
|
+
test_files: []
|