eg_nijigazou_sokuhou 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create @ero_getter
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source :rubygems
2
+
3
+ # Specify your gem's dependencies in eg_nijigazou_sokuhou.gemspec
4
+ gemspec
5
+
6
+ gem 'nokogiri'
7
+ gem 'httpclient'
8
+ gem 'ero_getter'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Yamada Masaki
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # EgNijigazouSokuhou
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'eg_nijigazou_sokuhou'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install eg_nijigazou_sokuhou
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = 'spec/**/*_spec.rb'
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/eg_nijigazou_sokuhou/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["masarakki"]
6
+ gem.email = ["masaki@hisme.net"]
7
+ gem.description = %q{Downloader for 二次画像速報}
8
+ gem.summary = %q{Downloader for 二次画像速報}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "eg_nijigazou_sokuhou"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = NijigazouSokuhou::VERSION
17
+ end
@@ -0,0 +1,3 @@
1
+ class NijigazouSokuhou
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,56 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'ero_getter'
3
+ require 'nokogiri'
4
+
5
+ class NijigazouSokuhou < EroGetter::Downloader::Base
6
+
7
+ name '二次画像速報'
8
+ url %r{http://nijigazo.2chblog.jp/archives/\d+.html}
9
+
10
+ def dirname(image_url = nil)
11
+ path = image_url.split('/')
12
+ d = path[3..5].join('')
13
+ chara = path[6]
14
+ dirname = File.join(EroGetter::Downloader.base_path, base_dir, chara, d)
15
+ EroGetter::Downlaoder.mkdir(dirname) unless File.exists?(dirname)
16
+ dirname
17
+ end
18
+
19
+ def run
20
+ fetch_url(url)
21
+ end
22
+
23
+ def fetch_url(src_url, dist = 0)
24
+ document = Nokogiri::HTML(open(src_url).read)
25
+
26
+ title_full = document.title
27
+ title = title_full.split(/:/).last.match(/(.+?)(その.+)?$/)[1].strip.gsub(/&amp;/, '&')
28
+
29
+ image_urls = document.css(".article-body-more > a > img").map { |path|
30
+ path.parent[:href] if path.parent[:href] =~ /jpe?g|png|gif$/
31
+ }.compact
32
+
33
+ connection = {:prev => document.xpath("//a[@rel='prev']").first, :next => document.xpath("//a[@rel='next']").first}
34
+ dir = dirname(image_urls.first)
35
+
36
+ image_urls.each do |image_url|
37
+ filename = File.basename(image_url)
38
+ response = http_client.get(image_url, :header => {:referer => src_url})
39
+ raise unless response.status == 200
40
+ File.open(File.join(dir, filename), "wb") {|f| f.write response.body }
41
+ end
42
+
43
+ connection.each do |type, path|
44
+ if path
45
+ case type
46
+ when :prev
47
+ fetch_url(path[:href], -1) if dist <= 0 && path.text.match(Regexp.escape(title))
48
+ when :next
49
+ fetch_url(path[:href], 1) if dist >= 0 && path.text.match(Regexp.escape(title))
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ require 'eg_nijigazou_sokuhou/version'
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe NijigazouSokuhou do
5
+ subject { NijigazouSokuhou.new }
6
+ describe 'VERSION' do
7
+ it { NijigazouSokuhou::VERSION.should == '0.0.1' }
8
+ end
9
+ its(:name) { should == '二次画像速報' }
10
+ end
@@ -0,0 +1 @@
1
+ require 'eg_nijigazou_sokuhou'
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eg_nijigazou_sokuhou
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - masarakki
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-12 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Downloader for 二次画像速報
15
+ email:
16
+ - masaki@hisme.net
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .rspec
23
+ - .rvmrc
24
+ - Gemfile
25
+ - LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - eg_nijigazou_sokuhou.gemspec
29
+ - lib/eg_nijigazou_sokuhou.rb
30
+ - lib/eg_nijigazou_sokuhou/version.rb
31
+ - spec/eg_nijigazou_sokuhou_spec.rb
32
+ - spec/spec_helper.rb
33
+ homepage: ''
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.24
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Downloader for 二次画像速報
57
+ test_files:
58
+ - spec/eg_nijigazou_sokuhou_spec.rb
59
+ - spec/spec_helper.rb