forked from moyy996/AVDC
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjavdb.py
executable file
·202 lines (168 loc) · 9.17 KB
/
javdb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import re
from lxml import etree
import json
from ADC_function import *
def getTitle(htmlcode):
try:
html = etree.fromstring(htmlcode, etree.HTMLParser())
result = str(html.xpath('/html/body/section/div/h2/strong/text()')).strip(" ['']")
return re.sub('.*\] ', '', result.replace('/', ',').replace('\\xa0', '').replace(' : ', ''))
except:
return re.sub('.*\] ', '', result.replace('/', ',').replace('\\xa0', ''))
def getActor(htmlcode): # //*[@id="center_column"]/div[2]/div[1]/div/table/tbody/tr[1]/td/text()
html = etree.fromstring(htmlcode, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
result1 = html.xpath('//strong[contains(text(),"演員")]/../following-sibling::span/text()')
result2 = html.xpath('//strong[contains(text(),"演員")]/../following-sibling::span/a/text()')
return result1 + result2
def getActorPhoto(actor): # //*[@id="star_qdt"]/li/a/img
d = {}
for i in actor:
if ',' not in i or ')' in i:
p = {i: ''}
d.update(p)
return d
def getStudio(htmlcode):
html = etree.fromstring(htmlcode, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
result1 = str(html.xpath('//strong[contains(text(),"片商")]/../following-sibling::span/text()')).strip(" ['']")
result2 = str(html.xpath('//strong[contains(text(),"片商")]/../following-sibling::span/a/text()')).strip(" ['']")
return str(result1 + result2).strip('+').replace("', '", '').replace('"', '')
def getPublisher(htmlcode):
html = etree.fromstring(htmlcode, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
result1 = str(html.xpath('//strong[contains(text(),"發行")]/../following-sibling::span/text()')).strip(" ['']")
result2 = str(html.xpath('//strong[contains(text(),"發行")]/../following-sibling::span/a/text()')).strip(" ['']")
return str(result1 + result2).strip('+').replace("', '", '').replace('"', '')
def getRuntime(htmlcode):
html = etree.fromstring(htmlcode, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
result1 = str(html.xpath('//strong[contains(text(),"時長")]/../following-sibling::span/text()')).strip(" ['']")
result2 = str(html.xpath('//strong[contains(text(),"時長")]/../following-sibling::span/a/text()')).strip(" ['']")
return str(result1 + result2).strip('+').rstrip('mi')
def getSeries(htmlcode):
html = etree.fromstring(htmlcode, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
result1 = str(html.xpath('//strong[contains(text(),"系列")]/../following-sibling::span/text()')).strip(" ['']")
result2 = str(html.xpath('//strong[contains(text(),"系列")]/../following-sibling::span/a/text()')).strip(" ['']")
return str(result1 + result2).strip('+').replace("', '", '').replace('"', '')
def getNum(htmlcode):
html = etree.fromstring(htmlcode, etree.HTMLParser())
result1 = str(html.xpath('//strong[contains(text(),"番號")]/../following-sibling::span/text()')).strip(
" ['']").replace('_', '-')
result2 = str(html.xpath('//strong[contains(text(),"番號")]/../following-sibling::span/a/text()')).strip(
" ['']").replace('_', '-')
return str(result2 + result1).strip('+')
def getYear(getRelease):
try:
result = str(re.search('\d{4}', getRelease).group())
return result
except:
return getRelease
def getRelease(htmlcode):
html = etree.fromstring(htmlcode, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
result1 = str(html.xpath('//strong[contains(text(),"時間")]/../following-sibling::span/text()')).strip(" ['']")
result2 = str(html.xpath('//strong[contains(text(),"時間")]/../following-sibling::span/a/text()')).strip(" ['']")
return str(result1 + result2).strip('+')
def getTag(htmlcode):
html = etree.fromstring(htmlcode, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
result1 = str(html.xpath('//strong[contains(text(),"类别")]/../following-sibling::span/text()')).strip(" ['']")
result2 = str(html.xpath('//strong[contains(text(),"类别")]/../following-sibling::span/a/text()')).strip(" ['']")
return str(result1 + result2).strip('+').replace(",\\xa0", "").replace("'", "").replace(' ', '').replace(',,',
'').lstrip(
',')
def getCover_small(htmlcode, count):
html = etree.fromstring(htmlcode, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
result = html.xpath("//div[@class='item-image fix-scale-cover']/img/@src")[count]
if not 'https' in result:
result = 'https:' + result
return result
def getCover(htmlcode):
html = etree.fromstring(htmlcode, etree.HTMLParser())
result = str(html.xpath("//div[@class='column column-video-cover']/a/img/@src")).strip(" ['']")
return result
def getDirector(htmlcode):
html = etree.fromstring(htmlcode, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
result1 = str(html.xpath('//strong[contains(text(),"導演")]/../following-sibling::span/text()')).strip(" ['']")
result2 = str(html.xpath('//strong[contains(text(),"導演")]/../following-sibling::span/a/text()')).strip(" ['']")
return str(result1 + result2).strip('+').replace("', '", '').replace('"', '')
def getOutline(htmlcode):
html = etree.fromstring(htmlcode, etree.HTMLParser())
result = str(html.xpath('//*[@id="introduction"]/dd/p[1]/text()')).strip(" ['']")
return result
def main(number):
try:
htmlcode = get_html('https://javdb.com/search?q=' + number + '&f=all').replace(u'\xa0', u' ')
html = etree.fromstring(htmlcode, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
counts = len(html.xpath(
'//div[@id=\'videos\']/div[@class=\'grid columns\']/div[@class=\'grid-item column\']'))
if counts == 0:
dic = {
'title': '',
'actor': '',
'website': '',
}
js = json.dumps(dic, ensure_ascii=False, sort_keys=True, indent=4,
separators=(',', ':'), ) # .encode('UTF-8')
return js
count = 1
number_get = ''
movie_found = 0
result_url = ''
for count in range(1, counts + 1): # 遍历搜索结果,找到需要的番号
number_get = html.xpath(
'//div[@id=\'videos\']/div[@class=\'grid columns\']/div[@class=\'grid-item column\'][' + str(
count) + ']/a[@class=\'box\']/div[@class=\'uid\']/text()')[0]
# number_get = number_get.replace('_', '-')
if number_get == number.upper() or number_get == number.lower():
movie_found = 1
break
result_url = 'https://javdb.com' + html.xpath('//*[@id="videos"]/div/div/a/@href')[count - 1]
b = get_html(result_url).replace(u'\xa0', u' ')
actor = getActor(b)
if len(actor) == 0 and 'FC2-' in number_get:
actor.append('FC2-NoActor')
if movie_found == 1:
dic = {
'actor': str(actor).strip(" [',']").replace('\'', ''),
'title': getTitle(b).replace('中文字幕', '').replace("\\n", '').replace('_', '-').replace(number_get,
'').strip().replace(
' ', '-').replace('--', '-'),
'studio': getStudio(b),
'publisher': getPublisher(b),
'outline': getOutline(b).replace('\n', ''),
'runtime': getRuntime(b).replace(' 分鍾', ''),
'director': getDirector(b),
'release': getRelease(b),
'number': number_get,
'cover': getCover(b),
'cover_small': getCover_small(htmlcode, count - 1),
'imagecut': 3,
'tag': getTag(b),
'series': getSeries(b),
'year': getYear(getRelease(b)), # str(re.search('\d{4}',getRelease(htmlcode)).group()),
'actor_photo': getActorPhoto(actor),
'website': result_url,
'source': 'javdb.py',
}
else: # 未找到番号
dic = {
'title': '',
'actor': str(actor).strip(" [',']").replace('\'', ''),
'website': '',
}
except: # actor 用于判断ip是否被封
if htmlcode == 'ProxyError':
dic = {
'title': '',
'actor': '',
'website': 'timeout',
}
else:
dic = {
'title': '',
'actor': '',
'website': '',
}
js = json.dumps(dic, ensure_ascii=False, sort_keys=True, indent=4, separators=(',', ':'), ) # .encode('UTF-8')
return js
# print(main('LUXU-1217'))
# input("[+][+]Press enter key exit, you can check the error messge before you exit.\n[+][+]按回车键结束,你可以在结束之前查看和错误信息。")
# print(main('abs-141'))
# print(main('HYSD-00083'))
# print(main('n1403'))