imagechan 0.2.2 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5408ce82328c425dcbe399032e75731f191cc64f
4
- data.tar.gz: 6dfa0f1df5720befbfe71b2200f49e82a6ea3bdc
3
+ metadata.gz: 8aa7643f63cfe2a01f130c1e0bf9ba3cbc77c53c
4
+ data.tar.gz: 8033eef5983385761e3fab9681502350827bc645
5
5
  SHA512:
6
- metadata.gz: 1c5d40b17c55ad7f2834b7550a3ad53891d7f325ac0d20343c187e65d78a5dc7b359ad325312ccd6e9204ef1e3e8dad969fdc6a89dc1c761450d5d9b3a14514f
7
- data.tar.gz: d5290658784a00feeaab8c180eb9855cc4815337153e7431f9e80cdf521be6c0f4e42593569977719a3b1b53d57dab170d00b838f047c3d6db1cc317dbf09ae7
6
+ metadata.gz: c2ff013662f440776b195e283b9540354e4f564a2dc8cf9a63cf9cde20f8e5078371c2eaa87f258d7c7ef2b05be2d81eb90c92b421591c9733a29916b0179a66
7
+ data.tar.gz: bcf6334f442948557c312870e420e96d4448037d10c0ee1e647421206c7ceb90442ffa200c5230ee869ab08b38d64ad8752cd41abcac8660fa4f1334f6dd4bc0
@@ -18,9 +18,13 @@ if ARGV.size == 0
18
18
  puts <<-end
19
19
  Usage: imagechan <command> [params]
20
20
  Commands:
21
- - <url> : Download images from <url>
21
+ - <threadurl> : Download images from valid 4chan thread URL
22
22
  - version : Show current version
23
23
  - clearlock : Clear LOCK file
24
+ - where : Show path to images
25
+
26
+ example: $ imagechan http://boards.4chan.org/w/res/1515138
27
+ will download all image from that thread
24
28
  end
25
29
  exit(0)
26
30
  else
@@ -65,7 +69,7 @@ else
65
69
  target_dir = File.join(Imagechan.dir,category,Imagechan.get_folder_name_by_id(thread_id))
66
70
  end
67
71
 
68
- # Locking download for small connection
72
+ # Locking download for slow connection
69
73
  if not File.exists?(File.join(Imagechan.dir,"LOCK"))
70
74
  File.open(File.join(Imagechan.dir,"LOCK"),'w'){|f| f.write ""}
71
75
  else
@@ -73,6 +77,7 @@ else
73
77
  exit(0)
74
78
  end
75
79
 
80
+
76
81
  # Let's the fun begin
77
82
  html_file = open(url)
78
83
  doc = Nokogiri::HTML(html_file)
@@ -82,6 +87,7 @@ puts "There are #{images.size} images"
82
87
  puts "Saving images to #{target_dir}"
83
88
 
84
89
  loop_number = 1
90
+
85
91
  images.each do |image|
86
92
  img = "http:" + image.attr("href")
87
93
  image_filename = img[/[0-9]+\.(jpg|png|gif)/]
@@ -89,18 +95,27 @@ images.each do |image|
89
95
  if File.exists?(File.join(target_dir,image_filename))
90
96
  puts "#{image_filename} exists, skipping..."
91
97
  else
92
- print "downloading #{image_filename}..."
98
+ begin
99
+ print "downloading #{image_filename}..."
93
100
 
94
- # Pure ruby download method
95
- File.open(File.join(target_dir,image_filename),"wb") do |save_file|
96
- open(img,"rb") do |read_file|
97
- save_file.write(read_file.read)
101
+ # Pure ruby download method
102
+ File.open(File.join(target_dir,image_filename),"wb") do |save_file|
103
+ open(img,"rb") do |read_file|
104
+ save_file.write(read_file.read)
105
+ end
98
106
  end
107
+ puts " done!"
108
+ rescue Interrupt
109
+ puts "\nExiting..."
110
+ File.delete(File.join(target_dir,image_filename)) if File.exists? File.join(target_dir,image_filename)
111
+ puts "Removed last image to prevent error"
112
+ File.delete(File.join(Imagechan.dir,"LOCK")) if File.exists? File.join(Imagechan.dir,"LOCK")
113
+ puts "Lock removed"
114
+ exit(0)
99
115
  end
100
- puts " done!"
101
116
  end
102
117
  loop_number += 1
103
118
  end
104
119
 
105
- puts "Your images save in #{target_dir}"
120
+ puts "Your images saved in #{target_dir}"
106
121
  File.delete(File.join(Imagechan.dir,"LOCK")) if File.exists? File.join(Imagechan.dir,"LOCK")
@@ -1,5 +1,5 @@
1
1
  module Imagechan
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
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.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - virtualpain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-11 00:00:00.000000000 Z
11
+ date: 2013-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri