iloveck101 0.1.1 → 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 +4 -4
- data/bin/iloveck101 +48 -22
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4d50e2206fa60de311ee10cd31c3c0746990c74
|
4
|
+
data.tar.gz: 190b1fff19e56b4f28cc1387e4bedf3deb2eb399
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d5924634255db648efd2b76fb4bb2ec3cd44aa2f97e7698e5f1b12db4badcf0a3a3d7867abf26db5a8e3e720c819d3d2becd2a134be09a8275c892f183d6ea3
|
7
|
+
data.tar.gz: be8d894be8bca6d92606a8b49a7e2e8fcd9869d37afd75c6547dbcb24f11f2a268de8b190dce950bf014c10620d4c6a3884901587615bfb47f8df1372fa92644
|
data/bin/iloveck101
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'open-uri'
|
4
3
|
require 'set'
|
5
4
|
require 'fileutils'
|
5
|
+
require 'mechanize'
|
6
6
|
|
7
7
|
def iloveck101(url)
|
8
8
|
page_uri = URI.parse(url)
|
@@ -19,18 +19,42 @@ def iloveck101(url)
|
|
19
19
|
return
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
agent = Mechanize.new
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
page = agent.get(page_uri)
|
25
|
+
|
26
|
+
if not page.search('#messagelogin').empty?
|
27
|
+
puts 'Need to log-in to access this page!'
|
28
|
+
print 'Username: '
|
29
|
+
username = STDIN.gets.chomp
|
30
|
+
print 'Password: '
|
31
|
+
password = STDIN.gets.chomp
|
32
|
+
password_hash = Digest::MD5.hexdigest(password)
|
33
|
+
|
34
|
+
login_result_page = agent.post(
|
35
|
+
'http://ck101.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1',
|
36
|
+
{
|
37
|
+
:quickforawrd => 'yes',
|
38
|
+
:handlekey => 'ls',
|
39
|
+
:username => username,
|
40
|
+
:password => password_hash
|
41
|
+
})
|
42
|
+
if login_result_page.body.match(/succeedhandle_ls/).nil?
|
43
|
+
STDERR.print "Failed to log-in."
|
44
|
+
return
|
45
|
+
end
|
46
|
+
|
47
|
+
page = agent.get(page_uri)
|
48
|
+
end
|
49
|
+
|
50
|
+
title = page.title.split(' - ')[0].gsub('/', '').strip
|
51
|
+
|
52
|
+
puts "Parsing #{title}"
|
28
53
|
|
29
54
|
image_url_set = Set.new(
|
30
|
-
|
31
|
-
.
|
32
|
-
.
|
33
|
-
.find_all { |e| e.index('.thumb.').nil?}
|
55
|
+
page.search('article img[file]')
|
56
|
+
.map { |image_tag| image_tag['file'] }
|
57
|
+
.find_all { |image_url| image_url.index('.thumb.').nil?}
|
34
58
|
)
|
35
59
|
|
36
60
|
target_folder_path = File.expand_path("~/Pictures/iloveck101/#{thread_id} - #{title}")
|
@@ -38,20 +62,22 @@ def iloveck101(url)
|
|
38
62
|
FileUtils.mkdir_p(target_folder_path)
|
39
63
|
end
|
40
64
|
|
65
|
+
puts "Found #{image_url_set.length} images."
|
66
|
+
|
41
67
|
image_url_set.each { |image_url|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
68
|
+
puts "Downloading #{image_url}"
|
69
|
+
|
70
|
+
image = agent.get(image_url)
|
71
|
+
|
72
|
+
filename = File.expand_path(File.basename(image.uri.path), target_folder_path)
|
73
|
+
image.save(filename)
|
47
74
|
}
|
48
75
|
|
76
|
+
puts 'Done!'
|
49
77
|
end
|
50
78
|
|
51
|
-
if
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|
79
|
+
if ARGV.length >= 1
|
80
|
+
iloveck101(ARGV[0])
|
81
|
+
else
|
82
|
+
STDERR.print "Usage: #{File.basename($0)} URL\n"
|
83
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iloveck101
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- WanCW
|
@@ -9,7 +9,21 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2013-12-03 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mechanize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.7.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.7.3
|
13
27
|
description: Download images from ck101 thread, inspired by tzangms.
|
14
28
|
email: wancw.wang@gmail.com
|
15
29
|
executables:
|