forked from TheGreat00Q/JAV-Scraper-and-Rename-local-files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuren.py
603 lines (575 loc) · 31 KB
/
suren.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
# -*- coding:utf-8 -*-
import requests, re, os, shutil, configparser, time, hashlib, json, traceback
from PIL import Image
from time import sleep
from tkinter import filedialog, Tk
from shutil import copyfile
# 功能为记录错误txt
def write_fail(fail_m):
record_txt = open('【记得清理它】失败记录.txt', 'a', encoding="utf-8")
record_txt.write(fail_m)
record_txt.close()
# get_directory功能为获取用户选取的文件夹路径
def get_directory():
directory_root = Tk()
directory_root.withdraw()
work_path = filedialog.askdirectory()
if work_path == '':
print('你没有选择目录! 请重新选:')
sleep(2)
return get_directory()
else:
# askdirectory 获得是 正斜杠 路径C:/,所以下面要把 / 换成 反斜杠\
temp_path = work_path.replace('/', '\\')
return temp_path
# 调用百度翻译API接口,返回中文简介str
def tran(api_id, key, word, to_lang):
# init salt and final_sign
salt = str(time.time())[:10]
final_sign = api_id + word + salt + key
final_sign = hashlib.md5(final_sign.encode("utf-8")).hexdigest()
# 表单paramas
paramas = {
'q': word,
'from': 'jp',
'to': to_lang,
'appid': '%s' % api_id,
'salt': '%s' % salt,
'sign': '%s' % final_sign
}
response = requests.get('http://api.fanyi.baidu.com/api/trans/vip/translate', params=paramas, timeout=10).content
content = str(response, encoding="utf-8")
json_reads = json.loads(content)
try:
return json_reads['trans_result'][0]['dst']
except:
print(' >正在尝试重新日译中...')
return tran(api_id, key, word, to_lang)
# 获取网页源码,返回网页text;假装python的“重载”函数
def get_jav_html(url_list):
if len(url_list) == 2:
return requests.post(url_list[0], data=url_list[1], headers=headers, timeout=10).text
else:
return requests.post(url_list[0], data=url_list[1], proxies=url_list[2], headers=headers, timeout=10).text
# 下载图片,无返回
def download_pic(cov_list):
# 0错误次数 1图片url 2图片路径 3proxies
if cov_list[0] < 3:
try:
if len(cov_list) == 3:
r = requests.get(cov_list[1], stream=True, timeout=10)
with open(cov_list[2], 'wb') as pic:
for chunk in r:
pic.write(chunk)
else:
r = requests.get(cov_list[1], proxies=cov_list[3], stream=True, timeout=10)
with open(cov_list[2], 'wb') as pic:
for chunk in r:
pic.write(chunk)
except:
print(' >下载失败,重新下载...')
cov_list[0] += 1
download_pic(cov_list)
try:
Image.open(cov_list[2])
except OSError:
print(' >下载失败,重新下载....')
cov_list[0] += 1
download_pic(cov_list)
else:
raise Exception(' >下载多次,仍然失败')
# 每一部jav的“结构体”
class JavFile(object):
def __init__(self):
self.name = 'ABC-123.mp4' # 文件名
self.car = 'ABC-123' # 车牌
self.episodes = 0 # 第几集
# 读取配置文件
print('1、请开启代理,建议美国节点,访问“https://www.jav321.com/”\n'
'2、影片信息没有导演,没有演员头像,可能没有演员姓名\n'
'3、如有素人车牌识别不出,请在ini中添加该车牌\n')
config_settings = configparser.ConfigParser()
print('正在读取ini中的设置...', end='')
try:
config_settings.read('ini的设置会影响所有exe的操作结果.ini', encoding='utf-8-sig')
if_nfo = config_settings.get("收集nfo", "是否收集nfo?")
if_exnfo = config_settings.get("收集nfo", "是否跳过已存在nfo的文件夹?")
custom_title = config_settings.get("收集nfo", "nfo中title的格式")
custom_subtitle = config_settings.get("收集nfo", "是否中字的表现形式")
if_jpg = config_settings.get("下载封面", "是否下载封面海报?")
custom_fanart = config_settings.get("下载封面", "DVD封面的格式")
custom_poster = config_settings.get("下载封面", "海报的格式")
if_mp4 = config_settings.get("重命名影片", "是否重命名影片?")
rename_mp4 = config_settings.get("重命名影片", "重命名影片的格式")
if_folder = config_settings.get("修改文件夹", "是否重命名或创建独立文件夹?")
rename_folder = config_settings.get("修改文件夹", "新文件夹的格式")
if_classify = config_settings.get("归类影片", "是否归类影片?")
classify_root = config_settings.get("归类影片", "归类的根目录")
classify_basis = config_settings.get("归类影片", "归类的标准")
if_proxy = config_settings.get("代理", "是否使用代理?")
proxy = config_settings.get("代理", "代理IP及端口")
if_tran = config_settings.get("百度翻译API", "是否翻译为中文?")
ID = config_settings.get("百度翻译API", "APP ID")
SK = config_settings.get("百度翻译API", "密钥")
simp_trad = config_settings.get("其他设置", "简繁中文?")
suren_pref = config_settings.get("其他设置", "素人车牌(若有新车牌请自行添加)")
file_type = config_settings.get("其他设置", "扫描文件类型")
title_len = int(config_settings.get("其他设置", "重命名中的标题长度(50~150)"))
except:
print(traceback.format_exc())
print('\n无法读取ini文件,请修改它为正确格式,或者打开“【ini】重新创建ini.exe”创建全新的ini!')
os.system('pause')
print('\n读取ini文件成功! ')
if simp_trad == '简': # https://tw.jav321.com/video/ssni00643
url = 'https://www.jav321.com/search'
t_lang = 'zh' # 百度翻译,日译简中
else:
url = 'https://tw.jav321.com/search'
t_lang = 'cht'
# 确认:代理哪些站点
proxies = {"http": "http://" + proxy, "https": "https://" + proxy}
if if_proxy == '是' and proxy != '': # 是否需要代理,设置requests请求时的状态
jav_list = [url, {}, proxies] # 代理javbus
cover_list = [0, '', '', proxies] # 代理javbus上的图片 0错误次数 1图片url 2图片路径 3proxies
else:
jav_list = [url, {}]
cover_list = [0, '', '']
# 初始化其他
nfo_dict = {'空格': ' ', '车牌': 'ABC-123', '标题': '未知标题', '完整标题': '完整标题',
'发行年月日': '1970-01-01', '发行年份': '1970', '月': '01', '日': '01',
'片商': '未知片商', '评分': '0', '首个女优': '未知演员', '全部女优': '未知演员',
'片长': '0', '\\': '\\', '是否中字': '中字-', '视频': 'ABC-123'} # 用于暂时存放影片信息,女优,标题等
suren_list = suren_pref.split('、')
rename_mp4_list = rename_mp4.split('+') #重命名格式的列表,来自ini文件的rename_mp4
rename_folder_list = rename_folder.split('+') #重命名格式的列表,来自ini文件的rename_floder
type_tuple = tuple(file_type.split('、')) #重命名格式的列表,来自ini文件的rename_mp4
classify_basis_list = classify_basis.split('\\') # 归类标准,来自ini文件的file_type
title_list = custom_title.replace('标题', '完整标题', 1).split('+') # 归类标准,来自ini文件的custom_title
fanart_list = custom_fanart.split('+') # 归类标准,来自ini文件的custom_title
poster_list = custom_poster.split('+') # 归类标准,来自ini文件的custom_title
for j in rename_mp4_list and rename_folder_list:
if j not in nfo_dict:
nfo_dict[j] = j
for j in rename_folder_list:
if j not in nfo_dict:
nfo_dict[j] = j
classify_list = []
for i in classify_basis_list:
for j in i.split('+'):
if j not in nfo_dict:
nfo_dict[j] = j
classify_list.append(j)
classify_list.append('\\')
for j in title_list:
if j not in nfo_dict:
nfo_dict[j] = j
for j in fanart_list:
if j not in nfo_dict:
nfo_dict[j] = j
for j in poster_list:
if j not in nfo_dict:
nfo_dict[j] = j
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'} # 伪装成浏览器浏览网页
start_key = ''
while start_key == '':
# 用户选择文件夹
print('请选择要整理的文件夹:', end='')
path = get_directory()
print(path)
write_fail('已选择文件夹:' + path + '\n')
print('...文件扫描开始...如果时间过长...请避开中午夜晚高峰期...\n')
#
if if_classify == '是':
classify_root = classify_root.rstrip('\\')
if classify_root != '所选文件夹':
if classify_root != path: # 归类根目录和所选不一样,继续核实归类根目录和所选不一样的合法性
if classify_root[:2] != path[:2]:
print('归类的根目录“', classify_root, '”和所选文件夹不在同一磁盘无法归类!请修正!')
os.system('pause')
if not os.path.exists(classify_root):
print('归类的根目录“', classify_root, '”不存在!无法归类!请修正!')
os.system('pause')
else: # 一样
classify_root = path + '\\归类完成'
else:
classify_root = path + '\\归类完成'
#
fail_times = 0 # 处理过程中错失败的个数
fail_list = [] # 用于存放处理失败的信息
# 【当前路径】 【子目录】 【文件】
for root, dirs, files in os.walk(path):
if if_classify == '是' and root.startswith(classify_root):
# print('>>该文件夹在归类的根目录中,跳过处理...', root)
continue
if if_exnfo == '是' and files and (files[-1].endswith('nfo') or (len(files) > 1 and files[-2].endswith('nfo'))):
continue
# 对这一层文件夹进行评估,有多少视频,有多少同车牌视频,是不是独立文件夹
car_videos = [] # 存放:需要整理的jav的结构体
cars_dic = {}
videos_num = 0 # 当前文件夹中视频的数量,可能有视频不是jav
subtitles = False # 有没有字幕
nfo_dict['是否中字'] = ''
for raw_file in files:
# 判断文件是不是字幕文件
if raw_file.endswith(('.srt', '.vtt', '.ass',)):
subtitles = True
continue
# 判断是不是视频,得到车牌号
if raw_file.endswith(type_tuple) and not raw_file.startswith('.'):
video_num_g = re.search(r'([a-zA-Z]{2,6})-? ?(\d{2,5})', raw_file)
if str(video_num_g) != 'None':
num_pref = video_num_g.group(1)
num_pref = num_pref.upper()
if num_pref in suren_list:
num_suf = video_num_g.group(2)
car_num = num_pref + '-' + num_suf
if car_num not in cars_dic:
cars_dic[car_num] = 1
else:
cars_dic[car_num] += 1
jav_file = JavFile()
jav_file.car = car_num
jav_file.name = raw_file
jav_file.episodes = cars_dic[car_num]
car_videos.append(jav_file)
else:
continue
else:
continue
else:
continue
if cars_dic:
if len(cars_dic) > 1 or videos_num > len(car_videos) or len(dirs) > 1 or (
len(dirs) == 1 and dirs[0] != '.actors'):
# 当前文件夹下, 车牌不止一个,还有其他非jav视频,有其他文件夹
separate_folder = False
else:
separate_folder = True
else:
continue
# 正式开始
for srt in car_videos:
car_num = srt.car
file = srt.name
video_type = '.' + file.split('.')[-1] # 文件类型,如:.mp4
relative_path = '\\' + root.lstrip(path) + '\\' + file # 影片的相对于所选文件夹的路径,用于报错
try:
# 获取nfo信息的jav321搜索网页
jav_list[1] = {'sn': car_num}
try:
jav_html = get_jav_html(jav_list)
except:
print('>>尝试打开jav321搜索页面失败,正在尝试第二次打开...')
try:
jav_html = get_jav_html(jav_list)
print(' >第二次尝试成功!')
except:
fail_times += 1
fail_message = '第' + str(fail_times) + '个失败!连接jav321失败,' + relative_path + '\n'
print('>>' + fail_message, end='')
fail_list.append(' >' + fail_message)
write_fail(' >' + fail_message)
continue
# 尝试找标题
titleg = re.search(r'<h3>(.+?) <small>', jav_html) # 匹配处理“标题”
# 搜索结果就是AV的页面
if str(titleg) != 'None':
only_title = titleg.group(1)
# print(only_title)
# 找不到标题,jav321找不到影片
else:
fail_times += 1
fail_message = '第' + str(fail_times) + '个失败!找不到该车牌的影片:' + relative_path + '\n'
print('>>' + fail_message, end='')
fail_list.append(' >' + fail_message)
write_fail(' >' + fail_message)
continue
# 正则匹配 影片信息 开始
# 车牌号
nfo_dict['车牌'] = re.search(r'番.</b>: (.+?)<br>', jav_html).group(1).upper()
nfo_dict['车牌前缀'] = nfo_dict['车牌'].split('-')[0]
# 去除title中的特殊字符
only_title = only_title.replace('\n', '').replace('&', '和').replace('\\', '#') \
.replace('/', '#').replace(':', ':').replace('*', '#').replace('?', '?') \
.replace('"', '#').replace('<', '【').replace('>', '】') \
.replace('|', '#').replace('<', '【').replace('>', '】') \
.replace('〈', '【').replace('〉', '】').replace('.', '。').replace('&', '和')
# 素人的title开头不是车牌
title = nfo_dict['车牌'] + ' ' + only_title
print('>>正在处理:', title)
# 处理标题过长
nfo_dict['完整标题'] = only_title
if len(only_title) > title_len:
nfo_dict['标题'] = only_title[:title_len]
else:
nfo_dict['标题'] = only_title
# 片商</b>: <a href="/company/%E83%A0%28PRESTIGE+PREMIUM%29/1">プレステージプレミアム(PRESTIGE PREMIUM)</a>
studiog = re.search(r'<a href="/company.+?">(.+?)</a>', jav_html)
if str(studiog) != 'None':
nfo_dict['片商'] = studiog.group(1)
else:
nfo_dict['片商'] = '未知片商'
# 上映日 (\d\d\d\d-\d\d-\d\d)</td>
premieredg = re.search(r'日期</b>: (\d\d\d\d-\d\d-\d\d)<br>', jav_html)
if str(premieredg) != 'None':
nfo_dict['发行年月日'] = premieredg.group(1)
nfo_dict['发行年份'] = nfo_dict['发行年月日'][0:4]
nfo_dict['月'] = nfo_dict['发行年月日'][5:7]
nfo_dict['日'] = nfo_dict['发行年月日'][8:10]
else:
nfo_dict['发行年月日'] = '1970-01-01'
nfo_dict['发行年份'] = '1970'
nfo_dict['月'] = '01'
nfo_dict['日'] = '01'
# 片长 <td><span class="text">150</span> 分钟</td>
runtimeg = re.search(r'播放..</b>: (\d+)', jav_html)
if str(runtimeg) != 'None':
nfo_dict['片长'] = runtimeg.group(1)
else:
nfo_dict['片长'] = '0'
# 没有导演
# 演员们 和 # 第一个演员 女优</b>: 花音さん 21歳 床屋さん(家族経営)  
actorg = re.search(r'<small>(.+?)</small>', jav_html)
if str(actorg) != 'None':
actor_str = actorg.group(1)
actor_list = actor_str.replace('/', ' ').split(' ') # <small>luxu-071 松波優 29歳 システムエンジニア</small>
actor_list = [i for i in actor_list if i != '']
if len(actor_list) > 3:
nfo_dict['首个女优'] = actor_list[1] + ' ' + actor_list[2] + ' ' + actor_list[3]
elif len(actor_list) > 1:
del actor_list[0]
nfo_dict['首个女优'] = ' '.join(actor_list)
else:
nfo_dict['首个女优'] = '素人'
nfo_dict['全部女优'] = nfo_dict['首个女优']
else:
nfo_dict['首个女优'] = nfo_dict['全部女优'] = '素人'
# print(nfo_dict['全部女优'])
# 特点
genres = re.findall(r'genre.+?">(.+?)</a>', jav_html)
genres = [i for i in genres if i != '标签' and i != '標籤']
genres.append('片商:' + nfo_dict['片商'])
if '-c.' in file or '-C.' in file or subtitles:
genres.append('中文字幕')
nfo_dict['是否中字'] = custom_subtitle
# 下载封面 cover fanart
coverg = re.search(r'poster="(.+?)"><source', jav_html) # 封面图片的正则对象
if str(coverg) != 'None':
cover_url = coverg.group(1)
else: # src="http://pics.dmm.co.jp/digital/amateur/scute530/scute530jp-001.jpg"
coverg = re.search(r'img-responsive" src="(.+?)"', jav_html) # 封面图片的正则对象
if str(coverg) != 'None':
cover_url = coverg.group(1)
else: # src="http://pics.dmm.co.jp/digital/amateur/scute530/scute530jp-001.jpg"
coverg = re.search(r'src="(.+?)"', jav_html) # 封面图片的正则对象
if str(coverg) != 'None':
cover_url = coverg.group(1)
else:
cover_url = ''
# 下载海报 poster
posterg = re.search(r'img-responsive" src="(.+?)"', jav_html) # 封面图片的正则对象
if str(posterg) != 'None':
poster_url = posterg.group(1)
else:
poster_url = ''
# 评分
scoreg = re.search(r'评分</b>: (\d\.\d)<br>', jav_html)
if str(scoreg) != 'None':
score = float(scoreg.group(1))
score = (score - 2) * 10 / 3
if score >= 0:
score = '%.1f' % score
nfo_dict['评分'] = str(score)
else:
nfo_dict['评分'] = '0'
else:
scoreg = re.search(r'"/img/(\d\d)\.gif', jav_html)
if str(scoreg) != 'None':
score = float(scoreg.group(1))/10
score = (score - 2) * 10 / 3
if score >= 0:
score = '%.1f' % score
nfo_dict['评分'] = str(score)
else:
nfo_dict['评分'] = '0'
else:
nfo_dict['评分'] = '0'
criticrating = str(float(nfo_dict['评分'])*10)
# 素人上没有企划set
# 把标题当做plot
plot = only_title
if if_nfo == '是' and if_tran == '是':
print(' >正在日译中...')
plot = tran(ID, SK, title, t_lang)
# 1重命名视频
new_mp4 = file[:-len(video_type)].rstrip(' ')
if if_mp4 == '是':
# 新文件名new_mp4
new_mp4 = ''
# print(nfo_dict['完整标题'])
for j in rename_mp4_list:
new_mp4 += nfo_dict[j]
new_mp4 = new_mp4.rstrip(' ')
cd_msg = ''
if cars_dic[car_num] > 1: # 是CD1还是CDn?
cd_msg = '-cd' + str(srt.episodes)
new_mp4 += cd_msg
# rename 文件名
os.rename(root + '\\' + file, root + '\\' + new_mp4 + video_type)
file = new_mp4 + video_type
print(' >修改文件名' + cd_msg + '完成')
# 2重命名文件夹
new_root = root
new_folder = root.split('\\')[-1] # 当前影片的新目录名称
if if_folder == '是':
# 新文件夹名rename_folder
new_folder = ''
for j in rename_folder_list:
new_folder += (nfo_dict[j])
new_folder = new_folder.rstrip(' ')
if separate_folder:
if cars_dic[car_num] == 1 or (
cars_dic[car_num] > 1 and cars_dic[car_num] == srt.episodes): # 同一车牌有多部,且这是最后一部,才会重命名
newroot_list = root.split('\\')
del newroot_list[-1]
upper2_root = '\\'.join(newroot_list)
new_root = upper2_root + '\\' + new_folder # 当前文件夹就会被重命名
# 修改文件夹
os.rename(root, new_root)
print(' >重命名文件夹完成')
else:
if not os.path.exists(root + '\\' + new_folder): # 已经存在目标文件夹
os.makedirs(root + '\\' + new_folder)
# 创建独立的文件夹完成
os.rename(root + '\\' + file, root + '\\' + new_folder + '\\' + file) # 就把影片放进去
new_root = root + '\\' + new_folder # 在当前文件夹下再创建新文件夹
print(' >创建独立的文件夹完成')
# 更新一下relative_path
relative_path = '\\' + new_root.lstrip(path) + '\\' + file # 影片的相对于所选文件夹的路径,用于报错
# 3写入nfo
if if_nfo:
cus_title = ''
for i in title_list:
cus_title += nfo_dict[i]
# 写入nfo开始
info_path = new_root + '\\' + new_mp4 + '.nfo'
# 开始写入nfo
f = open(info_path, 'w', encoding="utf-8")
f.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n"
"<movie>\n"
" <plot>" + plot + "</plot>\n"
" <title>" + cus_title + "</title>\n"
" <rating>" + nfo_dict['评分'] + "</rating>\n"
" <criticrating>" + criticrating + "</criticrating>\n"
" <year>" + nfo_dict['发行年份'] + "</year>\n"
" <mpaa>NC-17</mpaa>\n"
" <customrating>NC-17</customrating>\n"
" <countrycode>JP</countrycode>\n"
" <premiered>" + nfo_dict['发行年月日'] + "</premiered>\n"
" <release>" + nfo_dict['发行年月日'] + "</release>\n"
" <runtime>" + nfo_dict['片长'] + "</runtime>\n"
" <country>日本</country>\n"
" <studio>" + nfo_dict['片商'] + "</studio>\n"
" <id>" + nfo_dict['车牌'] + "</id>\n"
" <num>" + nfo_dict['车牌'] + "</num>\n")
for i in genres:
f.write(" <genre>" + i + "</genre>\n")
for i in genres:
f.write(" <tag>" + i + "</tag>\n")
f.write(" <actor>\n <name>" + nfo_dict['首个女优'] + "</name>\n <type>Actor</type>\n </actor>\n")
f.write("</movie>\n")
f.close()
print(" >nfo收集完成")
# nfo_dict['视频']用于图片的命名
nfo_dict['视频'] = new_mp4
# 4需要两张图片
if if_jpg == '是':
# fanart和poster路径
fanart_path = new_root + '\\'
poster_path = new_root + '\\'
for i in fanart_list:
fanart_path += nfo_dict[i]
for i in poster_list:
poster_path += nfo_dict[i]
# 下载海报的地址 cover
print(' >fanart.jpg的链接:', cover_url)
# 下载 海报
cover_list[0] = 0
cover_list[1] = cover_url
cover_list[2] = fanart_path
try:
download_pic(cover_list)
print(' >fanart.jpg下载成功')
except:
fail_times += 1
fail_message = ' >第' + str(
fail_times) + '个失败!fanart下载失败:' + cover_url + ',网络不佳,下载失败:' + relative_path + '\n'
print(fail_message, end='')
fail_list.append(fail_message)
write_fail(fail_message)
continue
# 下载poster.jpg img-responsive" src="https://www.jav321.com/images/prestigepremium/300mium/034/pf_o1_300mium-034.jpg">
print(' >poster.jpg的链接:', poster_url)
cover_list[0] = 0
cover_list[1] = poster_url
cover_list[2] = poster_path
try:
download_pic(cover_list)
print(' >poster.jpg下载成功')
except:
fail_times += 1
fail_message = ' >第' + str(
fail_times) + '个失败!poster下载失败:' + relative_path + '\n'
print(fail_message, end='')
fail_list.append(fail_message)
write_fail(fail_message)
continue
# 5收集女优头像
# 6移动文件夹
if if_classify == '是' and (
cars_dic[car_num] == 1 or (cars_dic[car_num] > 1 and cars_dic[car_num] == srt.episodes)):
# 需要移动文件夹,且,是该影片的最后一集
if separate_folder and classify_root.startswith(root):
print(' >无法归类,请选择该文件夹的上级目录作它的归类根目录', root.lstrip(path))
continue
class_root = classify_root + '\\'
# 对归类标准再细化
for j in classify_list:
class_root += nfo_dict[j] # C:\\Users\\JuneRain\\Desktop\\测试文件夹\\1\\葵司\\
new_new_root = class_root + new_folder # 移动的目标文件夹 C:\\Users\\JuneRain\\Desktop\\测试文件夹\\1\\葵司\\【葵司】AVOP-127
if not os.path.exists(new_new_root): # 不存在目标目录
os.makedirs(new_new_root)
jav_files = os.listdir(new_root)
for i in jav_files:
os.rename(new_root + '\\' + i, new_new_root + '\\' + i)
os.rmdir(new_root)
print(' >归类文件夹完成')
else:
fail_times += 1
fail_message = ' >第' + str(fail_times) + '个失败!归类失败,重复的影片,归类的根目录已存在相同文件夹:' + new_new_root + '\n'
print(fail_message, end='')
fail_list.append(fail_message)
write_fail(fail_message)
if not os.path.exists(path + '\\归类失败'): # 还不存在失败文件夹,先创建一个
os.makedirs(path + '\\归类失败')
shutil.move(new_root, path + '\\归类失败\\' + new_root.split('\\')[-1])
continue
except:
fail_times += 1
fail_message = ' >第' + str(fail_times) + '个失败!发生错误,如一直在该影片报错请截图并联系作者:' + relative_path + '\n'\
+ traceback.format_exc() + '\n'
print(fail_message, end='')
fail_list.append(fail_message)
write_fail(fail_message)
continue
print('\n当前文件夹完成,', end='')
if fail_times > 0:
print('失败', fail_times, '个! ', path, '\n')
if len(fail_list) > 0:
for fail in fail_list:
print(fail, end='')
print('\n“【记得清理它】失败记录.txt”已记录错误\n')
else:
print('没有处理失败的AV,干得漂亮! ', path, '\n')
start_key = input('回车继续选择文件夹整理:')