imagechan 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/imagechan +31 -11
- data/imagechan.gemspec +2 -2
- data/lib/imagechan.rb +26 -0
- data/lib/imagechan/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 876f49f4b41c7a5723530327050e625c34607f3b
|
4
|
+
data.tar.gz: bea28e45907ab6df60da25e3b525760019c231e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a82db3460930d2e6573cef97166d16ebcb9b7f54ceec97243e05131dd5bf8169bfd8a8504bc5e6bf4aae304a21b5505a690ca21b2b146e5fd00b90ce97673aeb
|
7
|
+
data.tar.gz: c23e642fd454486b0a89a4c8c783fefd3a62971c2812b75cf3c839fd6198fa5fbaaa865b74589950a5cf527729f03a258e878d6236183d81b3123c7845b475d6
|
data/bin/imagechan
CHANGED
@@ -4,28 +4,47 @@ require 'nokogiri'
|
|
4
4
|
require "fileutils"
|
5
5
|
require "open-uri"
|
6
6
|
require 'imagechan'
|
7
|
+
require "imagechan/version"
|
8
|
+
require "imagechan/catalog"
|
7
9
|
|
8
|
-
#
|
10
|
+
# Currently available commands
|
11
|
+
commands = %w{catalog version clearlock where}
|
9
12
|
|
13
|
+
# Preparation
|
10
14
|
if not File.exists? Imagechan.dir
|
11
|
-
|
12
|
-
Dir.mkdir(Imagechan.dir)
|
15
|
+
Imagechan.prepare
|
13
16
|
end
|
14
17
|
|
15
18
|
if ARGV.size == 0
|
16
|
-
# puts "Puts complete thread url to download"
|
17
|
-
# print "url: "
|
18
|
-
# url = STDIN.gets.chomp
|
19
19
|
puts <<-end
|
20
|
-
Usage:
|
21
|
-
|
20
|
+
Usage: imagechan <command> [params]
|
21
|
+
Commands:
|
22
|
+
- <url> : Download images from <url>
|
23
|
+
- version : Show current version
|
24
|
+
- clearlock : Clear LOCK file
|
22
25
|
end
|
23
26
|
exit(0)
|
24
27
|
else
|
25
|
-
|
28
|
+
command = ARGV.first
|
29
|
+
|
30
|
+
case command
|
31
|
+
when "catalog"
|
32
|
+
Imagechan::FourChan.catalog(ARGV[1])
|
33
|
+
when "version"
|
34
|
+
puts "Version #{Imagechan.version}"
|
35
|
+
when "clearlock"
|
36
|
+
Imagechan.clearlock
|
37
|
+
when "where"
|
38
|
+
Imagechan.where?
|
39
|
+
else
|
40
|
+
url = command
|
41
|
+
end
|
42
|
+
if commands.include? command
|
43
|
+
exit(0)
|
44
|
+
end
|
26
45
|
end
|
27
46
|
|
28
|
-
if not
|
47
|
+
if not Imagechan.match_thread_url(url)
|
29
48
|
puts "Error: Please put a valid 4chan thread URL!"
|
30
49
|
exit(0)
|
31
50
|
end
|
@@ -49,7 +68,7 @@ else
|
|
49
68
|
target_dir = File.join(Imagechan.dir,category,Imagechan.get_folder_name_by_id(thread_id))
|
50
69
|
end
|
51
70
|
|
52
|
-
#
|
71
|
+
# Locking download for small connection
|
53
72
|
if not File.exists?(File.join(Imagechan.dir,"LOCK"))
|
54
73
|
File.open(File.join(Imagechan.dir,"LOCK"),'w'){|f| f.write ""}
|
55
74
|
else
|
@@ -57,6 +76,7 @@ else
|
|
57
76
|
exit(0)
|
58
77
|
end
|
59
78
|
|
79
|
+
# Let's the fun begin
|
60
80
|
html_file = open(url)
|
61
81
|
doc = Nokogiri::HTML(html_file)
|
62
82
|
images = doc.css("a.fileThumb")
|
data/imagechan.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'imagechan/version'
|
4
|
+
# require 'imagechan/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "imagechan"
|
8
|
-
gem.version = Imagechan::VERSION
|
8
|
+
gem.version = "0.2.0" #Imagechan::VERSION
|
9
9
|
gem.authors = ["virtualpain"]
|
10
10
|
gem.email = ["uehara.kikumi@gmail.com"]
|
11
11
|
gem.description = %q{Simple 4chan image downloader command}
|
data/lib/imagechan.rb
CHANGED
@@ -23,4 +23,30 @@ module Imagechan
|
|
23
23
|
dir = Dir[File.join(Imagechan.dir,"*","#{id}*")].first.split(File::SEPARATOR).last
|
24
24
|
return dir
|
25
25
|
end
|
26
|
+
|
27
|
+
def self.prepare
|
28
|
+
puts "Preparing directory"
|
29
|
+
Dir.mkdir(Imagechan.dir)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.clearlock
|
33
|
+
if File.exists?(File.join(Imagechan.dir,"LOCK"))
|
34
|
+
File.delete File.join(Imagechan.dir,"LOCK")
|
35
|
+
puts "LOCK cleared!"
|
36
|
+
else
|
37
|
+
puts "There are nothing to unlock"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.match_thread_url(url)
|
42
|
+
if url.match(/http:\/\/boards\.4chan\.org\/[a-z]+\/res\/[0-9]+/)
|
43
|
+
true
|
44
|
+
else
|
45
|
+
false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.where?
|
50
|
+
puts Imagechan.dir
|
51
|
+
end
|
26
52
|
end
|
data/lib/imagechan/version.rb
CHANGED