imagechan 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a6bfef270bbbc81bfc45ca03eee1ab2244ee525f
4
+ data.tar.gz: 9847d0d3fc89beaa7a07dcad249d01abcd9be5b1
5
+ SHA512:
6
+ metadata.gz: d63889ae4f62ce8dedfea09f87848b899aeb61b83fdf4c52f24927c151a3925cf609ce8122dbd588b42656f7feb2d102c7469ddb599f2463384aaea9dcb70ccb
7
+ data.tar.gz: d0707355e563e22dd1d659bd66b13fd087b97faf7751a328ce5ed15d3f53068ca41e156dfd78f5214eeea1cf08a74ffe929a4c8cd4cadc979cbd6d45001c1bc6
@@ -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/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in imagechan.gemspec
4
+ gemspec
5
+
6
+ gem "nokogiri"
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 virtualpain
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.
@@ -0,0 +1,29 @@
1
+ # Imagechan
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'imagechan'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install imagechan
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 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'nokogiri'
4
+ require "fileutils"
5
+ require "open-uri"
6
+ require 'imagechan'
7
+
8
+ # Preparation
9
+
10
+ if not File.exists? Imagechan.dir
11
+ puts "Preparing directory"
12
+ Dir.mkdir(Imagechan.dir)
13
+ end
14
+
15
+ if ARGV.size == 0
16
+ # puts "Puts complete thread url to download"
17
+ # print "url: "
18
+ # url = STDIN.gets.chomp
19
+ puts <<-end
20
+ Usage: $ imagechan <url>
21
+ url is a complete 4chan thread url
22
+ end
23
+ exit(0)
24
+ else
25
+ url = ARGV.first
26
+ end
27
+
28
+ if not url.match(/http:\/\/boards\.4chan\.org\/[a-z]+\/res\/[0-9]+/)
29
+ puts "Error: Please put a valid 4chan thread URL!"
30
+ exit(0)
31
+ end
32
+
33
+ category = url.scan(/([a-z]+)\/res/).first.first
34
+ thread_id = url.scan(/res\/([0-9]+)/).first.first
35
+ Dir.mkdir File.join(Imagechan.dir,category) if not File.exists? File.join(Imagechan.dir,category)
36
+
37
+ print "Folder name: "
38
+ dir_name = STDIN.gets.chomp.downcase
39
+ target_dir_name = thread_id + ( dir_name.empty? ? "" : "_") + dir_name
40
+ target_dir = File.join(Imagechan.dir,category,target_dir_name)
41
+ Dir.mkdir(target_dir)
42
+
43
+ # Let's the fun begin
44
+
45
+ html_file = open(url)
46
+ doc = Nokogiri::HTML(html_file)
47
+ images = doc.css("a.fileThumb")
48
+
49
+ puts "There are #{images.size} images"
50
+ puts "Saving images to #{target_dir}"
51
+
52
+ loop_number = 1
53
+ images.each do |image|
54
+ img = "http:" + image.attr("href")
55
+ image_filename = img[/[0-9]+\.(jpg|png|gif)/]
56
+ print "#{loop_number}/#{images.size} "
57
+ if File.exists?(File.join(target_dir,image_filename))
58
+ puts "#{image_filename} exists, skipping..."
59
+ else
60
+ print "downloading #{image_filename}..."
61
+ File.open(File.join(target_dir,image_filename),"wb") do |save_file|
62
+ open(img,"rb") do |read_file|
63
+ save_file.write(read_file.read)
64
+ end
65
+ end
66
+ puts " done!"
67
+ end
68
+ loop_number += 1
69
+ end
70
+
71
+ puts "Your images save in #{target_dir}"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'imagechan/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "imagechan"
8
+ gem.version = Imagechan::VERSION
9
+ gem.authors = ["virtualpain"]
10
+ gem.email = ["uehara.kikumi@gmail.com"]
11
+ gem.description = %q{Downloading 4chan images}
12
+ gem.summary = %q{Easily downloading 4chan images in a thread with a single command}
13
+ gem.homepage = "http://eirworks.net/projects/imagechan"
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+ gem.add_runtime_dependency 'nokogiri', '>= 1.5.6'
21
+ end
@@ -0,0 +1,13 @@
1
+ # require File.join(File.dirname(__FILE__),"imagechan","version")
2
+
3
+ dir = File.join(File.dirname(__FILE__))
4
+ files = Dir["imagechan/*.rb"]
5
+ files.each do |file|
6
+ require dir + "/" + file
7
+ end
8
+
9
+ module Imagechan
10
+ def self.dir
11
+ return File.join(Dir.home,'.imagechan')
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ module Imagechan
2
+ VERSION = "0.1.0"
3
+ def self.version
4
+ return VERSION
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imagechan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - virtualpain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.5.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.6
27
+ description: Downloading 4chan images
28
+ email:
29
+ - uehara.kikumi@gmail.com
30
+ executables:
31
+ - imagechan
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - .gitignore
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - bin/imagechan
41
+ - imagechan.gemspec
42
+ - lib/imagechan.rb
43
+ - lib/imagechan/version.rb
44
+ homepage: http://eirworks.net/projects/imagechan
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.0.0
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Easily downloading 4chan images in a thread with a single command
68
+ test_files: []