yotsuba 0.4.0 → 0.5.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: 48d3289804f7c84c1eed41d3bf2fb32b1531a05a
4
- data.tar.gz: b6a84c8f189a424e2a5b5d180c686a6db9b9f023
3
+ metadata.gz: 76b652a4c650b22100d4d701393711541c68d64d
4
+ data.tar.gz: 547ea8a390b38426e16533ed38c40e7396d55223
5
5
  SHA512:
6
- metadata.gz: 3ec3be4b889ef85639bd6d4466186011d84753008a946db110d6edfdbd5aa4fc422d3614d0d0f4edb94ca072cb16a65ab6fd9caf18701ad63dc5c1f3fc8a335f
7
- data.tar.gz: f298bf48eb88c324974732bd55137ecdabc568fae5626d8f7d530ebc539532d95490d65fa00308d67a86260f2840f141b2419aca300cd6ccb41aad238d301a18
6
+ metadata.gz: 8a499aa346247857d285fd29866504cc4f64e2a95d44023af7f44a3142a8b25eeac8e6bdadc2db8b5dc387fd5fa5f864c2e5021c1c1fe2c257630ff524ec46ad
7
+ data.tar.gz: c6c0908de703c8b699243ef3f8754248c41f0da014ba627ecb00baae901d49abe08fecf3fc389207da975d888857b1c8e8906178d82daae731ed002bc828b15c
@@ -6,4 +6,4 @@ require 'serial'
6
6
  require 'anime'
7
7
  require 'file'
8
8
  require 'download'
9
- require 'methods'
9
+ require 'messenger'
@@ -1,73 +1,14 @@
1
1
  module Yotsuba
2
2
  class Anime
3
- attr_reader :id, :title, :num_files
4
3
 
5
- @@all_animes = []
4
+ attr_reader :id, :title, :num_files
6
5
 
7
6
  def initialize(options = {id: nil, title: nil, num_files: nil})
8
7
  @id = options[:id]
9
8
  @title = options[:title]
10
9
  @num_files = options[:num_files]
11
- @@all_animes << self if self.valid?
12
10
  return self
13
11
  end
14
12
 
15
- def valid?
16
- self.id != nil && self.title != nil && self.num_files != nil
17
- end
18
-
19
- def files
20
- @files ||= Yotsuba.get_files(self)
21
- end
22
-
23
- def self.clear_anime_list!
24
- @@all_animes = []
25
- end
26
-
27
- def self.all
28
- precache_animes
29
- @@all_animes
30
- end
31
-
32
- def self.[](key)
33
- return Anime.find_by(title: key) if key.is_a?(String)
34
- return Anime.find_by(id: key) if key.is_a?(Fixnum)
35
- return Anime.search(key) if key.is_a?(Regexp)
36
-
37
- raise(ArgumentError, "Argument should be a String (title), Fixnum (id), or Regexp (matches title).")
38
- end
39
-
40
- def self.find_by(hash = {title: nil, id: nil})
41
- precache_animes
42
- @@all_animes.each do |anime|
43
- match = check_property(anime, :id, hash) || check_property(anime, :title, hash)
44
- return match if match
45
- end
46
- return nil
47
- end
48
-
49
- def self.find(id)
50
- Anime.find_by(id: id)
51
- end
52
-
53
- def self.search(regexp)
54
- precache_animes
55
- results = []
56
- @@all_animes.each do |anime|
57
- results << anime if anime.title.match(regexp)
58
- end
59
- return results
60
- end
61
-
62
- private
63
-
64
- def self.precache_animes
65
- Yotsuba.get_animes if @@all_animes.length == 0
66
- end
67
-
68
- def self.check_property(object, symbol, hash)
69
- hash[symbol] && object.respond_to?(symbol) && object.send(symbol) == hash[symbol] ? object : nil
70
- end
71
-
72
13
  end
73
14
  end
@@ -1 +1,5 @@
1
1
  require 'savon'
2
+ require 'typhoeus'
3
+ require 'fileutils'
4
+ require 'concurrent'
5
+
@@ -1,14 +1,7 @@
1
- require 'typhoeus'
2
- require 'fileutils'
3
- require 'concurrent'
4
-
5
1
  module Yotsuba
6
-
7
2
  class Download
8
3
  include Concurrent::Async
9
4
 
10
- @@all_downloads = []
11
-
12
5
  attr_reader :status, :file, :id
13
6
 
14
7
  def initialize(options = {animefile: nil, output_dir: "." })
@@ -16,18 +9,10 @@ module Yotsuba
16
9
  @output_dir = File.absolute_path(options[:output_dir])
17
10
  @multiple = (@file.download_links.length > 1) if @file
18
11
  @status = "Queued"
19
- if self.valid?
20
- @id = @@all_downloads.length + 1
21
- @@all_downloads << self if self.valid?
22
- end
23
12
 
24
13
  init_mutex # Required by Concurrent::Async
25
14
  end
26
15
 
27
- def valid?
28
- self.file != nil
29
- end
30
-
31
16
  def run
32
17
  @path = @multiple ? File.join(@output_dir, @file.name+".zip") : @path = File.join(@output_dir, @file.name)
33
18
 
@@ -56,7 +41,6 @@ module Yotsuba
56
41
  def delete
57
42
  abort if @status != "Aborted"
58
43
  File.delete(@path) if @path
59
- @@all_downloads -= [self]
60
44
  return true
61
45
  end
62
46
 
@@ -68,34 +52,6 @@ module Yotsuba
68
52
  100.0 * self.bytes_written / self.file.size
69
53
  end
70
54
 
71
- def self.all
72
- @@all_downloads
73
- end
74
-
75
- def self.[](key)
76
- return self.find_by(id: key) if key.is_a?(Fixnum)
77
- return self.find_by(file: key) if key.is_a?(AnimeFile)
78
- return self.find_by(filename: key) if key.is_a?(String)
79
- return self.find_by
80
- end
81
-
82
- def self.find_by(hash = {id: nil, file: nil, filename: nil, status: nil, percent_downloaded: nil})
83
- @@all_downloads.each do |download|
84
- match = check_property(download, :id, hash) ||
85
- check_property(download, :file, hash) ||
86
- check_property(download, :filename, hash) ||
87
- check_property(download, :status, hash) ||
88
- check_property(download, :percent_downloaded, hash)
89
-
90
- return match if match
91
- end
92
- return nil
93
- end
94
-
95
- def self.find(id)
96
- return Download.find_by(id: id)
97
- end
98
-
99
55
  private
100
56
 
101
57
  def create_request(link)
@@ -119,9 +75,5 @@ module Yotsuba
119
75
  @file_handle.close
120
76
  end
121
77
 
122
- def check_property(object, symbol, hash)
123
- hash[symbol] && object.respond_to?(symbol) && object.send(symbol) == hash[symbol] ? object : nil
124
- end
125
-
126
78
  end
127
79
  end
@@ -1,37 +1,17 @@
1
1
  module Yotsuba
2
2
  class AnimeFile
3
3
 
4
- attr_reader :id, :name, :size, :first_downloaded, :times_downloaded, :anime_id
4
+ attr_reader :id, :name, :size, :first_downloaded, :times_downloaded, :anime
5
5
 
6
- def initialize(options = {id: nil, name: nil, size: nil, first_downloaded: nil, times_downloaded: nil, anime_id: nil})
6
+ def initialize(options = {id: nil, name: nil, size: nil, first_downloaded: nil, times_downloaded: nil, anime: nil})
7
7
  @id = options[:id]
8
8
  @name = options[:name]
9
9
  @size = options[:size]
10
10
  @first_downloaded = options[:first_downloaded]
11
11
  @times_downloaded = options[:times_downloaded]
12
- @anime_id = options[:anime_id]
12
+ @anime = options[:anime]
13
13
  return self
14
14
  end
15
15
 
16
- def anime
17
- @anime ||= Yotsuba::Anime[self.anime_id]
18
- end
19
-
20
- def download_links
21
- @download_links ||= Yotsuba.get_download_links(self)
22
- end
23
-
24
- def download(output_dir)
25
- @download ||= Download.new(animefile: self, output_dir: output_dir)
26
- end
27
-
28
- def ==(other_file)
29
- other_file && self.id == other_file.id
30
- end
31
-
32
- def eq(other_file)
33
- self == other_file
34
- end
35
-
36
16
  end
37
17
  end
@@ -0,0 +1,57 @@
1
+ module Yotsuba
2
+ module Messenger
3
+
4
+ def self.get_animes(options = {use_cache: false})
5
+ setup
6
+ return @animes if options[:use_cache] && @animes.length > 0
7
+ response = @client.call(:get_anime_list)
8
+ animes = response.body[:get_anime_list_response][:get_anime_list_result][:anime]
9
+ animes = [animes] unless animes.is_a?(Array)
10
+ results = []
11
+ animes.each do |a|
12
+ results << {
13
+ id: a[:id].to_i,
14
+ title: a[:title],
15
+ num_files: a[:num_file].to_i
16
+ }
17
+ end
18
+ @animes = results if options[:use_cache]
19
+ return results
20
+ end
21
+
22
+ def self.get_files(anime)
23
+ setup
24
+ response = @client.call(:get_list_episode, message: { animeTitle: anime.title, serial: Yotsuba::Serial })
25
+ files = response.body[:get_list_episode_response][:get_list_episode_result][:episode_file]
26
+ files = [files] unless files.is_a?(Array)
27
+ results = []
28
+ files.each do |f|
29
+ results << {
30
+ id: f[:id].to_i,
31
+ name: f[:name],
32
+ size: f[:file_size].to_i,
33
+ first_downloaded: f[:first_download_time_in_day],
34
+ times_downloaded: f[:download_times].to_i,
35
+ anime: anime
36
+ }
37
+ end
38
+ return results
39
+ end
40
+
41
+ def self.get_download_links(file)
42
+ setup
43
+ response = @client.call :request_link_download2, message: { animeTitle: file.anime.title, episodeName: file.name, serial: Yotsuba::Serial }
44
+ links = response.body[:request_link_download2_response][:request_link_download2_result].split('|||')
45
+ links = [links] unless links.is_a?(Array)
46
+ return links
47
+ end
48
+
49
+ private
50
+
51
+ def self.setup
52
+ @client ||= Savon.client(wsdl: 'http://anime.domdomsoft.com/Services/MainService.asmx?wsdl')
53
+ @animes ||= []
54
+ end
55
+
56
+ end
57
+ end
@@ -1,3 +1,3 @@
1
1
  module Yotsuba
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  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.4.0
4
+ version: 0.5.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-15 00:00:00.000000000 Z
11
+ date: 2015-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -129,7 +129,7 @@ files:
129
129
  - lib/yotsuba/dependencies.rb
130
130
  - lib/yotsuba/download.rb
131
131
  - lib/yotsuba/file.rb
132
- - lib/yotsuba/methods.rb
132
+ - lib/yotsuba/messenger.rb
133
133
  - lib/yotsuba/serial.rb
134
134
  - lib/yotsuba/version.rb
135
135
  - yotsuba.gemspec
@@ -1,47 +0,0 @@
1
- module Yotsuba
2
-
3
- def self.setup_savon
4
- @client ||= Savon.client(wsdl: 'http://anime.domdomsoft.com/Services/MainService.asmx?wsdl')
5
- end
6
-
7
- def self.get_animes
8
- setup_savon
9
- Anime.clear_anime_list!
10
- response = @client.call(:get_anime_list)
11
- animes = response.body[:get_anime_list_response][:get_anime_list_result][:anime]
12
- animes.each do |a|
13
- Anime.new({
14
- id: a[:id].to_i,
15
- title: a[:title],
16
- num_files: a[:num_file].to_i
17
- })
18
- end
19
- return animes.length > 0
20
- end
21
-
22
- def self.get_files(anime)
23
- setup_savon
24
- response = @client.call(:get_list_episode, message: { animeTitle: anime.title, serial: Serial })
25
- files = response.body[:get_list_episode_response][:get_list_episode_result][:episode_file]
26
- results = []
27
- files = [files] unless files.is_a?(Array)
28
- files.each do |f|
29
- results << AnimeFile.new({
30
- id: f[:id].to_i,
31
- name: f[:name],
32
- size: f[:file_size].to_i,
33
- first_downloaded: f[:first_download_time_in_day],
34
- times_downloaded: f[:download_times].to_i,
35
- anime_id: anime.id
36
- })
37
- end
38
- return results
39
- end
40
-
41
- def self.get_download_links(file)
42
- setup_savon
43
- response = @client.call :request_link_download2, message: { animeTitle: file.anime.title, episodeName: file.name, serial: Serial }
44
- links = response.body[:request_link_download2_response][:request_link_download2_result].split('|||')
45
- end
46
-
47
- end