javlibrary 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 +4 -4
- data/lib/javlibrary.rb +48 -32
- data/lib/javlibrary/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c397e79bab44e6163aa9c2fd0b854b449e8d0db9
|
4
|
+
data.tar.gz: 8dfbd699be7a1f259c1adf89a75914aa08aa8803
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d13f2461c778dd98578dd81e99a2d7a1767906a1663f09740ca2f8f5561a1d03f9f70870b1aded735e8beb38448dbaf44ff3d275f342ecf2173e9c8c8a4b094d
|
7
|
+
data.tar.gz: 847f291b7087b8975690bd144aaae583174edfa36724c86c24e4ee162fdc2a7de0faa0c313adab5669a32457c3a216859789a704ab4fb9581f272249c765c384
|
data/lib/javlibrary.rb
CHANGED
@@ -6,18 +6,28 @@ require 'nokogiri'
|
|
6
6
|
require 'mysql2'
|
7
7
|
require 'pp'
|
8
8
|
|
9
|
-
|
9
|
+
class Javlibrary
|
10
|
+
JAVLIBRARY_URL = [ "jav11b.com", "javlibrary.com" ]
|
11
|
+
|
12
|
+
def initialize(database_name = 'javlibrary', user = 'root', pwd = 'default')
|
13
|
+
# Define client variable
|
14
|
+
@database = database_name
|
15
|
+
@username = user
|
16
|
+
@password = pwd
|
17
|
+
|
18
|
+
# Define default Javlibrary url
|
19
|
+
@url = JAVLIBRARY_URL[0]
|
20
|
+
end
|
10
21
|
|
11
|
-
module Javlibrary
|
12
22
|
def client
|
13
23
|
client = Mysql2::Client.new(:host => "127.0.0.1",
|
14
|
-
:username =>
|
15
|
-
:password =>
|
16
|
-
:database =>
|
24
|
+
:username => @user,
|
25
|
+
:password => @password,
|
26
|
+
:database => @database)
|
17
27
|
end
|
18
28
|
|
19
|
-
def
|
20
|
-
baseurl = "http://www
|
29
|
+
def downloader(identifer)
|
30
|
+
baseurl = "http://www.#{@url}/cn/?v=#{identifer}"
|
21
31
|
response = Mechanize.new
|
22
32
|
response.user_agent = Mechanize::AGENT_ALIASES.values[rand(21)]
|
23
33
|
begin
|
@@ -53,7 +63,7 @@ module Javlibrary
|
|
53
63
|
#result["cast"] = details[-1]; result["genres"] = video_genres; result["img_url"] = video_jacket_img
|
54
64
|
end
|
55
65
|
|
56
|
-
def
|
66
|
+
def video_info_insert(client, index, identifer, actor_hash, genres_hash)
|
57
67
|
title, id, date, director, maker, label, cast_tmp, genres_tmp, img_url = downloader(identifer).split('$')
|
58
68
|
cast = cast_tmp.split.reject(&:empty?)
|
59
69
|
genres = genres_tmp.split.reject(&:empty?)
|
@@ -79,8 +89,8 @@ module Javlibrary
|
|
79
89
|
client.close
|
80
90
|
end
|
81
91
|
|
82
|
-
def
|
83
|
-
client =
|
92
|
+
def download_all_videos
|
93
|
+
client = client
|
84
94
|
result = client.query("SELECT video_num, video_label FROM label WHERE video_download=0")
|
85
95
|
client.close
|
86
96
|
|
@@ -90,6 +100,7 @@ module Javlibrary
|
|
90
100
|
end
|
91
101
|
|
92
102
|
video_array = video_array.each_slice(5000).to_a
|
103
|
+
|
93
104
|
actor_hash = Javlibrary::actor_hash
|
94
105
|
genre_hash = Javlibrary::genre_hash
|
95
106
|
thread_pool = Array::new
|
@@ -97,7 +108,7 @@ module Javlibrary
|
|
97
108
|
video_array.each do |group|
|
98
109
|
# Create a download thread
|
99
110
|
thread_temp = Thread.new {
|
100
|
-
client =
|
111
|
+
client = client
|
101
112
|
group.each do |item|
|
102
113
|
begin
|
103
114
|
video_info_insert(client, item['video_num'], item['video_label'],
|
@@ -107,6 +118,7 @@ module Javlibrary
|
|
107
118
|
end
|
108
119
|
end
|
109
120
|
client.close
|
121
|
+
GC.start
|
110
122
|
}
|
111
123
|
thread_pool << thread_temp
|
112
124
|
end
|
@@ -114,7 +126,7 @@ module Javlibrary
|
|
114
126
|
end
|
115
127
|
|
116
128
|
def actor_hash
|
117
|
-
client =
|
129
|
+
client = client
|
118
130
|
actor_hash = Hash.new
|
119
131
|
client.query("SELECT * FROM actor").each do |item|
|
120
132
|
actor_hash["#{item['actor_name']}"] = item['actor_id']
|
@@ -125,7 +137,7 @@ module Javlibrary
|
|
125
137
|
end
|
126
138
|
|
127
139
|
def genre_hash
|
128
|
-
client =
|
140
|
+
client = client
|
129
141
|
category_hash = Hash.new
|
130
142
|
client.query("SELECT * FROM category").each do |item|
|
131
143
|
category_hash["#{item['category_name']}"] = item['category_id']
|
@@ -135,10 +147,10 @@ module Javlibrary
|
|
135
147
|
category_hash
|
136
148
|
end
|
137
149
|
|
138
|
-
def
|
150
|
+
def genres
|
139
151
|
response = Mechanize.new; genres = Array.new
|
140
152
|
begin
|
141
|
-
response.get "http://www
|
153
|
+
response.get "http://www.#{@url}/cn/genres.php"
|
142
154
|
rescue
|
143
155
|
retry
|
144
156
|
end
|
@@ -150,7 +162,7 @@ module Javlibrary
|
|
150
162
|
end
|
151
163
|
|
152
164
|
def genres_insert
|
153
|
-
client =
|
165
|
+
client = client
|
154
166
|
genres = genres()
|
155
167
|
genres.each do |e|
|
156
168
|
begin
|
@@ -163,7 +175,9 @@ module Javlibrary
|
|
163
175
|
client.close
|
164
176
|
end
|
165
177
|
|
166
|
-
|
178
|
+
alias download_all_genres genres_insert
|
179
|
+
|
180
|
+
def author_page_num(nokogiri_doc)
|
167
181
|
last_page = 1
|
168
182
|
nokogiri_doc.search('//div[@class="page_selector"]/a[@class="page last"]').each do |row|
|
169
183
|
last_page = row['href'].split("=")[-1].to_i
|
@@ -172,9 +186,9 @@ module Javlibrary
|
|
172
186
|
end
|
173
187
|
|
174
188
|
def get_all_actor
|
175
|
-
firsturl = "http://www
|
189
|
+
firsturl = "http://www.#{@url}/cn/star_list.php?prefix="
|
176
190
|
|
177
|
-
client =
|
191
|
+
client = client
|
178
192
|
'A'.upto('Z') do |alphabet|
|
179
193
|
tempurl = firsturl + alphabet
|
180
194
|
begin
|
@@ -212,9 +226,11 @@ module Javlibrary
|
|
212
226
|
client.close
|
213
227
|
end
|
214
228
|
|
215
|
-
|
216
|
-
|
217
|
-
|
229
|
+
alias download_all_actors get_all_actor
|
230
|
+
|
231
|
+
def download_video_label(actor_id)
|
232
|
+
firsturl = "http://www.#{@url}/ja/vl_star.php?s=#{actor_id}"
|
233
|
+
baseurl = "http://www.#{@url}/ja/vl_star.php?&mode=&s=#{actor_id}&page="
|
218
234
|
|
219
235
|
begin
|
220
236
|
response = RestClient.get firsturl
|
@@ -246,7 +262,7 @@ module Javlibrary
|
|
246
262
|
end
|
247
263
|
end
|
248
264
|
|
249
|
-
client =
|
265
|
+
client = client
|
250
266
|
result.each do |e|
|
251
267
|
begin
|
252
268
|
client.query("INSERT INTO label (video_label, video_download) VALUES ('#{e}', '0')")
|
@@ -257,8 +273,8 @@ module Javlibrary
|
|
257
273
|
client.close
|
258
274
|
end
|
259
275
|
|
260
|
-
def
|
261
|
-
client =
|
276
|
+
def select_actor(type)
|
277
|
+
client = client
|
262
278
|
result = client.query("SELECT actor_label FROM actor WHERE type='#{type}'")
|
263
279
|
client.close
|
264
280
|
|
@@ -267,7 +283,7 @@ module Javlibrary
|
|
267
283
|
end
|
268
284
|
end
|
269
285
|
|
270
|
-
def
|
286
|
+
def download_all_video_labels
|
271
287
|
thread_pool =[]
|
272
288
|
'A'.upto('Z').each do |alphabet|
|
273
289
|
thread_temp = Thread.new{
|
@@ -278,10 +294,10 @@ module Javlibrary
|
|
278
294
|
thread_pool.map(&:join)
|
279
295
|
end
|
280
296
|
|
281
|
-
module_function :client
|
282
|
-
module_function :
|
283
|
-
module_function :actor_hash, :genre_hash
|
284
|
-
module_function :genres_insert
|
285
|
-
module_function :get_all_actor
|
286
|
-
module_function :
|
297
|
+
# module_function :client
|
298
|
+
# module_function :download_all_videos
|
299
|
+
# module_function :actor_hash, :genre_hash
|
300
|
+
# module_function :genres_insert(download_all_genres)
|
301
|
+
# module_function :get_all_actor(download_all_actors)
|
302
|
+
# module_function :download_all_video_labels
|
287
303
|
end
|
data/lib/javlibrary/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: javlibrary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuanhao Sun
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|