Merge branch 'master' into patch-6

This commit is contained in:
Feng4
2020-12-29 17:35:49 +08:00
committed by GitHub
15 changed files with 520 additions and 104 deletions

View File

@@ -1,6 +1,6 @@
import requests
from lxml import etree
import re
import config
SUPPORT_PROXY_TYPE = ("http", "socks5", "socks5h")
@@ -463,3 +463,14 @@ def translate(src:str,target_language:str="zh_cn"):
translate_list = [i["trans"] for i in result.json()["sentences"]]
return "".join(translate_list)
# ========================================================================是否为无码
def is_uncensored(number):
if re.match('^\d{4,}', number) or re.match('n\d{4}', number) or 'HEYZO' in number.upper():
return True
configs = config.Config().get_uncensored()
prefix_list = str(configs).split(',')
for pre in prefix_list:
if pre.upper() in number.upper():
return True
return False

BIN
Img/LEAK.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
Img/SUB.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
Img/UNCENSORED.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -110,56 +110,65 @@ def getTag(htmlcode): # 获取标签
tag.append(i.get_text())
return tag
def getExtrafanart(htmlcode): # 获取剧照
html_pather = re.compile(r'<div class=\"mobileImgThumbnail\">[\s\S]*?</div></div></div></div>')
html = html_pather.search(htmlcode)
if html:
html = html.group()
extrafanart_pather = re.compile(r'<img.*?src=\"(.*?)\"')
extrafanart_imgs = extrafanart_pather.findall(html)
if extrafanart_imgs:
return extrafanart_imgs
return ''
def main(number):
try:
try:
try:
htmlcode = get_html('https://cn.airav.wiki/video/' + number)
javbus_htmlcode = get_html('https://www.javbus.com/ja/' + number)
htmlcode = get_html('https://cn.airav.wiki/video/' + number)
javbus_htmlcode = get_html('https://www.javbus.com/ja/' + number)
except:
print(number)
dic = {
# 标题可使用airav
'title': str(re.sub('\w+-\d+-', '', getTitle(htmlcode))),
# 制作商选择使用javbus
'studio': getStudio(javbus_htmlcode),
# 年份也是用javbus
'year': str(re.search('\d{4}', getYear(javbus_htmlcode)).group()),
# 简介 使用 airav
'outline': getOutline(htmlcode),
# 使用javbus
'runtime': getRuntime(javbus_htmlcode),
# 导演 使用javbus
'director': getDirector(javbus_htmlcode),
# 作者 使用airav
'actor': getActor(htmlcode),
# 发售日使用javbus
'release': getRelease(javbus_htmlcode),
# 番号使用javbus
'number': getNum(javbus_htmlcode),
# 封面链接 使用javbus
'cover': getCover(javbus_htmlcode),
'imagecut': 1,
# 使用 airav
'tag': getTag(htmlcode),
# 使用javbus
'label': getSerise(javbus_htmlcode),
# 妈的airav不提供作者图片
'actor_photo': getActorPhoto(javbus_htmlcode),
'website': 'https://www.airav.wiki/video/' + number,
'source': 'airav.py',
# 使用javbus
'series': getSerise(javbus_htmlcode),
}
js = json.dumps(dic, ensure_ascii=False, sort_keys=True, indent=4,separators=(',', ':'), ) # .encode('UTF-8')
return js
except:
return main_uncensored(number)
print(number)
dic = {
# 标题可使用airav
'title': str(re.sub('\w+-\d+-', '', getTitle(htmlcode))),
# 制作商选择使用javbus
'studio': getStudio(javbus_htmlcode),
# 年份也是用javbus
'year': str(re.search('\d{4}', getYear(javbus_htmlcode)).group()),
# 简介 使用 airav
'outline': getOutline(htmlcode),
# 使用javbus
'runtime': getRuntime(javbus_htmlcode),
# 导演 使用javbus
'director': getDirector(javbus_htmlcode),
# 作者 使用airav
'actor': getActor(htmlcode),
# 发售日使用javbus
'release': getRelease(javbus_htmlcode),
# 番号使用javbus
'number': getNum(javbus_htmlcode),
# 封面链接 使用javbus
'cover': getCover(javbus_htmlcode),
# 剧照获取
'extrafanart': getExtrafanart(htmlcode),
'imagecut': 1,
# 使用 airav
'tag': getTag(htmlcode),
# 使用javbus
'label': getSerise(javbus_htmlcode),
# 妈的airav不提供作者图片
'actor_photo': getActorPhoto(javbus_htmlcode),
'website': 'https://www.airav.wiki/video/' + number,
'source': 'airav.py',
# 使用javbus
'series': getSerise(javbus_htmlcode),
}
js = json.dumps(dic, ensure_ascii=False, sort_keys=True, indent=4,separators=(',', ':'), ) # .encode('UTF-8')
return js
except:
data = {
"title": "",
@@ -171,4 +180,5 @@ def main(number):
if __name__ == '__main__':
print(main('sdsi-019'))
print(main('ADN-188'))

View File

@@ -209,6 +209,21 @@ def getSeries(text):
except:
return ""
def getExtrafanart(htmlcode): # 获取剧照
html_pather = re.compile(r'<div id=\"sample-image-block\"[\s\S]*?<br></div></div>')
html = html_pather.search(htmlcode)
if html:
html = html.group()
extrafanart_pather = re.compile(r'<img.*?src=\"(.*?)\"')
extrafanart_imgs = extrafanart_pather.findall(html)
if extrafanart_imgs:
s = []
for img_url in extrafanart_imgs:
img_urls = img_url.rsplit('-', 1)
img_url = img_urls[0] + 'jp-' + img_urls[1]
s.append(img_url)
return s
return ''
def main(number):
# fanza allow letter + number + underscore, normalize the input here
@@ -260,6 +275,7 @@ def main(number):
"cover": getCover(htmlcode, fanza_hinban),
"imagecut": 1,
"tag": getTag(htmlcode),
"extrafanart": getExtrafanart(htmlcode),
"label": getLabel(htmlcode),
"year": getYear(
getRelease(htmlcode)
@@ -309,5 +325,6 @@ def main_htmlcode(number):
if __name__ == "__main__":
print(main("DV-1562"))
print(main("96fad1217"))
# print(main("DV-1562"))
# print(main("96fad1217"))
print(main("pred00251"))

View File

@@ -60,6 +60,29 @@ def getYear_fc2com(release):
except:
return ''
def getExtrafanart(htmlcode): # 获取剧照
html_pather = re.compile(r'<ul class=\"items_article_SampleImagesArea\"[\s\S]*?</ul>')
html = html_pather.search(htmlcode)
if html:
html = html.group()
extrafanart_pather = re.compile(r'<a href=\"(.*?)\"')
extrafanart_imgs = extrafanart_pather.findall(html)
if extrafanart_imgs:
return extrafanart_imgs
return ''
def getTrailer(htmlcode):
video_pather = re.compile(r'\'[a-zA-Z0-9]{32}\'')
video = video_pather.findall(htmlcode)
if video:
video_url = video[0].replace('\'', '')
video_url = 'https://adult.contents.fc2.com/api/v2/videos/1603395/sample?key=' + video_url
url_json = eval(ADC_function.get_html(video_url))['path'].replace('\\', '')
else:
video_url = ''
return url_json
def main(number):
try:
number = number.replace('FC2-', '').replace('fc2-', '')
@@ -70,7 +93,7 @@ def main(number):
dic = {
'title': getTitle_fc2com(htmlcode2),
'studio': getStudio_fc2com(htmlcode2),
'year': str(re.search('\d{4}', getRelease_fc2com(htmlcode2)).group()),
'year': getYear_fc2com(getRelease_fc2com(htmlcode2)),
'outline': '', # getOutline_fc2com(htmlcode2),
'runtime': '',
'director': getStudio_fc2com(htmlcode2),
@@ -79,6 +102,8 @@ def main(number):
'number': 'FC2-' + number,
'label': '',
'cover': getCover_fc2com(htmlcode2),
'extrafanart': getExtrafanart(htmlcode2),
"trailer": getTrailer(htmlcode2),
'imagecut': 0,
'tag': getTag_fc2com(number),
'actor_photo': '',
@@ -87,10 +112,11 @@ def main(number):
'series': '',
}
except Exception as e:
# print(e)
print(e)
dic = {"title": ""}
js = json.dumps(dic, ensure_ascii=False, sort_keys=True, indent=4, separators=(',', ':'), ) # .encode('UTF-8')
return js
if __name__ == '__main__':
print(main('1228742'))
print(main('FC2-1603395'))

View File

@@ -4,15 +4,18 @@ import json
from bs4 import BeautifulSoup
from lxml import html
from ADC_function import post_html
import re
def main(number: str) -> json:
result = post_html(url="https://www.jav321.com/search", query={"sn": number})
soup = BeautifulSoup(result.text, "html.parser")
lx = html.fromstring(str(soup))
if "/video/" in result.url:
data = parse_info(soup)
dic = {
"title": get_title(lx),
"year": get_year(data),
@@ -20,6 +23,8 @@ def main(number: str) -> json:
"director": "",
"cover": get_cover(lx),
"imagecut": 1,
"trailer": get_trailer(result.text),
"extrafanart": get_extrafanart(result.text),
"actor_photo": "",
"website": result.url,
"source": "jav321.py",
@@ -30,7 +35,6 @@ def main(number: str) -> json:
return json.dumps(dic, ensure_ascii=False, sort_keys=True, indent=4, separators=(',', ':'))
def get_title(lx: html.HtmlElement) -> str:
return lx.xpath("/html/body/div[2]/div[1]/div[1]/div[1]/h3/text()")[0].strip()
@@ -79,6 +83,24 @@ def get_anchor_info(h: str) -> str:
def get_text_info(h: str) -> str:
return h.split(": ")[1]
def get_trailer(html) -> str:
videourl_pather = re.compile(r'<source src=\"(.*?)\"')
videourl = videourl_pather.findall(html)
if videourl:
return videourl[0]
else:
return ''
def get_extrafanart(htmlcode): # 获取剧照
html_pather = re.compile(r'<div class=\"col\-md\-3\"><div class=\"col\-xs\-12 col\-md\-12\">[\s\S]*?</script><script async src=\"\/\/adserver\.juicyads\.com/js/jads\.js\">')
html = html_pather.search(htmlcode)
if html:
html = html.group()
extrafanart_pather = re.compile(r'<img.*?src=\"(.*?)\"')
extrafanart_imgs = extrafanart_pather.findall(html)
if extrafanart_imgs:
return extrafanart_imgs
return ''
def get_cover(lx: html.HtmlElement) -> str:
return lx.xpath("/html/body/div[2]/div[2]/div[1]/p/a/img/@src")[0]
@@ -112,6 +134,7 @@ def get_tag(data: hash) -> str:
return ""
def get_studio(data: hash) -> str:
if "片商" in data:
return get_anchor_info(data["片商"])
@@ -155,4 +178,4 @@ def get_series(data: hash) -> str:
if __name__ == "__main__":
print(main("soe-259"))
print(main("jul-404"))

View File

@@ -107,6 +107,17 @@ def getTag(htmlcode): # 获取标签
tag.append(translateTag_to_sc(i.get_text()))
return tag
def getExtrafanart(htmlcode): # 获取剧照
html_pather = re.compile(r'<div id=\"sample-waterfall\">[\s\S]*?</div></a>\s*?</div>')
html = html_pather.search(htmlcode)
if html:
html = html.group()
extrafanart_pather = re.compile(r'<a class=\"sample-box\" href=\"(.*?)\"')
extrafanart_imgs = extrafanart_pather.findall(html)
if extrafanart_imgs:
return extrafanart_imgs
return ''
def main_uncensored(number):
htmlcode = get_html('https://www.javbus.com/ja/' + number)
if getTitle(htmlcode) == '':
@@ -127,6 +138,7 @@ def main_uncensored(number):
'number': getNum(htmlcode),
'cover': getCover(htmlcode),
'tag': getTag(htmlcode),
'extrafanart': getExtrafanart(htmlcode),
'label': getSerise(htmlcode),
'imagecut': 0,
'actor_photo': '',
@@ -162,6 +174,7 @@ def main(number):
'cover': getCover(htmlcode),
'imagecut': 1,
'tag': getTag(htmlcode),
'extrafanart': getExtrafanart(htmlcode),
'label': getSerise(htmlcode),
'actor_photo': getActorPhoto(htmlcode),
'website': 'https://www.javbus.com/' + number,

View File

@@ -18,18 +18,38 @@ def getActor(a): # //*[@id="center_column"]/div[2]/div[1]/div/table/tbody/tr[1]
result1 = str(html.xpath('//strong[contains(text(),"演員")]/../span/text()')).strip(" ['']")
result2 = str(html.xpath('//strong[contains(text(),"演員")]/../span/a/text()')).strip(" ['']")
return str(result1 + result2).strip('+').replace(",\\xa0", "").replace("'", "").replace(' ', '').replace(',,', '').replace('N/A', '').lstrip(',').replace(',', ', ')
def getActorPhoto(actor): #//*[@id="star_qdt"]/li/a/img
a = actor.split(',')
d={}
for i in a:
p={i:''}
d.update(p)
return d
def getaphoto(url):
html_page = get_html(url)
img_prether = re.compile(r'<span class\=\"avatar\" style\=\"background\-image\: url\((.*?)\)')
img_url = img_prether.findall(html_page)
if img_prether:
return img_url[0]
else:
return ''
def getActorPhoto(html): #//*[@id="star_qdt"]/li/a/img
actorall_prether = re.compile(r'<strong>演員\:</strong>\s*?.*?<span class=\"value\">(.*)\s*?</div>')
actorall = actorall_prether.findall(html)
if actorall:
actoralls = actorall[0]
actor_prether = re.compile(r'<a href\=\"(.*?)\">(.*?)</a>')
actor = actor_prether.findall(actoralls)
actor_photo = {}
for i in actor:
actor_photo[i[1]] = getaphoto('https://javdb.com'+i[0])
return actor_photo
else:
return {}
def getStudio(a):
# html = etree.fromstring(a, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
# result1 = str(html.xpath('//strong[contains(text(),"片商")]/../span/text()')).strip(" ['']")
# result2 = str(html.xpath('//strong[contains(text(),"片商")]/../span/a/text()')).strip(" ['']")
# return str(result1 + result2).strip('+').replace("', '", '').replace('"', '')
# html = etree.fromstring(a, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
# result1 = str(html.xpath('//strong[contains(text(),"片商")]/../span/text()')).strip(" ['']")
# result2 = str(html.xpath('//strong[contains(text(),"片商")]/../span/a/text()')).strip(" ['']")
# return str(result1 + result2).strip('+').replace("', '", '').replace('"', '')
patherr = re.compile(r'<strong>片商\:</strong>[\s\S]*?<a href=\".*?>(.*?)</a></span>')
pianshang = patherr.findall(a)
if pianshang:
@@ -37,6 +57,7 @@ def getStudio(a):
else:
result = ""
return result
def getRuntime(a):
html = etree.fromstring(a, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
result1 = str(html.xpath('//strong[contains(text(),"時長")]/../span/text()')).strip(" ['']")
@@ -53,11 +74,11 @@ def getNum(a):
result2 = str(html.xpath('//strong[contains(text(),"番號")]/../span/a/text()')).strip(" ['']")
return str(result2 + result1).strip('+')
def getYear(getRelease):
# try:
# result = str(re.search('\d{4}', getRelease).group())
# return result
# except:
# return getRelease
# try:
# result = str(re.search('\d{4}', getRelease).group())
# return result
# except:
# return getRelease
patherr = re.compile(r'<strong>日期\:</strong>\s*?.*?<span class="value">(.*?)\-.*?</span>')
dates = patherr.findall(getRelease)
if dates:
@@ -65,11 +86,12 @@ def getYear(getRelease):
else:
result = ''
return result
def getRelease(a):
# html = etree.fromstring(a, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
# result1 = str(html.xpath('//strong[contains(text(),"時間")]/../span/text()')).strip(" ['']")
# result2 = str(html.xpath('//strong[contains(text(),"時間")]/../span/a/text()')).strip(" ['']")
# return str(result1 + result2).strip('+')
# html = etree.fromstring(a, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
# result1 = str(html.xpath('//strong[contains(text(),"時間")]/../span/text()')).strip(" ['']")
# result2 = str(html.xpath('//strong[contains(text(),"時間")]/../span/a/text()')).strip(" ['']")
# return str(result1 + result2).strip('+')
patherr = re.compile(r'<strong>日期\:</strong>\s*?.*?<span class="value">(.*?)</span>')
dates = patherr.findall(a)
if dates:
@@ -121,6 +143,30 @@ def getCover_small(a, index=0):
result = 'https:' + result
return result
def getTrailer(htmlcode): # 获取预告片
video_pather = re.compile(r'<video id\=\".*?>\s*?<source src=\"(.*?)\"')
video = video_pather.findall(htmlcode)
if video:
if not 'https:' in video[0]:
video_url = 'https:' + video[0]
else:
video_url = video[0]
else:
video_url = ''
return video_url
def getExtrafanart(htmlcode): # 获取剧照
html_pather = re.compile(r'<div class=\"tile\-images preview\-images\">[\s\S]*?</a>\s+?</div>\s+?</div>')
html = html_pather.search(htmlcode)
if html:
html = html.group()
extrafanart_pather = re.compile(r'<a class="tile-item" href=\"(.*?)\"')
extrafanart_imgs = extrafanart_pather.findall(html)
if extrafanart_imgs:
return extrafanart_imgs
return ''
def getCover(htmlcode):
html = etree.fromstring(htmlcode, etree.HTMLParser())
try:
@@ -145,6 +191,10 @@ def getSeries(a):
return str(result1 + result2).strip('+').replace("', '", '').replace('"', '')
def main(number):
try:
# if re.search(r'[a-zA-Z]+\.\d{2}\.\d{2}\.\d{2}', number).group():
# pass
# else:
# number = number.upper()
number = number.upper()
try:
query_result = get_html('https://javdb.com/search?q=' + number + '&f=all')
@@ -161,7 +211,6 @@ def main(number):
else:
ids =html.xpath('//*[@id="videos"]/div/div/a/div[contains(@class, "uid")]/text()')
correct_url = urls[ids.index(number)]
detail_page = get_html('https://javdb.com' + correct_url)
# no cut image by default
@@ -171,7 +220,6 @@ def main(number):
cover_small = getCover_small(query_result)
else:
cover_small = getCover_small(query_result, index=ids.index(number))
if 'placeholder' in cover_small:
# replace wit normal cover and cut it
imagecut = 1
@@ -194,17 +242,20 @@ def main(number):
'number': number,
'cover': getCover(detail_page),
'cover_small': cover_small,
'trailer': getTrailer(detail_page),
'extrafanart': getExtrafanart(detail_page),
'imagecut': imagecut,
'tag': getTag(detail_page),
'label': getLabel(detail_page),
'year': getYear(getRelease(detail_page)), # str(re.search('\d{4}',getRelease(a)).group()),
'actor_photo': getActorPhoto(getActor(detail_page)),
'year': getYear(detail_page), # str(re.search('\d{4}',getRelease(a)).group()),
'actor_photo': getActorPhoto(detail_page),
'website': 'https://javdb.com' + correct_url,
'source': 'javdb.py',
'series': getSeries(detail_page),
}
except Exception as e:
# print(e)
print(e)
dic = {"title": ""}
js = json.dumps(dic, ensure_ascii=False, sort_keys=True, indent=4, separators=(',', ':'), ) # .encode('UTF-8')
return js
@@ -212,4 +263,6 @@ def main(number):
# main('DV-1562')
# input("[+][+]Press enter key exit, you can check the error messge before you exit.\n[+][+]按回车键结束,你可以在结束之前查看和错误信息。")
if __name__ == "__main__":
print(main('ipx-292'))
# print(main('blacked.20.05.30'))
# print(main('AGAV-042'))
print(main('BANK-022'))

View File

@@ -95,6 +95,18 @@ def getSeries(a):
result2 = str(html.xpath('//th[contains(text(),"シリーズ")]/../td/text()')).strip(" ['']").strip('\\n ').strip(
'\\n')
return str(result1 + result2).strip('+').replace("', '", '').replace('"', '')
def getExtrafanart(htmlcode): # 获取剧照
html_pather = re.compile(r'<dd>\s*?<ul>[\s\S]*?</ul>\s*?</dd>')
html = html_pather.search(htmlcode)
if html:
html = html.group()
extrafanart_pather = re.compile(r'<a class=\"sample_image\" href=\"(.*?)\"')
extrafanart_imgs = extrafanart_pather.findall(html)
if extrafanart_imgs:
return extrafanart_imgs
return ''
def main(number2):
number=number2.upper()
htmlcode=str(get_html('https://www.mgstage.com/product/product_detail/'+str(number)+'/',cookies={'adc':'1'}))
@@ -115,6 +127,7 @@ def main(number2):
'imagecut': 0,
'tag': getTag(a),
'label':getLabel(a),
'extrafanart': getExtrafanart(htmlcode),
'year': getYear(getRelease(a)), # str(re.search('\d{4}',getRelease(a)).group()),
'actor_photo': '',
'website':'https://www.mgstage.com/product/product_detail/'+str(number)+'/',

View File

@@ -154,6 +154,20 @@ def getSeries(htmlcode):
except:
return ''
def getExtrafanart(htmlcode): # 获取剧照
html_pather = re.compile(r'<div id="sample_images".*?>[\s\S]*?</div>')
html = html_pather.search(htmlcode)
if html:
html = html.group()
extrafanart_pather = re.compile(r'<a.*?href=\"(.*?)\"')
extrafanart_imgs = extrafanart_pather.findall(html)
if extrafanart_imgs:
s = []
for urli in extrafanart_imgs:
urli = 'https:' + urli.replace('/scene/small', '')
s.append(urli)
return s
return ''
def main(number):
try:
@@ -174,6 +188,7 @@ def main(number):
'number': getNum(detail_page),
'cover': getCover(detail_page),
'cover_small': '',
'extrafanart': getExtrafanart(detail_page),
'imagecut': 1,
'tag': getTag(detail_page),
'label': getLabel(detail_page),

View File

@@ -36,3 +36,29 @@ switch=0
[transalte]
switch=0
values=title,outline
; 预告片
[trailer]
switch=1
; 用来确定是否是无码
[uncensored]
uncensored_prefix=S2M,BT,LAF,SMD
[media]
; 影片后缀
media_type=.mp4,.avi,.rmvb,.wmv,.mov,.mkv,.flv,.ts,.webm,.MP4,.AVI,.RMVB,.WMV,.MOV,.MKV,.FLV,.TS,.WEBM,iso,ISO
; 字幕后缀
sub_type=.smi,.srt,.idx,.sub,.sup,.psb,.ssa,.ass,.txt,.usf,.xss,.ssf,.rt,.lrc,.sbv,.vtt,.ttml
; 水印
[watermark]
switch=1
water=2
; 左上 0, 右上 1, 右下 2 左下 3
; 剧照
[extrafanart]
switch=1
extrafanart_folder=extrafanart

View File

@@ -45,6 +45,35 @@ class Config:
return self.conf.getboolean("common", "transalte_to_sc")
def is_transalte(self) -> bool:
return self.conf.getboolean("transalte", "switch")
def is_trailer(self) -> bool:
return self.conf.getboolean("trailer", "switch")
def is_watermark(self) -> bool:
return self.conf.getboolean("watermark", "switch")
def is_extrafanart(self) -> bool:
return self.conf.getboolean("extrafanart", "switch")
def watermark_type(self) -> int:
return int(self.conf.get("watermark", "water"))
def get_uncensored(self):
try:
sec = "uncensored"
uncensored_prefix = self.conf.get(sec, "uncensored_prefix")
# uncensored_poster = self.conf.get(sec, "uncensored_poster")
return uncensored_prefix
except ValueError:
self._exit("uncensored")
def get_extrafanart(self):
try:
extrafanart_download = self.conf.get("extrafanart", "extrafanart_folder")
return extrafanart_download
except ValueError:
self._exit("extrafanart_folder")
def transalte_values(self) -> bool:
return self.conf.get("transalte", "values")
def proxy(self) -> [str, int, int, str]:
@@ -58,7 +87,13 @@ class Config:
return switch, proxy, timeout, retry, proxytype
except ValueError:
self._exit("common")
def media_rule(self) -> str:
return self.conf.get('media', 'media_type').replace(',', '|')
def sub_rule(self):
return self.conf.get('media', 'sub_type').split(',')
def naming_rule(self) -> str:
return self.conf.get("Name_Rule", "naming_rule")
@@ -146,6 +181,29 @@ class Config:
conf.add_section(sec8)
conf.set(sec8, "switch", "0")
conf.set(sec8, "values", "title,outline")
sec9 = "trailer"
conf.add_section(sec9)
conf.set(sec9, "switch", "0")
sec10 = "uncensored"
conf.add_section(sec10)
conf.set(sec10, "uncensored_prefix", "S2M,BT,LAF,SMD")
sec11 = "media"
conf.add_section(sec11)
conf.set(sec11, "media_type", ".mp4,.avi,.rmvb,.wmv,.mov,.mkv,.flv,.ts,.webm,.MP4,.AVI,.RMVB,.WMV,.MOV,.MKV,.FLV,.TS,.WEBM,iso,ISO")
conf.set(sec11, "sub_type", ".smi,.srt,.idx,.sub,.sup,.psb,.ssa,.ass,.txt,.usf,.xss,.ssf,.rt,.lrc,.sbv,.vtt,.ttml")
sec12 = "watermark"
conf.add_section(sec12)
conf.set(sec12, "switch", 1)
conf.set(sec12, "water", 2)
sec13 = "extrafanart"
conf.add_section(sec13)
conf.set(sec13, "switch", 1)
conf.set(sec13, "extrafanart_folder", "extrafanart")
return conf

201
core.py
View File

@@ -34,7 +34,7 @@ def moveFailedFolder(filepath, failed_folder):
root_path = str(pathlib.Path(filepath).parent)
file_name = pathlib.Path(filepath).name
destination_path = root_path + '/' + failed_folder + '/'
if config.Config.soft_link():
if config.Config().soft_link():
print('[-]Create symlink to Failed output folder')
os.symlink(filepath, destination_path + '/' + file_name)
else:
@@ -127,7 +127,17 @@ def get_data_from_json(file_number, filepath, conf: config.Config): # 从JSON
cover_small = ''
else:
cover_small = json_data.get('cover_small')
if json_data.get('trailer') == None:
trailer = ''
else:
trailer = json_data.get('trailer')
if json_data.get('extrafanart') == None:
extrafanart = ''
else:
extrafanart = json_data.get('extrafanart')
imagecut = json_data.get('imagecut')
tag = str(json_data.get('tag')).strip("[ ]").replace("'", '').replace(" ", '').split(',') # 字符串转列表 @
actor = str(actor_list).strip("[ ]").replace("'", '').replace(" ", '')
@@ -217,6 +227,23 @@ def get_data_from_json(file_number, filepath, conf: config.Config): # 从JSON
translate_values = conf.transalte_values().split(",")
for translate_value in translate_values:
json_data[translate_value] = translate(json_data[translate_value])
if conf.is_trailer():
if trailer:
json_data['trailer'] = trailer
else:
json_data['trailer'] = ''
else:
json_data['trailer'] = ''
if conf.is_extrafanart():
if extrafanart:
json_data['extrafanart'] = extrafanart
else:
json_data['extrafanart'] = ''
else:
json_data['extrafanart'] = ''
naming_rule=""
for i in conf.naming_rule().split("+"):
if i not in json_data:
@@ -238,10 +265,11 @@ def get_info(json_data): # 返回json里的数据
release = json_data.get('release')
number = json_data.get('number')
cover = json_data.get('cover')
trailer = json_data.get('trailer')
website = json_data.get('website')
series = json_data.get('series')
label = json_data.get('label', "")
return title, studio, year, outline, runtime, director, actor_photo, release, number, cover, website, series, label
return title, studio, year, outline, runtime, director, actor_photo, release, number, cover, trailer, website, series, label
def small_cover_check(path, number, cover_small, c_word, conf: config.Config, filepath, failed_folder):
@@ -250,7 +278,7 @@ def small_cover_check(path, number, cover_small, c_word, conf: config.Config, fi
def create_folder(success_folder, location_rule, json_data, conf: config.Config): # 创建文件夹
title, studio, year, outline, runtime, director, actor_photo, release, number, cover, website, series, label = get_info(json_data)
title, studio, year, outline, runtime, director, actor_photo, release, number, cover, trailer, website, series, label = get_info(json_data)
if len(location_rule) > 240: # 新建成功输出文件夹
path = success_folder + '/' + location_rule.replace("'actor'", "'manypeople'", 3).replace("actor","'manypeople'",3) # path为影片+元数据所在目录
else:
@@ -326,6 +354,44 @@ def download_file_with_filename(url, filename, path, conf: config.Config, filepa
moveFailedFolder(filepath, failed_folder)
return
def trailer_download(trailer, c_word, number, path, filepath, conf: config.Config, failed_folder):
if download_file_with_filename(trailer, number + c_word + '-trailer.mp4', path, conf, filepath, failed_folder) == 'failed':
return
switch, _proxy, _timeout, retry, _proxytype = conf.proxy()
for i in range(retry):
if os.path.getsize(path+'/' + number + c_word + '-trailer.mp4') == 0:
print('[!]Video Download Failed! Trying again. [{}/3]', i + 1)
download_file_with_filename(trailer, number + c_word + '-trailer.mp4', path, conf, filepath, failed_folder)
continue
else:
break
if os.path.getsize(path + '/' + number + c_word + '-trailer.mp4') == 0:
return
print('[+]Video Downloaded!', path + '/' + number + c_word + '-trailer.mp4')
# 剧照下载成功否则移动到failed
def extrafanart_download(data, path, conf: config.Config, filepath, failed_folder):
j = 1
path = path + '/' + conf.get_extrafanart()
for url in data:
if download_file_with_filename(url, '/extrafanart-' + str(j)+'.jpg', path, conf, filepath, failed_folder) == 'failed':
moveFailedFolder(filepath, failed_folder)
return
switch, _proxy, _timeout, retry, _proxytype = conf.proxy()
for i in range(retry):
if os.path.getsize(path + '/extrafanart-' + str(j) + '.jpg') == 0:
print('[!]Image Download Failed! Trying again. [{}/3]', i + 1)
download_file_with_filename(url, '/extrafanart-' + str(j)+'.jpg', path, conf, filepath,
failed_folder)
continue
else:
break
if os.path.getsize(path + '/extrafanart-' + str(j) + '.jpg') == 0:
return
print('[+]Image Downloaded!', path + '/extrafanart-' + str(j) + '.jpg')
j += 1
# 封面是否下载成功否则移动到failed
def image_download(cover, number, c_word, path, conf: config.Config, filepath, failed_folder):
@@ -348,7 +414,7 @@ def image_download(cover, number, c_word, path, conf: config.Config, filepath, f
def print_files(path, c_word, naming_rule, part, cn_sub, json_data, filepath, failed_folder, tag, actor_list, liuchu):
title, studio, year, outline, runtime, director, actor_photo, release, number, cover, website, series, label = get_info(json_data)
title, studio, year, outline, runtime, director, actor_photo, release, number, cover, trailer, website, series, label = get_info(json_data)
try:
if not os.path.exists(path):
@@ -397,6 +463,7 @@ def print_files(path, c_word, naming_rule, part, cn_sub, json_data, filepath, fa
print(" <num>" + number + "</num>", file=code)
print(" <premiered>" + release + "</premiered>", file=code)
print(" <cover>" + cover + "</cover>", file=code)
print(" <trailer>" + trailer + "</trailer>", file=code)
print(" <website>" + website + "</website>", file=code)
print("</movie>", file=code)
print("[+]Wrote! " + path + "/" + number + part + c_word + ".nfo")
@@ -428,9 +495,70 @@ def cutImage(imagecut, path, number, c_word):
shutil.copyfile(path + '/' + number + c_word + '-fanart.jpg',path + '/' + number + c_word + '-poster.jpg')
print('[+]Image Copyed! ' + path + '/' + number + c_word + '-poster.jpg')
# 此函数从gui版copy过来用用
# 参数说明
# poster_path
# thumb_path
# cn_sub 中文字幕 参数值为 1 0
# leak 流出 参数值为 1 0
# uncensored 无码 参数值为 1 0
# ========================================================================加水印
def add_mark(poster_path, thumb_path, cn_sub, leak, uncensored, conf:config.Config):
mark_type = ''
if cn_sub:
mark_type += ',字幕'
if leak:
mark_type += ',流出'
if uncensored:
mark_type += ',无码'
add_mark_thread(thumb_path, cn_sub, leak, uncensored, conf)
print('[+]Thumb Add Mark: ' + mark_type.strip(','))
add_mark_thread(poster_path, cn_sub, leak, uncensored, conf)
print('[+]Poster Add Mark: ' + mark_type.strip(','))
def add_mark_thread(pic_path, cn_sub, leak, uncensored, conf):
size = 14
img_pic = Image.open(pic_path)
# 获取自定义位置取余配合pos达到顺时针添加的效果
# 左上 0, 右上 1, 右下 2 左下 3
count = conf.watermark_type()
if cn_sub == 1 or cn_sub == '1':
add_to_pic(pic_path, img_pic, size, count, 1) # 添加
count = (count + 1) % 4
if leak == 1 or leak == '1':
add_to_pic(pic_path, img_pic, size, count, 2)
count = (count + 1) % 4
if uncensored == 1 or uncensored == '1':
add_to_pic(pic_path, img_pic, size, count, 3)
img_pic.close()
def add_to_pic(pic_path, img_pic, size, count, mode):
mark_pic_path = ''
if mode == 1:
mark_pic_path = 'Img/SUB.png'
elif mode == 2:
mark_pic_path = 'Img/LEAK.png'
elif mode == 3:
mark_pic_path = 'Img/UNCENSORED.png'
img_subt = Image.open(mark_pic_path)
scroll_high = int(img_pic.height / size)
scroll_wide = int(scroll_high * img_subt.width / img_subt.height)
img_subt = img_subt.resize((scroll_wide, scroll_high), Image.ANTIALIAS)
r, g, b, a = img_subt.split() # 获取颜色通道保持png的透明性
# 封面四个角的位置
pos = [
{'x': 0, 'y': 0},
{'x': img_pic.width - scroll_wide, 'y': 0},
{'x': img_pic.width - scroll_wide, 'y': img_pic.height - scroll_high},
{'x': 0, 'y': img_pic.height - scroll_high},
]
img_pic.paste(img_subt, (pos[count]['x'], pos[count]['y']), mask=a)
img_pic.save(pic_path, quality=95)
# ========================结束=================================
def paste_file_to_folder(filepath, path, number, c_word, conf: config.Config): # 文件路径,番号,后缀,要移动至的位置
houzhui = str(re.search('[.](iso|ISO|AVI|RMVB|WMV|MOV|MP4|MKV|FLV|TS|WEBM|avi|rmvb|wmv|mov|mp4|mkv|flv|ts|webm)$', filepath).group())
media_res = conf.media_rule()
houzhui = str(re.search(media_res + '$', filepath).group())
file_parent_origin_path = str(pathlib.Path(filepath).parent)
try:
# 如果soft_link=1 使用软链接
@@ -438,15 +566,14 @@ def paste_file_to_folder(filepath, path, number, c_word, conf: config.Config):
os.symlink(filepath, path + '/' + number + c_word + houzhui)
else:
os.rename(filepath, path + '/' + number + c_word + houzhui)
if os.path.exists(file_parent_origin_path + '/' + number + c_word + '.srt'): # 字幕移动
os.rename(file_parent_origin_path + '/' + number + c_word + '.srt', path + '/' + number + c_word + '.srt')
print('[+]Sub moved!')
elif os.path.exists(file_parent_origin_path + '/' + number + c_word + '.ssa'):
os.rename(file_parent_origin_path + '/' + number + c_word + '.ssa', path + '/' + number + c_word + '.ssa')
print('[+]Sub moved!')
elif os.path.exists(file_parent_origin_path + '/' + number + c_word + '.sub'):
os.rename(file_parent_origin_path + '/' + number + c_word + '.sub', path + '/' + number + c_word + '.sub')
print('[+]Sub moved!')
sub_res = conf.sub_rule()
for subname in sub_res:
if os.path.exists(os.getcwd() + '/' + number + c_word + subname): # 字幕移动
os.rename(os.getcwd() + '/' + number + c_word + subname, path + '/' + number + c_word + subname)
print('[+]Sub moved!')
return True
except FileExistsError:
print('[-]File Exists! Please check your movie!')
print('[-]move to the root folder of the program.')
@@ -459,23 +586,22 @@ def paste_file_to_folder(filepath, path, number, c_word, conf: config.Config):
def paste_file_to_folder_mode2(filepath, path, multi_part, number, part, c_word, conf): # 文件路径,番号,后缀,要移动至的位置
if multi_part == 1:
number += part # 这时number会被附加上CD1后缀
houzhui = str(re.search('[.](AVI|RMVB|WMV|MOV|MP4|MKV|FLV|TS|WEBM|avi|rmvb|wmv|mov|mp4|mkv|flv|ts|webm|iso|ISO)$', filepath).group())
media_res = conf.media_rule()
houzhui = str(re.search(media_res + '$', filepath).group())
file_parent_origin_path = str(pathlib.Path(filepath).parent)
try:
if conf.soft_link():
os.symlink(filepath, path + '/' + number + part + c_word + houzhui)
else:
os.rename(filepath, path + '/' + number + part + c_word + houzhui)
if os.path.exists(file_parent_origin_path + '/' + number + '.srt'): # 字幕移动
os.rename(file_parent_origin_path + '/' + number + part + c_word + '.srt', path + '/' + number + part + c_word + '.srt')
print('[+]Sub moved!')
elif os.path.exists(file_parent_origin_path + '/' + number + part + c_word + '.ass'):
os.rename(file_parent_origin_path + '/' + number + part + c_word + '.ass', path + '/' + number + part + c_word + '.ass')
print('[+]Sub moved!')
elif os.path.exists(file_parent_origin_path + '/' + number + part + c_word + '.sub'):
os.rename(file_parent_origin_path + '/' + number + part + c_word + '.sub', path + '/' + number + part + c_word + '.sub')
print('[+]Sub moved!')
print('[!]Success')
sub_res = conf.sub_rule()
for subname in sub_res:
if os.path.exists(os.getcwd() + '/' + number + c_word + subname): # 字幕移动
os.rename(os.getcwd() + '/' + number + c_word + subname, path + '/' + number + c_word + subname)
print('[+]Sub moved!')
print('[!]Success')
return True
except FileExistsError:
print('[-]File Exists! Please check your movie!')
print('[-]move to the root folder of the program.')
@@ -547,8 +673,19 @@ def core_main(file_path, number_th, conf: config.Config):
if '-c.' in filepath or '-C.' in filepath or '中文' in filepath or '字幕' in filepath:
cn_sub = '1'
c_word = '-C' # 中文字幕影片后缀
# 判断是否无码
if is_uncensored(number):
uncensored = 1
else:
uncensored = 0
if '流出' in filepath:
liuchu = '流出'
leak = 1
else:
leak = 0
# 调试模式检测
if conf.debug():
@@ -574,6 +711,14 @@ def core_main(file_path, number_th, conf: config.Config):
# creatFolder会返回番号路径
image_download( json_data.get('cover'), number, c_word, path, conf, filepath, conf.failed_folder())
# 下载预告片
if json_data.get('trailer'):
trailer_download(json_data.get('trailer'), c_word, number, path, filepath, conf, conf.failed_folder())
# 下载剧照 data, path, conf: config.Config, filepath, failed_folder
if json_data.get('extrafanart'):
extrafanart_download(json_data.get('extrafanart'), path, conf, filepath, conf.failed_folder())
# 裁剪图
cutImage(imagecut, path, number, c_word)
@@ -582,6 +727,12 @@ def core_main(file_path, number_th, conf: config.Config):
# 移动文件
paste_file_to_folder(filepath, path, number, c_word, conf)
poster_path = path + '/' + number + c_word + '-poster.jpg'
thumb_path = path + '/' + number + c_word + '-thumb.jpg'
if conf.is_watermark():
add_mark(poster_path, thumb_path, cn_sub, leak, uncensored, conf)
elif conf.main_mode() == 2:
# 创建文件夹
path = create_folder(conf.success_folder(), json_data.get('location_rule'), json_data, conf)