sfacg 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/sfacg +3 -0
- data/lib/sfacg.rb +1 -0
- data/lib/sfacg/chapter.rb +48 -0
- data/lib/sfacg/cli.rb +24 -0
- data/lib/sfacg/comic.rb +18 -0
- data/lib/sfacg/version.rb +3 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5646a3638227e1b696661c58537f21f48926e7e0
|
4
|
+
data.tar.gz: 1ea10251f189d22034f22211356c8c967d1accb9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 81b81cb5ecab76f20eeceb06023edfdecd3bec4853ae6a8cac79431ae5007905d8932965886e1f6893a6a9aea73c331ff55120d505fcc1b0687f528de31599de
|
7
|
+
data.tar.gz: 7cc6227bf90507711dfaf9db744b13955660db29e5f405bc619e6e62dee190e90a561f630b364f868c28acfefc89d019bd644387038a189e20bab9342aa62369
|
data/bin/sfacg
ADDED
data/lib/sfacg.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'sfacg/comic'
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'therubyracer'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
module Sfacg
|
7
|
+
class Chapter
|
8
|
+
def initialize url
|
9
|
+
@uri = URI(url)
|
10
|
+
end
|
11
|
+
|
12
|
+
def js_uri
|
13
|
+
return @js_uri if @js_uri
|
14
|
+
chapter = @uri.to_s[/\/([^\/]*)\/?$/, 1]
|
15
|
+
doc = Nokogiri::HTML(Net::HTTP.get(@uri))
|
16
|
+
@js_uri = URI.join(@uri, doc.at_css("script[src*=\"#{chapter}.js\"]")['src'])
|
17
|
+
end
|
18
|
+
|
19
|
+
def images
|
20
|
+
return @images if @images
|
21
|
+
cxt = V8::Context.new
|
22
|
+
cxt.eval(Net::HTTP.get(js_uri))
|
23
|
+
@hosts = cxt['hosts']
|
24
|
+
@images = cxt['picAy'].map{|path| URI.join(@hosts.first, path)}
|
25
|
+
end
|
26
|
+
|
27
|
+
def download to: '.'
|
28
|
+
FileUtils::mkdir_p to
|
29
|
+
threads = []
|
30
|
+
images.each_with_index do |img_uri, i|
|
31
|
+
threads << Thread.new{
|
32
|
+
file_name = "#{i}#{File.extname(img_uri.to_s)}"
|
33
|
+
file_path = File.join(to, file_name)
|
34
|
+
begin
|
35
|
+
Net::HTTP.start(img_uri.host, img_uri.port, read_timeout: 5) do |http|
|
36
|
+
response = http.request(Net::HTTP::Get.new(img_uri))
|
37
|
+
File.write file_path, response.body
|
38
|
+
puts "#{img_uri} -> #{file_path}"
|
39
|
+
end
|
40
|
+
rescue => e
|
41
|
+
puts "#{e} #{e.message} #{img_uri} -> #{file_path}"
|
42
|
+
end
|
43
|
+
}
|
44
|
+
end
|
45
|
+
threads.each &:join
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/sfacg/cli.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'sfacg'
|
2
|
+
require 'sfacg/version'
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
module Sfacg
|
6
|
+
class Cli < Thor
|
7
|
+
desc 'comic URL', 'Download a comic, ex: http://comic.sfacg.com/HTML/JJDJR/'
|
8
|
+
option :to, default: '.'
|
9
|
+
def comic url
|
10
|
+
Comic.new(url).download to: options[:to]
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'chapter URL', 'Download a chapter, ex: http://comic.sfacg.com/HTML/JJDJR/056/'
|
14
|
+
option :to, default: '.'
|
15
|
+
def chapter url
|
16
|
+
Chapter.new(url).download to: options[:to]
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'version', 'Prints version'
|
20
|
+
def version
|
21
|
+
puts VERSION
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/sfacg/comic.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'sfacg/chapter'
|
2
|
+
module Sfacg
|
3
|
+
class Comic
|
4
|
+
def initialize url
|
5
|
+
@uri = URI(url)
|
6
|
+
@comic_name = url[/\/([^\/]*)\/?$/, 1]
|
7
|
+
end
|
8
|
+
|
9
|
+
def download to: '.'
|
10
|
+
doc = Nokogiri::HTML(Net::HTTP.get(@uri))
|
11
|
+
doc.css('ul.serialise_list.Blue_link2 li>a').each do |link|
|
12
|
+
chapter_uri = URI.join(@uri, link['href'])
|
13
|
+
chapter_name = File.basename(chapter_uri.to_s)
|
14
|
+
Chapter.new(chapter_uri).download to: File.join(to, "#{@comic_name}/#{chapter_name}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sfacg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tony Jian
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
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: therubyracer
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: sfacg comic downloader
|
56
|
+
email: tonytonyjan@gmail.com
|
57
|
+
executables:
|
58
|
+
- sfacg
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- bin/sfacg
|
63
|
+
- lib/sfacg.rb
|
64
|
+
- lib/sfacg/chapter.rb
|
65
|
+
- lib/sfacg/cli.rb
|
66
|
+
- lib/sfacg/comic.rb
|
67
|
+
- lib/sfacg/version.rb
|
68
|
+
homepage: https://github.com/tonytonyjan/sfacg
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.3.0
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: sfacg comic downloader
|
92
|
+
test_files: []
|