imagechan 0.1.0 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6bfef270bbbc81bfc45ca03eee1ab2244ee525f
4
- data.tar.gz: 9847d0d3fc89beaa7a07dcad249d01abcd9be5b1
3
+ metadata.gz: d20405a29d95ff1a6956d4b3c3e745c689dde91c
4
+ data.tar.gz: 9d357e9302e566d45fec2fe3fa9f40a6eceb84fa
5
5
  SHA512:
6
- metadata.gz: d63889ae4f62ce8dedfea09f87848b899aeb61b83fdf4c52f24927c151a3925cf609ce8122dbd588b42656f7feb2d102c7469ddb599f2463384aaea9dcb70ccb
7
- data.tar.gz: d0707355e563e22dd1d659bd66b13fd087b97faf7751a328ce5ed15d3f53068ca41e156dfd78f5214eeea1cf08a74ffe929a4c8cd4cadc979cbd6d45001c1bc6
6
+ metadata.gz: 161373d7e63ac36fac2563f48e9616bb06a531e6f76f488d9efc43a267ab0bc5500a30482dd0d1deabaaa34d6fe565d9d12a6e02c737986d4f6e24ac23863bec
7
+ data.tar.gz: d020c44588af5206cfa6bd77457c341ea6a2171a1db4563e4a0e83378abe04888d6a57e765713e2eabfddb78ecd4c1f18a2363a5adcf239515ca90fe475886b1
data/LOCK ADDED
File without changes
data/README.md CHANGED
@@ -1,29 +1,11 @@
1
1
  # Imagechan
2
2
 
3
- TODO: Write a gem description
3
+ Simple command to download all images from a single thread in 4chan.
4
4
 
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'imagechan'
5
+ Usage: `imagechan <threadurl>`
10
6
 
11
- And then execute:
12
-
13
- $ bundle
7
+ ## Installation
14
8
 
15
- Or install it yourself as:
9
+ Installation as simple as:
16
10
 
17
11
  $ 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
@@ -18,7 +18,7 @@ if ARGV.size == 0
18
18
  # url = STDIN.gets.chomp
19
19
  puts <<-end
20
20
  Usage: $ imagechan <url>
21
- url is a complete 4chan thread url
21
+ Where <url> is a complete 4chan thread url
22
22
  end
23
23
  exit(0)
24
24
  else
@@ -34,13 +34,28 @@ category = url.scan(/([a-z]+)\/res/).first.first
34
34
  thread_id = url.scan(/res\/([0-9]+)/).first.first
35
35
  Dir.mkdir File.join(Imagechan.dir,category) if not File.exists? File.join(Imagechan.dir,category)
36
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)
37
+ # Check if thread ID already downloaded!
38
+ if Imagechan.id_exists?(thread_id) == false
39
+ print "Folder name: "
40
+ dir_name = STDIN.gets.chomp.downcase.gsub(/[^a-zA-Z0-9\-\ ]/,"_").gsub(/_{2,}/,"_")
41
+ target_dir_name = thread_id + ( dir_name.empty? ? "" : "_") + dir_name
42
+ target_dir = File.join(Imagechan.dir,category,target_dir_name)
43
+ Dir.mkdir(target_dir)
44
+ else
45
+ puts "Folder with id #{thread_id} exist in #{Imagechan.get_folder_name_by_id(thread_id)}"
46
+ print "Continue download (y/N)? "
47
+ confirm = STDIN.gets.chomp.downcase
48
+ exit(0) if confirm.empty? or confirm == "n"
49
+ target_dir = File.join(Imagechan.dir,category,Imagechan.get_folder_name_by_id(thread_id))
50
+ end
42
51
 
43
52
  # Let's the fun begin
53
+ if not File.exists?(File.join(Imagechan.dir,"LOCK"))
54
+ File.open(File.join(Imagechan.dir,"LOCK"),'w'){|f| f.write ""}
55
+ else
56
+ puts "There are currently other download process"
57
+ exit(0)
58
+ end
44
59
 
45
60
  html_file = open(url)
46
61
  doc = Nokogiri::HTML(html_file)
@@ -58,6 +73,8 @@ images.each do |image|
58
73
  puts "#{image_filename} exists, skipping..."
59
74
  else
60
75
  print "downloading #{image_filename}..."
76
+
77
+ # Pure ruby download method
61
78
  File.open(File.join(target_dir,image_filename),"wb") do |save_file|
62
79
  open(img,"rb") do |read_file|
63
80
  save_file.write(read_file.read)
@@ -68,4 +85,5 @@ images.each do |image|
68
85
  loop_number += 1
69
86
  end
70
87
 
71
- puts "Your images save in #{target_dir}"
88
+ puts "Your images save in #{target_dir}"
89
+ File.delete(File.join(Imagechan.dir,"LOCK")) if File.exists? File.join(Imagechan.dir,"LOCK")
@@ -8,9 +8,9 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Imagechan::VERSION
9
9
  gem.authors = ["virtualpain"]
10
10
  gem.email = ["uehara.kikumi@gmail.com"]
11
- gem.description = %q{Downloading 4chan images}
11
+ gem.description = %q{Simple 4chan image downloader command}
12
12
  gem.summary = %q{Easily downloading 4chan images in a thread with a single command}
13
- gem.homepage = "http://eirworks.net/projects/imagechan"
13
+ gem.homepage = "https://github.com/virtualpain/imagechan"
14
14
  gem.license = "MIT"
15
15
 
16
16
  gem.files = `git ls-files`.split($/)
@@ -10,4 +10,17 @@ module Imagechan
10
10
  def self.dir
11
11
  return File.join(Dir.home,'.imagechan')
12
12
  end
13
+
14
+ def self.id_exists?(id)
15
+ if Dir[File.join(Imagechan.dir,"*","#{id}*")].size > 0
16
+ return true
17
+ else
18
+ return false
19
+ end
20
+ end
21
+
22
+ def self.get_folder_name_by_id(id)
23
+ dir = Dir[File.join(Imagechan.dir,"*","#{id}*")].first.split(File::SEPARATOR).last
24
+ return dir
25
+ end
13
26
  end
@@ -1,5 +1,5 @@
1
1
  module Imagechan
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.4"
3
3
  def self.version
4
4
  return VERSION
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imagechan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - virtualpain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-22 00:00:00.000000000 Z
11
+ date: 2013-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.5.6
27
- description: Downloading 4chan images
27
+ description: Simple 4chan image downloader command
28
28
  email:
29
29
  - uehara.kikumi@gmail.com
30
30
  executables:
@@ -35,13 +35,14 @@ files:
35
35
  - .gitignore
36
36
  - Gemfile
37
37
  - LICENSE.txt
38
+ - LOCK
38
39
  - README.md
39
40
  - Rakefile
40
41
  - bin/imagechan
41
42
  - imagechan.gemspec
42
43
  - lib/imagechan.rb
43
44
  - lib/imagechan/version.rb
44
- homepage: http://eirworks.net/projects/imagechan
45
+ homepage: https://github.com/virtualpain/imagechan
45
46
  licenses:
46
47
  - MIT
47
48
  metadata: {}
@@ -61,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
62
  version: '0'
62
63
  requirements: []
63
64
  rubyforge_project:
64
- rubygems_version: 2.0.0
65
+ rubygems_version: 2.0.3
65
66
  signing_key:
66
67
  specification_version: 4
67
68
  summary: Easily downloading 4chan images in a thread with a single command