irosi 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a76aba5b5179abe39028ba02fa78476f3431e50f
4
+ data.tar.gz: c65bf9ff628639712b862d214b7fecb684d0448b
5
+ SHA512:
6
+ metadata.gz: 2bc847b200d9388d002f430cc565fc3fb73274f9d05a11e8e1f8e534b58adc88a2f7d8941ad913912af286074bd286d9bbe5a5b9e17cafe9bdea626ea2d93d22
7
+ data.tar.gz: 640484590df859a88e2d369a172bb9b4e3943fe2b84f966ed892b587fe1194db63f34061df4e7ea8c2fe4b0b02e7b303827f3d249e61f6d9166fae6b4885cf2c
data/._Gemfile ADDED
Binary file
data/._README.md ADDED
Binary file
data/._Rakefile ADDED
Binary file
data/._irosi.gemspec ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ rosi-pics/
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source 'https://ruby.taobao.org'
2
+
3
+ # Specify your gem's dependencies in irosi.gemspec
4
+ gemspec
5
+
6
+ # gem 'thin'
7
+
8
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
9
+ gem 'rails', '4.0.2'
10
+
11
+ # Use sqlite3 as the database for Active Record
12
+ gem 'sqlite3'
13
+
14
+
15
+ gem 'logger'
16
+
17
+
18
+ gem 'curb'
19
+ gem 'nokogiri'
20
+ gem 'fileutils'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 shiren1118
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,46 @@
1
+ # Irosi
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'irosi'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install irosi
18
+
19
+ ## Usage
20
+
21
+
22
+ ```
23
+ Rosi.download do
24
+ for num in 1..8
25
+ item(num)
26
+ end
27
+ end
28
+ ```
29
+
30
+ or
31
+
32
+ ```
33
+ Rosi.download do
34
+ item(1)
35
+ item(2)
36
+ item(4)
37
+ end
38
+ ```
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it ( http://github.com/<my-github-username>/irosi/fork )
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/._irosi ADDED
Binary file
data/bin/irosi ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ require "irosi"
3
+ require 'optparse'
4
+
5
+ options = {}
6
+ option_parser = OptionParser.new do |opts|
7
+
8
+ opts.banner = 'here is help messages of rosi command line tool.'
9
+
10
+ options[:file] = Dir.getwd
11
+
12
+ opts.on('-n NAME', '--alburmnum Name', type="string",'download one alburnm with num') do |value|
13
+ options[:num] = value
14
+ end
15
+
16
+ opts.on('-b begin', '--begin begin','download one alburnm with num') do |value|
17
+ options[:begin] = value
18
+ end
19
+
20
+ opts.on('-e end', '--end end','download one alburnm with num') do |value|
21
+ options[:end] = value
22
+ end
23
+
24
+
25
+ opts.on('-f file', '--file file','download one alburnm with num') do |value|
26
+ options[:file] = value
27
+ end
28
+
29
+ end.parse!
30
+
31
+ # puts options.inspect
32
+
33
+ Irosi.parse(options);
data/irosi.gemspec ADDED
@@ -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 'irosi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "irosi"
8
+ spec.version = Irosi::VERSION
9
+ spec.authors = ["shiren1118"]
10
+ spec.email = ["shiren1118@126.com"]
11
+ spec.summary = "rosi image "
12
+ spec.description = "rosi image 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", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
data/lib/._irosi.rb ADDED
Binary file
Binary file
@@ -0,0 +1,96 @@
1
+ require 'curb'
2
+ require 'nokogiri'
3
+ require 'fileutils'
4
+
5
+ class Rosi
6
+
7
+ def self.download(debug=false,&block)
8
+ server = Rosi.new(debug)
9
+ server.instance_eval(&block)
10
+ server.download_all
11
+ end
12
+
13
+ def initialize(debug=false)
14
+ @debug = debug
15
+ @todo_download_numbers = []
16
+ end
17
+
18
+ def download_all
19
+ puts 'download_all starting...'
20
+ @todo_download_numbers.each do |num|
21
+ if @debug
22
+ # do nothing
23
+ else
24
+ download_pics_albumID num
25
+ end
26
+ end
27
+ end
28
+
29
+ def item(i)
30
+ puts "download alburm number = #{i}"
31
+ @todo_download_numbers << i
32
+ end
33
+
34
+ private
35
+
36
+ def myretry (tries = 3)
37
+ begin
38
+ yield
39
+ rescue
40
+ tries -= 1
41
+ retry if tries > 0
42
+ puts "can't operate : #{$!}"
43
+ end
44
+ end
45
+
46
+ def download_pics_albumID(albumID)
47
+
48
+ # make the directory to store the image files
49
+ dir = 'rosi-pics/ROSI-' + albumID.to_s
50
+ FileUtils.mkdir_p dir
51
+
52
+ url = 'http://rosi.mn/x/album-' + albumID.to_s + '.htm'
53
+ http = ""
54
+ myretry { http = Curl.get(url) }
55
+ doc = Nokogiri::HTML(http.body)
56
+
57
+ coverimg = doc.css("div#album-face img")
58
+ coverurl = coverimg[0]['src']
59
+ coverfilepath = dir + "/ROSI-#{albumID.to_s}-" + "000.jpg"
60
+ puts "\nDownloading " + coverurl
61
+ puts 'Store in ' + coverfilepath
62
+ myretry do
63
+ Curl::Easy.download( coverurl, coverfilepath ) do |curl|
64
+ curl.headers["Referer"] = url
65
+ end
66
+ end
67
+
68
+ i = 1
69
+ anchors = doc.css("div.album-thumbs-free a")
70
+ anchors.each do |anchor|
71
+ imgurl = anchor['href']
72
+ ext = imgurl.split(/\./).last
73
+ filepath = dir + "/ROSI-#{albumID.to_s}-" + i.to_s.rjust(3,"0") + ".#{ext}"
74
+
75
+ puts "\nDownloading " + imgurl
76
+ puts 'Store in ' + filepath
77
+ myretry do
78
+ Curl::Easy.download( imgurl, filepath ) do |curl|
79
+ curl.headers["Referer"] = url
80
+ end
81
+ end
82
+
83
+ sleep 0.1
84
+ i += 1
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+
91
+ # way 1
92
+ # server = Server.new
93
+ # server.handle(/hello/i) { "Hello from server at #{Time.now}" } server.handle(/goodbye/i) { "Goodbye from server at #{Time.now}" } server.handle(/name is (\w+)/) { |m| "Nice to meet you #{m[1]}!" }
94
+ # server.run
95
+
96
+ # way 2
@@ -0,0 +1,3 @@
1
+ module Irosi
2
+ VERSION = "0.0.1"
3
+ end
data/lib/irosi.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "irosi/version"
2
+ require "irosi/download"
3
+
4
+ module Irosi
5
+ # Your code goes here...
6
+
7
+ def self.parse(opts)
8
+ puts '2222'
9
+ puts opts.inspect
10
+ n = opts[:num]
11
+ b = opts[:begin]
12
+ e = opts[:end]
13
+
14
+ file = opts[:file]
15
+ debug_able = false;
16
+
17
+ if File.directory?(file)
18
+ puts 'exist path'
19
+ else
20
+ puts 'not exitst path'
21
+ end
22
+
23
+ if(b)
24
+ # 下载从begin开始到end结束中间的所有专辑
25
+ Rosi.download debug_able do
26
+ for num in "#{b}".."#{e}"
27
+ item(num)
28
+ end
29
+ end
30
+
31
+ elsif(n)
32
+ # 指定具体专辑id
33
+ Rosi.download debug_able do
34
+ item(n)
35
+ end
36
+
37
+ else
38
+ puts '没有合法参数'
39
+ end
40
+
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: irosi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - shiren1118
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-14 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: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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: rosi image downloader
42
+ email:
43
+ - shiren1118@126.com
44
+ executables:
45
+ - "._irosi"
46
+ - irosi
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - "._Gemfile"
51
+ - "._README.md"
52
+ - "._Rakefile"
53
+ - "._irosi.gemspec"
54
+ - ".gitignore"
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/._irosi
60
+ - bin/irosi
61
+ - irosi.gemspec
62
+ - lib/._irosi.rb
63
+ - lib/irosi.rb
64
+ - lib/irosi/._download.rb
65
+ - lib/irosi/download.rb
66
+ - lib/irosi/version.rb
67
+ homepage: ''
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.2.0
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: rosi image
91
+ test_files: []