mirror of
https://github.com/xhlove/GetDanMu.git
synced 2025-12-17 08:35:57 +08:00
第一次上传
This commit is contained in:
71
basic/ass.py
Normal file
71
basic/ass.py
Normal file
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
'''
|
||||
# 作者: weimo
|
||||
# 创建日期: 2020-01-04 13:05:23
|
||||
# 上次编辑时间 : 2020-01-04 15:52:11
|
||||
# 一个人的命运啊,当然要靠自我奋斗,但是...
|
||||
'''
|
||||
|
||||
import os
|
||||
|
||||
from basic.vars import fonts
|
||||
|
||||
|
||||
ass_script = """[Script Info]
|
||||
; Script generated by N
|
||||
ScriptType: v4.00+
|
||||
PlayResX: 1920
|
||||
PlayResY: 1080
|
||||
Aspect Ratio: 1920:1080
|
||||
Collisions: Normal
|
||||
WrapStyle: 0
|
||||
ScaledBorderAndShadow: yes
|
||||
YCbCr Matrix: TV.601"""
|
||||
|
||||
ass_style_head = """[V4+ Styles]\nFormat: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding"""
|
||||
ass_style_default = """Style: Default,Arial,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1"""
|
||||
ass_style_base = """Style:{font},{font},{font_size},&H00FFFFFF,&H66FFFFFF,&H66000000,&H66000000,0,0,0,0,100,100,0.00,0.00,1,1,0,7,0,0,0,0"""
|
||||
ass_events_head = """[Events]\nFormat: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"""
|
||||
# 基于当前时间范围,在0~1000ms之间停留在(676.571,506.629)处,在1000~3000ms内从位置1300,600移动到360,600(原点在左上)
|
||||
# ass_baseline = """Dialogue: 0,0:20:08.00,0:20:28.00,Default,,0,0,0,,{\t(1000,3000,\move(1300,600,360,600))\pos(676.571,506.629)}这是字幕内容示意"""
|
||||
|
||||
def get_ass_head(font_style_name, font_size):
|
||||
ass_head = ass_script + "\n\n" + ass_style_head + "\n" + ass_style_base.format(font=font_style_name, font_size=font_size) + "\n\n" + ass_events_head
|
||||
return ass_head
|
||||
|
||||
def check_font(font):
|
||||
win_font_path = r"C:\Windows\Fonts"
|
||||
maybe_font_path = os.path.join(win_font_path, font)
|
||||
font_style_name = "微软雅黑"
|
||||
font_path = os.path.join(win_font_path, fonts[font_style_name]) # 默认
|
||||
if os.path.exists(font):
|
||||
# 字体就在当前文件夹 或 完整路径
|
||||
if os.path.isfile(font):
|
||||
if os.path.isabs(font):
|
||||
font_path = font
|
||||
else:
|
||||
font_path = os.path.join(os.getcwd(), font)
|
||||
font_style_name = font[:-os.path.splitext(font)[-1].__len__()]
|
||||
else:
|
||||
pass
|
||||
elif os.path.exists(maybe_font_path):
|
||||
# 给的是字体文件名
|
||||
if os.path.isfile(maybe_font_path):
|
||||
font_path = maybe_font_path
|
||||
font_style_name = font[:-os.path.splitext(font)[-1].__len__()]
|
||||
else:
|
||||
pass
|
||||
elif fonts.get(font):
|
||||
# 别名映射
|
||||
font_path = os.path.join(win_font_path, fonts.get(font))
|
||||
font_style_name = font
|
||||
else:
|
||||
pass
|
||||
return font_path, font_style_name
|
||||
|
||||
def check_content(content: str, comments: list):
|
||||
content = content.replace(" ", "")
|
||||
if content in comments:
|
||||
return
|
||||
return content
|
||||
19
basic/vars.py
Normal file
19
basic/vars.py
Normal file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
'''
|
||||
# 作者: weimo
|
||||
# 创建日期: 2020-01-04 13:16:18
|
||||
# 上次编辑时间 : 2020-01-04 16:08:34
|
||||
# 一个人的命运啊,当然要靠自我奋斗,但是...
|
||||
'''
|
||||
qqlive = {
|
||||
"User-Agent":"qqlive"
|
||||
}
|
||||
iqiyiplayer = {
|
||||
"User-Agent":"Qiyi List Client PC 7.2.102.1343"
|
||||
}
|
||||
fonts = {
|
||||
"微软雅黑":"msyh.ttc",
|
||||
"微软雅黑粗体":"msyhbd.ttc",
|
||||
"微软雅黑细体":"msyhl.ttc",
|
||||
}
|
||||
Reference in New Issue
Block a user