MDowloader 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f6180e66d5da619cc12714965491eca1fc8345e
4
+ data.tar.gz: efbb2d4647def2789bcb2fbb828192ae0a114b4a
5
+ SHA512:
6
+ metadata.gz: b72e54f763d3d70f796efcb1804b73e9c6c6b0f1f072f02f02d88f37ba7732f352a28caf4fab93f928f7fcdc4f63e4690d14f14cea5d5da6f7d210495064308f
7
+ data.tar.gz: f2fe27335d6c67fd0ca18bd8c0615dc4c8d1b512c23b96796ed91f53fd33eb70352e3c94ef1b9ad1ad8f3fe3b93ed633d596fc1a7d5e8a86bfc3c71d0e0da5c0
data/.gitignore ADDED
@@ -0,0 +1,42 @@
1
+ # Ignore bundler config
2
+ /.bundle
3
+
4
+ # Ignore the default SQLite database.
5
+ /db/*.db
6
+
7
+ # Ignore all logfiles and tempfiles.
8
+ /log.txt
9
+ /tmp
10
+ /monitor/downloads
11
+ /lib/assets/barcode.png
12
+
13
+ /db/schema.rb
14
+
15
+ .idea
16
+ .DS_Store
17
+ Thumbs.db
18
+ .cache
19
+ .project
20
+ .settings
21
+ .tmproj
22
+ *.esproj
23
+ nbproject
24
+
25
+ .sass-cache/
26
+ backups/*
27
+
28
+ .rvmrc
29
+ .rbenv-version
30
+
31
+ nohup.out
32
+
33
+ # compile in here
34
+ /public/assets/*
35
+
36
+ /config/database.yml
37
+
38
+ coverage/*
39
+
40
+ /public/statics/*
41
+
42
+ rails_best_practices_output.html
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in MDowloader.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ MDowloader (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.1.1)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ MDowloader!
16
+ bundler (~> 1.5)
17
+ rake
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 RaymondChou
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.
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'MDowloader/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "MDowloader"
8
+ spec.version = MDowloader::VERSION
9
+ spec.authors = ["RaymondChou"]
10
+ spec.email = ["freezestart@gmail.com"]
11
+ spec.summary = %q{Ruby downloader}
12
+ spec.description = %q{Ruby downloader}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_development_dependency "bundler", "~> 0"
22
+ spec.add_development_dependency "rake"
23
+ end
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # MDowloader
2
+
3
+ 简单易用的下载工具,支持断点续传,支持下载进度块回调,失败重试等下载异常,适用于对文件下载稳定性要求高的系统及大文件下载。
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'MDowloader'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install MDowloader
18
+
19
+ ## Usage
20
+ url = 'http://download.corenetworks.net/50MB-testfile.zip'
21
+ path = '~/testfile.zip'
22
+
23
+ options = Hash.new
24
+ options[:retry] = :any #retry times, :any(any times retry), 0(no retry), or custom numbers(int)
25
+ options[:resume] = true #true or false, resume continue download, break point resume download
26
+
27
+ result, error = MDownloader.download(url, path, options) do |report|
28
+ puts "Progress:#{report[:percent]} Lave:#{report[:min]}m#{report[:sec]}"
29
+ end
30
+
31
+ if result
32
+ puts 'Download Finished!'
33
+ else
34
+ puts 'Download Error!'
35
+ puts error
36
+ end
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it ( http://github.com/<my-github-username>/MDowloader/fork )
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/MDowloader.rb ADDED
@@ -0,0 +1,61 @@
1
+ require "MDowloader/version"
2
+
3
+ module MDowloader
4
+
5
+ def download(url, path, options = {}, &block)
6
+ check_wget
7
+
8
+ resume_cmd = options[:resume] ? '-c' : ''
9
+
10
+ if options[:retry] == 0
11
+ retry_cmd = ''
12
+
13
+ elsif options[:retry] == :any
14
+ retry_cmd = '-t 0'
15
+
16
+ elsif options[:retry].is_a? Numeric
17
+ retry_cmd = "-t #{options[:retry]}"
18
+
19
+ else
20
+ raise Exception.new('Unknown retry option')
21
+
22
+ end
23
+
24
+ begin
25
+ IO.popen("wget #{resume_cmd} #{retry_cmd} -O #{path} #{url} 2>&1", "r") do |pipe|
26
+ pipe.each do |line|
27
+ result = Hash.new
28
+ match_pre = line.match(/ (\d{1,})% /)
29
+ unless match_pre.nil?
30
+ result[:percent] = match_pre[1]
31
+
32
+ match_s = line.match(/(\d{1,})s/)
33
+ unless match_s.nil?
34
+ result[:sec] = match_s[1]
35
+ match_m = line.match(/ (\d{1,})m/)
36
+ unless match_m.nil?
37
+ result[:min] = match_m[1]
38
+ end
39
+ end
40
+
41
+ else
42
+ if line.include?('saved')
43
+ return true, nil
44
+ end
45
+ end
46
+
47
+ block.call result
48
+ end
49
+ end
50
+
51
+ rescue => err
52
+ return false, err
53
+ end
54
+
55
+ end
56
+
57
+ def check_wget
58
+ raise Exception.new('Wget not found. Please install it.') if `which wget`.empty?
59
+ end
60
+
61
+ end
@@ -0,0 +1,3 @@
1
+ module MDowloader
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: MDowloader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - RaymondChou
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Ruby downloader
42
+ email:
43
+ - freezestart@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - LICENSE.txt
52
+ - MDowloader.gemspec
53
+ - README.md
54
+ - Rakefile
55
+ - lib/MDowloader.rb
56
+ - lib/MDowloader/version.rb
57
+ homepage: ''
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.2.1
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Ruby downloader
81
+ test_files: []