yotsuba 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 068f3385ec421837d2f387fbc637b9777280b319
4
- data.tar.gz: 73d81300f15625bbd79ff4f28284f1c5e9f83b74
3
+ metadata.gz: 16007be3d5d092565144cf0cf084846a0b881ed6
4
+ data.tar.gz: 5ca4d65b96c42ff5ae3e5ca9217e38f742060929
5
5
  SHA512:
6
- metadata.gz: cbec9826839e3d3069a143b0376516e179c3af171d7b5c657ad2344993189a4cfa26ee316795bc3c352cda12822b9c0df89f4dcbf90632b144c54eed8c58e10c
7
- data.tar.gz: 3d00822f56699a562a87f1e771edebf0dece977623e1418e038e7a3325200b5e61d4cf6c5ba79d549df5ca34195246f3b58401301d64a87f7a59b36e5190b5e6
6
+ metadata.gz: 271b8be2a043ee6e55de1e323f36f34a4365e09d42674c535031a3654724d96f744306533e90e89590236d35d16fa3ea36b7de135a8306bbd6f458367ba79bad
7
+ data.tar.gz: 0443bc79d9f83bd72e445b1947aca5f17a94aa206cf44f13a7bc4abfe055f2a4abb35b32be25cb6447d85b9842292271d51fab105912c267315eedd2deabf694
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Yotsuba
1
+ # Yotsuba [![Gem Version](https://img.shields.io/gem/v/yotsuba.svg?style=flat-square)](https://rubygems.org/gems/yotsuba) [![Total number of downloads](https://img.shields.io/gem/dt/yotsuba.svg?style=flat-square)](https://rubygems.org/gems/yotsuba)
2
2
 
3
3
  Yotsuba facilitates getting download links from the DomDomSoft Anime Downloader server.
4
4
 
data/lib/yotsuba.rb CHANGED
@@ -5,4 +5,5 @@ require 'version'
5
5
  require 'serial'
6
6
  require 'anime'
7
7
  require 'file'
8
+ require 'download'
8
9
  require 'methods'
@@ -0,0 +1,85 @@
1
+ require 'typhoeus'
2
+ require 'fileutils'
3
+ require 'concurrent'
4
+
5
+ module Yotsuba
6
+
7
+ class Download
8
+ include Concurrent::Async
9
+
10
+ attr_reader :status
11
+
12
+ def initialize(options = {filename: nil, link: nil, part_links: nil, output_dir: nil })
13
+ @filename = options[:filename]
14
+ @link = options[:link]
15
+ @part_links = options[:part_links]
16
+ @output_dir = File.absolute_path(options[:output_dir]) if options[:output_dir]
17
+ @status = "Queued"
18
+
19
+ @output_dir ||= "."
20
+
21
+ if @link.nil? && @part_links && @part_links.length == 1
22
+ @link = @part_links.first
23
+ @part_links = nil
24
+ end
25
+ init_mutex # Required by Concurrent::Async
26
+ end
27
+
28
+ def run
29
+ @path = File.join(@output_dir, @filename) if @link
30
+ @path = File.join(@output_dir, @filename+".zip") if @part_links
31
+ FileUtils.mkdir_p @output_dir
32
+
33
+ if File.exists? @path
34
+ @status = "File exists"
35
+ return
36
+ end
37
+
38
+ if @part_links
39
+ @part_links.each do |link|
40
+ create_request(link).run
41
+ end
42
+ finish_request
43
+ elsif @link
44
+ create_request(@link).run
45
+ finish_request
46
+ end
47
+ end
48
+
49
+ def run_async
50
+ self.async.run
51
+ end
52
+
53
+ def delete
54
+ File.delete(@path) if @path
55
+ end
56
+
57
+ def bytes_downloaded
58
+ @path ? File.size(@path) : 0
59
+ end
60
+
61
+ private
62
+
63
+ def create_request(link)
64
+ @status = "Downloading..."
65
+ @file_handle ||= File.new(@path, 'ab', 0644)
66
+
67
+ request = Typhoeus::Request.new(link, followlocation: true)
68
+ request.on_headers do |response|
69
+ if response.code != 200
70
+ @status = "Download failed, #{response.code}"
71
+ end
72
+ end
73
+ request.on_body do |chunk|
74
+ @file_handle.write(chunk)
75
+ end
76
+ return request
77
+ end
78
+
79
+ def finish_request
80
+ @status = "Complete"
81
+ @file_handle.close
82
+ end
83
+
84
+ end
85
+ end
data/lib/yotsuba/file.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Yotsuba
2
- class File
2
+ class AnimeFile
3
3
 
4
4
  attr_reader :id, :name, :size, :first_downloaded, :times_downloaded, :anime_id
5
5
 
@@ -21,5 +21,9 @@ module Yotsuba
21
21
  @download_links ||= Yotsuba.get_download_links(self)
22
22
  end
23
23
 
24
+ def download(output_dir)
25
+ Download.new(filename: self.name, part_links: self.download_links, output_dir: output_dir)
26
+ end
27
+
24
28
  end
25
29
  end
@@ -26,7 +26,7 @@ module Yotsuba
26
26
  results = []
27
27
  files = [files] unless files.is_a?(Array)
28
28
  files.each do |f|
29
- results << File.new({
29
+ results << AnimeFile.new({
30
30
  id: f[:id].to_i,
31
31
  name: f[:name],
32
32
  size: f[:file_size].to_i,
@@ -1,3 +1,3 @@
1
1
  module Yotsuba
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
data/yotsuba.gemspec CHANGED
@@ -20,6 +20,10 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.9"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "rspec"
24
- spec.add_dependency "savon", ">= 2.11.0"
23
+ spec.add_development_dependency "rspec", "~> 3.2"
24
+ spec.add_development_dependency "pry"
25
+
26
+ spec.add_dependency "savon", "~> 2.11"
27
+ spec.add_dependency "concurrent-ruby", "~> 0.8"
28
+ spec.add_dependency "typhoeus", "~> 0.7"
25
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yotsuba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Suchipi Izumi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-10 00:00:00.000000000 Z
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -40,6 +40,20 @@ dependencies:
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -56,16 +70,44 @@ dependencies:
56
70
  name: savon
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ">="
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: 2.11.0
75
+ version: '2.11'
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ">="
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.11'
83
+ - !ruby/object:Gem::Dependency
84
+ name: concurrent-ruby
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: typhoeus
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.7'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
67
109
  - !ruby/object:Gem::Version
68
- version: 2.11.0
110
+ version: '0.7'
69
111
  description:
70
112
  email:
71
113
  - me@suchipi.com
@@ -85,6 +127,7 @@ files:
85
127
  - lib/yotsuba.rb
86
128
  - lib/yotsuba/anime.rb
87
129
  - lib/yotsuba/dependencies.rb
130
+ - lib/yotsuba/download.rb
88
131
  - lib/yotsuba/file.rb
89
132
  - lib/yotsuba/methods.rb
90
133
  - lib/yotsuba/serial.rb