imagechan 0.1.4 → 0.2.0

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: d20405a29d95ff1a6956d4b3c3e745c689dde91c
4
- data.tar.gz: 9d357e9302e566d45fec2fe3fa9f40a6eceb84fa
3
+ metadata.gz: 876f49f4b41c7a5723530327050e625c34607f3b
4
+ data.tar.gz: bea28e45907ab6df60da25e3b525760019c231e0
5
5
  SHA512:
6
- metadata.gz: 161373d7e63ac36fac2563f48e9616bb06a531e6f76f488d9efc43a267ab0bc5500a30482dd0d1deabaaa34d6fe565d9d12a6e02c737986d4f6e24ac23863bec
7
- data.tar.gz: d020c44588af5206cfa6bd77457c341ea6a2171a1db4563e4a0e83378abe04888d6a57e765713e2eabfddb78ecd4c1f18a2363a5adcf239515ca90fe475886b1
6
+ metadata.gz: a82db3460930d2e6573cef97166d16ebcb9b7f54ceec97243e05131dd5bf8169bfd8a8504bc5e6bf4aae304a21b5505a690ca21b2b146e5fd00b90ce97673aeb
7
+ data.tar.gz: c23e642fd454486b0a89a4c8c783fefd3a62971c2812b75cf3c839fd6198fa5fbaaa865b74589950a5cf527729f03a258e878d6236183d81b3123c7845b475d6
@@ -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
- # Preparation
10
+ # Currently available commands
11
+ commands = %w{catalog version clearlock where}
9
12
 
13
+ # Preparation
10
14
  if not File.exists? Imagechan.dir
11
- puts "Preparing directory"
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: $ imagechan <url>
21
- Where <url> is a complete 4chan thread url
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
- url = ARGV.first
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 url.match(/http:\/\/boards\.4chan\.org\/[a-z]+\/res\/[0-9]+/)
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
- # Let's the fun begin
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")
@@ -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}
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Imagechan
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  def self.version
4
4
  return VERSION
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imagechan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - virtualpain