pixiv 0.0.4 → 0.0.5
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.
- data/README.md +32 -0
- data/console_helper.rb +12 -0
- data/lib/pixiv.rb +2 -0
- data/lib/pixiv/bookmark_list.rb +3 -3
- data/lib/pixiv/client.rb +14 -2
- data/lib/pixiv/error.rb +1 -0
- data/lib/pixiv/illust.rb +20 -6
- data/lib/pixiv/illust_list.rb +30 -9
- data/lib/pixiv/member.rb +29 -9
- data/lib/pixiv/owned_illust_list.rb +18 -2
- data/lib/pixiv/page.rb +3 -0
- data/lib/pixiv/page_collection.rb +16 -9
- data/lib/pixiv/search_result_list.rb +128 -0
- data/lib/pixiv/version.rb +1 -1
- data/lib/pixiv/work_list.rb +2 -2
- metadata +9 -3
data/README.md
CHANGED
@@ -32,6 +32,38 @@ Or install it yourself as:
|
|
32
32
|
|
33
33
|
$ gem install pixiv
|
34
34
|
|
35
|
+
## Synopsis
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
|
39
|
+
pixiv = Pixiv.client('pixiv_id', 'password') {|agent|
|
40
|
+
agent.user_agent_alias = 'Mac Safari'
|
41
|
+
}
|
42
|
+
|
43
|
+
illust_id = 123
|
44
|
+
illust = pixiv.illust(illust_id)
|
45
|
+
if illust.manga?
|
46
|
+
pixiv.download_manga(illust, ['manga/', :image_name])
|
47
|
+
else
|
48
|
+
pixiv.download_illust(illust, ['illust/', :image_name])
|
49
|
+
end
|
50
|
+
|
51
|
+
member_id = 456
|
52
|
+
member = pixiv.member(member_id)
|
53
|
+
member.works.each do |illust|
|
54
|
+
puts illust.title
|
55
|
+
puts illust.caption
|
56
|
+
end
|
57
|
+
|
58
|
+
me = pixiv.member
|
59
|
+
me.bookmarks do |illust|
|
60
|
+
author = illust.member
|
61
|
+
puts author.name
|
62
|
+
puts author.works.count
|
63
|
+
end
|
64
|
+
|
65
|
+
```
|
66
|
+
|
35
67
|
## Usage
|
36
68
|
|
37
69
|
See [a sample script](https://gist.github.com/4362297)
|
data/console_helper.rb
CHANGED
@@ -51,6 +51,14 @@ def PBL(p = 1)
|
|
51
51
|
$pixiv.private_bookmark_list(p)
|
52
52
|
end
|
53
53
|
|
54
|
+
def SRL(query, opts = {})
|
55
|
+
$pixiv.search_result_list(query, opts)
|
56
|
+
end
|
57
|
+
|
58
|
+
def Is(list)
|
59
|
+
$pixiv.illusts(list)
|
60
|
+
end
|
61
|
+
|
54
62
|
def Ws(member)
|
55
63
|
$pixiv.works(member)
|
56
64
|
end
|
@@ -58,3 +66,7 @@ end
|
|
58
66
|
def Bs(member)
|
59
67
|
$pixiv.bookmarks(member)
|
60
68
|
end
|
69
|
+
|
70
|
+
def S(query, opts = {})
|
71
|
+
$pixiv.search(query, opts)
|
72
|
+
end
|
data/lib/pixiv.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'mechanize'
|
2
|
+
require 'uri'
|
2
3
|
|
3
4
|
module Pixiv
|
4
5
|
autoload :BookmarkList, 'pixiv/bookmark_list'
|
@@ -11,6 +12,7 @@ module Pixiv
|
|
11
12
|
autoload :Page, 'pixiv/page'
|
12
13
|
autoload :PageCollection, 'pixiv/page_collection'
|
13
14
|
autoload :PrivateBookmarkList, 'pixiv/bookmark_list'
|
15
|
+
autoload :SearchResultList, 'pixiv/search_result_list'
|
14
16
|
autoload :WorkList, 'pixiv/work_list'
|
15
17
|
|
16
18
|
ROOT_URL = 'http://www.pixiv.net'
|
data/lib/pixiv/bookmark_list.rb
CHANGED
@@ -8,7 +8,7 @@ module Pixiv
|
|
8
8
|
# @return [Integer]
|
9
9
|
lazy_attr_reader(:total_count) {
|
10
10
|
node = at!('a[href="/bookmark.php?type=illust_all"]')
|
11
|
-
node.inner_text
|
11
|
+
node.inner_text[/\d+/].to_i
|
12
12
|
}
|
13
13
|
# @return [Array<Hash{Symbol=>Object}, nil>]
|
14
14
|
lazy_attr_reader(:page_hashes) {
|
@@ -26,12 +26,12 @@ module Pixiv
|
|
26
26
|
return nil if node.at('img[src*="limit_unknown_s.png"]')
|
27
27
|
member_node = node.at('a[href^="member_illust.php?id="]')
|
28
28
|
illust_node = node.at('a')
|
29
|
-
illust_id = illust_node['href']
|
29
|
+
illust_id = illust_node['href'][/illust_id=(\d+)/, 1].to_i
|
30
30
|
{
|
31
31
|
url: Illust.url(illust_id),
|
32
32
|
illust_id: illust_id,
|
33
33
|
title: illust_node.inner_text,
|
34
|
-
member_id: member_node['href']
|
34
|
+
member_id: member_node['href'][/\?id=(\d+)/, 1].to_i,
|
35
35
|
member_name: member_node.inner_text,
|
36
36
|
small_image_url: illust_node.at('img')['src'],
|
37
37
|
}
|
data/lib/pixiv/client.rb
CHANGED
@@ -83,12 +83,19 @@ module Pixiv
|
|
83
83
|
end
|
84
84
|
|
85
85
|
# @param [Pixiv::Member, Integer] member_or_id
|
86
|
-
# @param [Integer]
|
86
|
+
# @param [Integer] page
|
87
87
|
# @return [Pixiv::PrivateBookmarkList] private bookmark list bound to +self+
|
88
88
|
def private_bookmark_list(member_or_id = member_id, page = 1)
|
89
89
|
illust_list_with_class(PrivateBookmarkList, member_or_id, page)
|
90
90
|
end
|
91
91
|
|
92
|
+
def search_result_list(query, opts = {})
|
93
|
+
attrs = {query: query, search_opts: opts}
|
94
|
+
SearchResultList.lazy_new(attrs) {
|
95
|
+
agent.get(SearchResultList.url(query, opts))
|
96
|
+
}.bind(self)
|
97
|
+
end
|
98
|
+
|
92
99
|
# @param [Pixiv::IllustList] list
|
93
100
|
# @!macro [new] opts_and_return
|
94
101
|
# @param [Hash] opts
|
@@ -119,6 +126,11 @@ module Pixiv
|
|
119
126
|
illusts(private_bookmark_list(member_id, page), opts)
|
120
127
|
end
|
121
128
|
|
129
|
+
# (see {SearchResultList.url})
|
130
|
+
def search(query, opts = {})
|
131
|
+
illusts(search_result_list(query, opts))
|
132
|
+
end
|
133
|
+
|
122
134
|
# Downloads the image to +io_or_filename+
|
123
135
|
# @param [Pixiv::Illust] illust
|
124
136
|
# @param [#write, String, Array<String, Symbol, #call>] io_or_filename io or filename or pattern for {#filename_from_pattern}
|
@@ -209,7 +221,7 @@ module Pixiv
|
|
209
221
|
end
|
210
222
|
|
211
223
|
def member_id_from_mypage(doc)
|
212
|
-
doc.at('.profile_area a')['href']
|
224
|
+
doc.at('.profile_area a')['href'][/\d+$/].to_i
|
213
225
|
end
|
214
226
|
end
|
215
227
|
|
data/lib/pixiv/error.rb
CHANGED
data/lib/pixiv/illust.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Pixiv
|
4
4
|
class Illust < Page
|
5
|
+
# @!parse
|
6
|
+
# include ::Pixiv::Illust::WithClient
|
7
|
+
|
5
8
|
# Returns the URL for given +illust_id+
|
6
9
|
# @param [Integer] illust_id
|
7
10
|
# @return [String]
|
@@ -28,14 +31,16 @@ module Pixiv
|
|
28
31
|
lazy_attr_reader(:member_id) { at!('#rpc_u_id')['title'].to_i }
|
29
32
|
# @return [String]
|
30
33
|
lazy_attr_reader(:member_name) {
|
31
|
-
at
|
34
|
+
# Note: generally member_name can easily be found at +at('.profile_area a')['title']+
|
35
|
+
# but this is not the case on your own illust page; so this hack.
|
36
|
+
at!('title').inner_text[%r!^「#{Regexp.escape(title)}」/「(.+)」の(?:イラスト|漫画) \[pixiv\]$!, 1]
|
32
37
|
}
|
33
38
|
# @return [String]
|
34
39
|
lazy_attr_reader(:title) { at!('.work-info h1.title').inner_text }
|
35
40
|
# @return [Integer, nil]
|
36
41
|
lazy_attr_reader(:num_pages) {
|
37
42
|
node = doc.at('//ul[@class="meta"]/li[2]')
|
38
|
-
n = node ? node.inner_text
|
43
|
+
n = node ? node.inner_text[/(\d+)P$/, 1] : nil
|
39
44
|
n && n.to_i
|
40
45
|
}
|
41
46
|
# @return [Array<String>]
|
@@ -53,6 +58,8 @@ module Pixiv
|
|
53
58
|
lazy_attr_reader(:score) { at!('.score-count').inner_text.to_i }
|
54
59
|
|
55
60
|
alias id illust_id
|
61
|
+
alias author_id member_id
|
62
|
+
alias author_name member_name
|
56
63
|
alias original_image_referrer original_image_referer # referrer vs. referer
|
57
64
|
|
58
65
|
# @return [String]
|
@@ -74,19 +81,26 @@ module Pixiv
|
|
74
81
|
end
|
75
82
|
|
76
83
|
module Illust::WithClient
|
77
|
-
include Page::WithClient
|
84
|
+
include ::Pixiv::Page::WithClient
|
78
85
|
|
79
86
|
# @return [Pixiv::Member]
|
80
87
|
def member
|
81
|
-
|
88
|
+
attrs = {member_id: member_id, member_name: member_name}
|
89
|
+
Member.lazy_new(attrs) { client.agent.get(Member.url(member_id)) }
|
82
90
|
end
|
83
91
|
|
84
|
-
|
92
|
+
alias author member
|
93
|
+
|
94
|
+
# Download illust
|
95
|
+
#
|
96
|
+
# See {Pixiv::Client#download_illust} for the detail.
|
85
97
|
def download_illust(io_or_filename, size = :original)
|
86
98
|
client.download_illust(self, io_or_filename, size)
|
87
99
|
end
|
88
100
|
|
89
|
-
#
|
101
|
+
# Download manga
|
102
|
+
#
|
103
|
+
# See {Pixiv::Client#download_manga} for the detail.
|
90
104
|
def download_manga(pattern, &block)
|
91
105
|
client.download_manga(self, pattern, &block)
|
92
106
|
end
|
data/lib/pixiv/illust_list.rb
CHANGED
@@ -1,7 +1,18 @@
|
|
1
1
|
module Pixiv
|
2
2
|
# @abstract
|
3
3
|
class IllustList < Page
|
4
|
-
|
4
|
+
# @!parse
|
5
|
+
# include ::Pixiv::IllustList::WithClient
|
6
|
+
|
7
|
+
include ::Pixiv::PageCollection
|
8
|
+
|
9
|
+
def doc
|
10
|
+
unless @doc
|
11
|
+
super
|
12
|
+
check_bounds!
|
13
|
+
end
|
14
|
+
@doc
|
15
|
+
end
|
5
16
|
|
6
17
|
# @return [Integer]
|
7
18
|
attr_reader :page
|
@@ -22,18 +33,17 @@ module Pixiv
|
|
22
33
|
page_hashes
|
23
34
|
end
|
24
35
|
|
25
|
-
|
36
|
+
protected
|
26
37
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
page_urls
|
38
|
+
def check_bounds!
|
39
|
+
max_page = total_count / max_size + 1
|
40
|
+
raise Error::OutOfBounds unless (1..max_page).include?(page)
|
31
41
|
end
|
32
42
|
end
|
33
43
|
|
34
44
|
module IllustList::WithClient
|
35
|
-
include Page::WithClient
|
36
|
-
include Enumerable
|
45
|
+
include ::Pixiv::Page::WithClient
|
46
|
+
include ::Enumerable
|
37
47
|
|
38
48
|
# @yieldparam [Illust] illust
|
39
49
|
def each
|
@@ -42,5 +52,16 @@ module Pixiv
|
|
42
52
|
yield Illust.lazy_new(attrs) { client.agent.get(url) }
|
43
53
|
end
|
44
54
|
end
|
55
|
+
|
56
|
+
# @return [Illust, nil]
|
57
|
+
def next
|
58
|
+
return if last?
|
59
|
+
self.class.lazy_new(next_attrs) { client.agent.get(next_url) }
|
60
|
+
end
|
61
|
+
|
62
|
+
def prev
|
63
|
+
return if first?
|
64
|
+
self.class.lazy_new(next_attrs) { client.agent.get(prev_url) }
|
65
|
+
end
|
45
66
|
end
|
46
|
-
end
|
67
|
+
end
|
data/lib/pixiv/member.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module Pixiv
|
2
2
|
class Member < Page
|
3
|
+
# @!parse
|
4
|
+
# include ::Pixiv::Member::WithClient
|
5
|
+
|
3
6
|
# Returns the URL for given +member_id+
|
4
7
|
# @param [Integer] member_id
|
5
8
|
# @return [String]
|
@@ -11,8 +14,11 @@ module Pixiv
|
|
11
14
|
lazy_attr_reader(:name) { at!('.profile_area h2').inner_text }
|
12
15
|
# @return [Integer]
|
13
16
|
lazy_attr_reader(:member_id) { at!('input[name="user_id"]')['value'].to_i }
|
14
|
-
# return [Integer]
|
15
|
-
lazy_attr_reader(:pixiv_id) {
|
17
|
+
# @return [Integer]
|
18
|
+
lazy_attr_reader(:pixiv_id) { profile_image_url[%r{/profile/([a-z_-]+)/}, 1] }
|
19
|
+
# @return [String]
|
20
|
+
lazy_attr_reader(:profile_image_url) { at!('.profile_area img')['src'] }
|
21
|
+
|
16
22
|
|
17
23
|
alias id member_id
|
18
24
|
|
@@ -21,16 +27,30 @@ module Pixiv
|
|
21
27
|
end
|
22
28
|
|
23
29
|
module Member::WithClient
|
24
|
-
include Page::WithClient
|
30
|
+
include ::Pixiv::Page::WithClient
|
31
|
+
|
32
|
+
def work_list(page = 1)
|
33
|
+
client.work_list(self, page)
|
34
|
+
end
|
35
|
+
|
36
|
+
def bookmark_list(page = 1)
|
37
|
+
client.bookmark_list(self, page)
|
38
|
+
end
|
39
|
+
|
40
|
+
def private_bookmark_list(page = 1)
|
41
|
+
client.private_bookmark_list(self, page)
|
42
|
+
end
|
43
|
+
|
44
|
+
def works(page = 1, &block)
|
45
|
+
client.works(self, page, &block)
|
46
|
+
end
|
25
47
|
|
26
|
-
|
27
|
-
|
28
|
-
client.bookmark_list(self, page_num)
|
48
|
+
def bookmarks(page = 1, &block)
|
49
|
+
client.bookmarks(self, page, &block)
|
29
50
|
end
|
30
51
|
|
31
|
-
|
32
|
-
|
33
|
-
client.bookmarks(self, page_num, &block)
|
52
|
+
def private_bookmarks(page = 1, &block)
|
53
|
+
client.private_bookmarks(page, &block)
|
34
54
|
end
|
35
55
|
end
|
36
56
|
end
|
@@ -5,6 +5,11 @@ module Pixiv
|
|
5
5
|
#
|
6
6
|
# Implements common methods for bookmark.php and member_illust.php.
|
7
7
|
class OwnedIllustList < IllustList
|
8
|
+
# @!parse
|
9
|
+
# include ::Pixiv::OwnedIllustList::WithClient
|
10
|
+
|
11
|
+
ILLUSTS_PER_PAGE = 20
|
12
|
+
|
8
13
|
# Returns the URL for given +member_id+ and +page+
|
9
14
|
# @param [Integer] member_id
|
10
15
|
# @param [Integer] page
|
@@ -23,7 +28,7 @@ module Pixiv
|
|
23
28
|
}
|
24
29
|
# @return [Integer]
|
25
30
|
lazy_attr_reader(:member_id) {
|
26
|
-
doc.body
|
31
|
+
doc.body[/pixiv\.context\.userId = '(\d+)'/, 1].to_i
|
27
32
|
}
|
28
33
|
|
29
34
|
# @return [String]
|
@@ -45,14 +50,25 @@ module Pixiv
|
|
45
50
|
def prev_url
|
46
51
|
first? ? nil : self.class.url(member_id, page - 1)
|
47
52
|
end
|
53
|
+
|
54
|
+
# @return [Integer]
|
55
|
+
def max_size
|
56
|
+
ILLUSTS_PER_PAGE
|
57
|
+
end
|
58
|
+
|
59
|
+
# @!parse alias owner_id member_id
|
60
|
+
def owner_id; member_id end
|
48
61
|
end
|
49
62
|
|
50
63
|
module OwnedIllustList::WithClient
|
51
|
-
include IllustList::WithClient
|
64
|
+
include ::Pixiv::IllustList::WithClient
|
52
65
|
|
53
66
|
# @return [Pixiv::Member]
|
54
67
|
def member
|
55
68
|
client.member(member_id)
|
56
69
|
end
|
70
|
+
|
71
|
+
# @!parse alias owner member
|
72
|
+
def owner; member end
|
57
73
|
end
|
58
74
|
end
|
data/lib/pixiv/page.rb
CHANGED
@@ -24,6 +24,14 @@ module Pixiv
|
|
24
24
|
not_implemented!
|
25
25
|
end
|
26
26
|
|
27
|
+
def next_attrs
|
28
|
+
{}
|
29
|
+
end
|
30
|
+
|
31
|
+
def prev_attrs
|
32
|
+
{}
|
33
|
+
end
|
34
|
+
|
27
35
|
def page_class
|
28
36
|
not_implemented!
|
29
37
|
end
|
@@ -32,10 +40,6 @@ module Pixiv
|
|
32
40
|
not_implemented!
|
33
41
|
end
|
34
42
|
|
35
|
-
def page_urls
|
36
|
-
page_hashes.map {|h| h[:url] }
|
37
|
-
end
|
38
|
-
|
39
43
|
def size
|
40
44
|
page_hashes.size
|
41
45
|
end
|
@@ -84,15 +88,18 @@ module Pixiv
|
|
84
88
|
loop do
|
85
89
|
yield collection
|
86
90
|
next_url = collection.next_url or break
|
87
|
-
|
91
|
+
next_attrs = collection.next_attrs
|
92
|
+
collection = collection.class.lazy_new(next_attrs) { @client.agent.get(next_url) }
|
88
93
|
end
|
89
94
|
end
|
90
95
|
|
91
|
-
def
|
92
|
-
if
|
93
|
-
|
96
|
+
def size
|
97
|
+
if @collection.first? && @collection.respond_to?(:total_count)
|
98
|
+
@collection.total_count
|
99
|
+
elsif @collection.respond_to?(:max_size) && @collection.respond_to?(:total_count)
|
100
|
+
@collection.total_count - (@collection.max_size * (@collection.page - 1))
|
94
101
|
else
|
95
|
-
|
102
|
+
count { true }
|
96
103
|
end
|
97
104
|
end
|
98
105
|
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module Pixiv
|
2
|
+
class SearchResultList < IllustList
|
3
|
+
ILLUSTS_PER_PAGE = 20
|
4
|
+
|
5
|
+
=begin Coming Real Soon Now
|
6
|
+
# @param [String, Array<query>, Set<query>] query
|
7
|
+
#
|
8
|
+
# @option opts [query, nil] :tag (nil) same as +url(query, mode: :tag)+
|
9
|
+
# @option opts [query, nil] :word (nil) same as +url(query, mode: :word)+
|
10
|
+
# @option opts [:tag, :word] :mode (:tag)
|
11
|
+
# @option opts [Boolean] :exact (false) perform exact match (for tag mode only)
|
12
|
+
#
|
13
|
+
# @option opts [:illust, :manga, :both, nil] :type (nil)
|
14
|
+
# * +:illust+: search only for non-manga illust
|
15
|
+
# *+:manga+: search only for manga
|
16
|
+
# * +:both+ or +nil+: search for the both type
|
17
|
+
#
|
18
|
+
# @option opts [:tall, :wide, :square, nil] :ratio (nil)
|
19
|
+
# @option opts [String, nil] :tool tool name
|
20
|
+
# @option opts [Boolean] :r18 (false) X-rated only
|
21
|
+
# @option opts [Date, nil] :since (nil)
|
22
|
+
# @option opts [Integer, nil] :page (nil)
|
23
|
+
#
|
24
|
+
# @option opts [Array<(Integer, Integer)>, nil] :max_size (nil)
|
25
|
+
# maximum size as +[width, height]+ (either +width+ or +height+ can be +nil+)
|
26
|
+
# @option opts [Array<(Integer, Integer)>, nil] :min_size (nil)
|
27
|
+
# minimum size as +[width, height]+ (either +width+ or +height+ can be +nil+)
|
28
|
+
# @option opts [:small, :medium, :large, nil] :size (nil)
|
29
|
+
# * +:small+ for +:max_size => [1000, 1000]+
|
30
|
+
# * +:medium+ for +:max_size => [3000, 3000], :min_size => [1001, 1001]+
|
31
|
+
# * +:large+ for +:min_size => +[3001, 3001]+
|
32
|
+
#
|
33
|
+
# @example
|
34
|
+
# s = SearchResultList
|
35
|
+
# # Query
|
36
|
+
# s.url('tag1')
|
37
|
+
# s.url(%w[tag1 tag2]) # tag1 AND tag2
|
38
|
+
# s.url([Set.new('tag1', 'tag2'), 'tag3']) # (tag1 OR tag2) AND tag3
|
39
|
+
# # Mode
|
40
|
+
# s.url(%w[tag1 tag2]) # implicitly searches by tags
|
41
|
+
# s.url(%w[tag1 tag2], mode: :tag) # or explicitly
|
42
|
+
# s.url(tag: %w[tag1 tag2]) # same as above
|
43
|
+
# s.url('word', mode: :word) # searches by words
|
44
|
+
# s.url(word: 'word') # same as above
|
45
|
+
# # Options
|
46
|
+
# # s.url(%w[tag1 tag2], exact: true, type: :illust, r18: false, size: :large)
|
47
|
+
#
|
48
|
+
=end
|
49
|
+
|
50
|
+
#
|
51
|
+
def self.url(query, opts = {})
|
52
|
+
word = URI::encode_www_form({word: query})
|
53
|
+
"#{ROOT_URL}/search.php?s_mode=s_tag&#{word}&p=#{opts[:page] || 1}" # FIXME
|
54
|
+
end
|
55
|
+
|
56
|
+
def initialize(doc_or_doc_creator, attrs = {})
|
57
|
+
raise ArgumentError, "`attrs[:query]' must be present" unless attrs[:query]
|
58
|
+
raise ArgumentError, "`attrs[:search_opts]' must be present" unless attrs[:search_opts]
|
59
|
+
super
|
60
|
+
end
|
61
|
+
|
62
|
+
attr_reader :query
|
63
|
+
attr_reader :search_opts
|
64
|
+
|
65
|
+
lazy_attr_reader(:page) {
|
66
|
+
at!('.pager li.current').inner_text.to_i
|
67
|
+
}
|
68
|
+
lazy_attr_reader(:last?) {
|
69
|
+
doc.at('//nav[@class="pager"]//a[@rel="next"]').nil?
|
70
|
+
}
|
71
|
+
lazy_attr_reader(:total_count) {
|
72
|
+
at!('.info > .count').inner_text.to_i
|
73
|
+
}
|
74
|
+
lazy_attr_reader(:page_hashes) {
|
75
|
+
search!('#search-result li.image').map {|n| hash_from_list_item(n) }
|
76
|
+
}
|
77
|
+
|
78
|
+
def url
|
79
|
+
self.class.url(query, search_opts)
|
80
|
+
end
|
81
|
+
|
82
|
+
def first?
|
83
|
+
page == 1
|
84
|
+
end
|
85
|
+
|
86
|
+
def next_url
|
87
|
+
return if last?
|
88
|
+
opts = search_opts.dup
|
89
|
+
opts[:page] = page + 1
|
90
|
+
self.class.url(query, opts)
|
91
|
+
end
|
92
|
+
|
93
|
+
def prev_url
|
94
|
+
return if first?
|
95
|
+
opts = query_opts.dup
|
96
|
+
opts[:page] = page - 1
|
97
|
+
self.class.url(query, opts)
|
98
|
+
end
|
99
|
+
|
100
|
+
def next_attrs
|
101
|
+
{query: query, search_opts: search_opts, page: page + 1}
|
102
|
+
end
|
103
|
+
|
104
|
+
def prev_attrs
|
105
|
+
{query: query, search_opts: search_opts, page: page - 1}
|
106
|
+
end
|
107
|
+
|
108
|
+
def max_size
|
109
|
+
ILLUSTS_PER_PAGE
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def hash_from_list_item(node)
|
115
|
+
member_node = node.at('p.user a')
|
116
|
+
illust_node = node.at('a')
|
117
|
+
illust_id = illust_node['href'][/illust_id=(\d+)/, 1].to_i
|
118
|
+
{
|
119
|
+
url: Illust.url(illust_id),
|
120
|
+
illust_id: illust_id,
|
121
|
+
title: illust_node.at('h2').inner_text,
|
122
|
+
member_id: member_node['href'][/\?id=(\d+)/, 1].to_i,
|
123
|
+
member_name: member_node.inner_text,
|
124
|
+
small_image_url: illust_node.at('img')['src'],
|
125
|
+
}
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
data/lib/pixiv/version.rb
CHANGED
data/lib/pixiv/work_list.rb
CHANGED
@@ -8,7 +8,7 @@ module Pixiv
|
|
8
8
|
# @return [Integer]
|
9
9
|
lazy_attr_reader(:total_count) {
|
10
10
|
node = at!('.layout-cell .count-badge')
|
11
|
-
node.inner_text
|
11
|
+
node.inner_text[/\d+/].to_i
|
12
12
|
}
|
13
13
|
# @return [Array<Hash{Symbol=>Object}, nil>]
|
14
14
|
lazy_attr_reader(:page_hashes) {
|
@@ -24,7 +24,7 @@ module Pixiv
|
|
24
24
|
def hash_from_list_item(node)
|
25
25
|
return nil if node.at('img[src*="limit_unknown_s.png"]')
|
26
26
|
illust_node = node.at('a')
|
27
|
-
illust_id = illust_node['href']
|
27
|
+
illust_id = illust_node['href'][/illust_id=(\d+)/, 1].to_i
|
28
28
|
{
|
29
29
|
url: Illust.url(illust_id),
|
30
30
|
illust_id: illust_id,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixiv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mechanize
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- lib/pixiv/owned_illust_list.rb
|
100
100
|
- lib/pixiv/page.rb
|
101
101
|
- lib/pixiv/page_collection.rb
|
102
|
+
- lib/pixiv/search_result_list.rb
|
102
103
|
- lib/pixiv/version.rb
|
103
104
|
- lib/pixiv/work_list.rb
|
104
105
|
- pixiv.gemspec
|
@@ -121,12 +122,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
122
|
- - ! '>='
|
122
123
|
- !ruby/object:Gem::Version
|
123
124
|
version: '0'
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
hash: -4267183313172500808
|
124
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
129
|
none: false
|
126
130
|
requirements:
|
127
131
|
- - ! '>='
|
128
132
|
- !ruby/object:Gem::Version
|
129
133
|
version: '0'
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
hash: -4267183313172500808
|
130
137
|
requirements: []
|
131
138
|
rubyforge_project:
|
132
139
|
rubygems_version: 1.8.24
|
@@ -141,4 +148,3 @@ test_files:
|
|
141
148
|
- spec/pixiv/member_spec.rb
|
142
149
|
- spec/pixiv/page_spec.rb
|
143
150
|
- spec/spec_helper.rb
|
144
|
-
has_rdoc:
|