mirror of
https://github.com/xhlove/GetDanMu.git
synced 2025-12-17 08:35:57 +08:00
增加优酷弹幕下载以及其他改进
This commit is contained in:
@@ -3,11 +3,24 @@
|
||||
'''
|
||||
# 作者: weimo
|
||||
# 创建日期: 2020-01-05 12:45:18
|
||||
# 上次编辑时间: 2020-01-05 14:44:42
|
||||
# 上次编辑时间 : 2020-01-11 17:37:22
|
||||
# 一个人的命运啊,当然要靠自我奋斗,但是...
|
||||
'''
|
||||
|
||||
import hashlib
|
||||
from urllib.parse import urlparse
|
||||
|
||||
def remove_same_danmu(comments: list):
|
||||
# 在原有基础上pop会引起索引变化 所以还是采用下面这个方式
|
||||
contents = []
|
||||
for comment in comments:
|
||||
content, color, timepoint = comment
|
||||
content = content.replace(" ", "")
|
||||
if content in contents:
|
||||
continue
|
||||
else:
|
||||
contents.append([content, color, timepoint])
|
||||
return contents
|
||||
|
||||
def check_url_site(url):
|
||||
return urlparse(url).netloc.split(".")[-2]
|
||||
@@ -21,4 +34,11 @@ def check_url_locale(url):
|
||||
if urlparse(url).netloc.split(".")[0] == "tw":
|
||||
return flag["tw"]
|
||||
else:
|
||||
return flag["cn"]
|
||||
return flag["cn"]
|
||||
|
||||
def yk_msg_sign(msg: str):
|
||||
return hashlib.new("md5", bytes(msg + "MkmC9SoIw6xCkSKHhJ7b5D2r51kBiREr", "utf-8")).hexdigest()
|
||||
|
||||
def yk_t_sign(token, t, appkey, data):
|
||||
text = "&".join([token, t, appkey, data])
|
||||
return hashlib.new('md5', bytes(text, 'utf-8')).hexdigest()
|
||||
@@ -3,7 +3,7 @@
|
||||
'''
|
||||
# 作者: weimo
|
||||
# 创建日期: 2020-01-04 19:17:44
|
||||
# 上次编辑时间: 2020-01-05 14:45:03
|
||||
# 上次编辑时间 : 2020-01-11 17:25:09
|
||||
# 一个人的命运啊,当然要靠自我奋斗,但是...
|
||||
'''
|
||||
import os
|
||||
@@ -11,16 +11,19 @@ import os
|
||||
from basic.ass import get_ass_head, check_font
|
||||
from methods.assbase import ASS
|
||||
from methods.sameheight import SameHeight
|
||||
from pfunc.cfunc import remove_same_danmu
|
||||
|
||||
def write_one_video_subtitles(file_path, comments, args):
|
||||
# 对于合集则每次都都得检查一次 也可以放在上一级 放在这里 考虑后面可能特殊指定字体的情况
|
||||
font_path, font_style_name = check_font(args.font)
|
||||
ass_head = get_ass_head(font_style_name, args.font_size)
|
||||
get_xy_obj = SameHeight("那就写这一句作为初始化测试吧!", font_path=font_path, font_size=args.font_size)
|
||||
get_xy_obj = SameHeight("那就写这一句作为初始化测试吧!", font_path=font_path, font_size=int(args.font_size))
|
||||
subtitle = ASS(file_path, get_xy_obj, font=font_style_name)
|
||||
comments = remove_same_danmu(comments)
|
||||
for comment in comments:
|
||||
subtitle.create_new_line(comment)
|
||||
write_lines_to_file(ass_head, subtitle.lines, file_path)
|
||||
return comments
|
||||
|
||||
def write_lines_to_file(ass_head, lines, file_path):
|
||||
with open(file_path, "a+", encoding="utf-8") as f:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
'''
|
||||
# 作者: weimo
|
||||
# 创建日期: 2020-01-04 19:14:43
|
||||
# 上次编辑时间: 2020-01-05 14:47:16
|
||||
# 上次编辑时间 : 2020-01-11 17:42:30
|
||||
# 一个人的命运啊,当然要靠自我奋斗,但是...
|
||||
'''
|
||||
import re
|
||||
@@ -192,4 +192,64 @@ def get_vinfos_by_url(url):
|
||||
else:
|
||||
return get_vinfos(aid, locale=locale)
|
||||
|
||||
#-------------------------------------------iqiyi--------------------------------------------
|
||||
#-------------------------------------------iqiyi--------------------------------------------
|
||||
|
||||
#-------------------------------------------youku--------------------------------------------
|
||||
|
||||
def get_vinfos_by_url_youku(url, isall=False):
|
||||
vid_patterns = ["[\s\S]+?youku.com/video/id_(/+?)\.html", "[\s\S]+?youku.com/v_show/id_(.+?)\.html"]
|
||||
video_id = matchit(vid_patterns, url)
|
||||
show_id_patterns = ["[\s\S]+?youku.com/v_nextstage/id_(/+?)\.html", "[\s\S]+?youku.com/show/id_z(.+?)\.html", "[\s\S]+?youku.com/show_page/id_z(.+?)\.html", "[\s\S]+?youku.com/alipay_video/id_(.+?)\.html"]
|
||||
show_id = matchit(show_id_patterns, url)
|
||||
if video_id is None and show_id is None:
|
||||
return None
|
||||
if video_id:
|
||||
return get_vinfos_by_video_id(video_id, isall=isall)
|
||||
if show_id.__len__() == 20 and show_id == show_id.lower():
|
||||
return get_vinfos_by_show_id(show_id)
|
||||
else:
|
||||
return get_vinfos_by_video_id(show_id, isall=isall)
|
||||
|
||||
def get_vinfos_by_video_id(video_id, isall=False):
|
||||
api_url = "https://openapi.youku.com/v2/videos/show.json?client_id=53e6cc67237fc59a&package=com.huawei.hwvplayer.youku&ext=show&video_id={}".format(video_id)
|
||||
try:
|
||||
r = requests.get(api_url, headers=chrome, timeout=5).content.decode("utf-8")
|
||||
except Exception as e:
|
||||
print("get_vinfos_by_video_id error info -->", e)
|
||||
return None
|
||||
data = json.loads(r)
|
||||
if isall:
|
||||
show_id = data["show"]["id"]
|
||||
return get_vinfos_by_show_id(show_id)
|
||||
duration = 0
|
||||
if data.get("duration"):
|
||||
duration = int(float(data["duration"]))
|
||||
if data.get("title"):
|
||||
name = data["title"] + "_" + str(duration)
|
||||
else:
|
||||
name = "优酷未知" + "_" + str(duration)
|
||||
vinfo = [name, duration, video_id]
|
||||
return [vinfo]
|
||||
|
||||
def get_vinfos_by_show_id(show_id):
|
||||
api_url = "https://openapi.youku.com/v2/shows/videos.json?show_videotype=正片&count=100&client_id=53e6cc67237fc59a&page=1&show_id={}&package=com.huawei.hwvplayer.youku".format(show_id)
|
||||
try:
|
||||
r = requests.get(api_url, headers=chrome, timeout=5).content.decode("utf-8")
|
||||
except Exception as e:
|
||||
print("get_vinfos_by_show_id error info -->", e)
|
||||
return None
|
||||
data = json.loads(r)["videos"]
|
||||
if data.__len__() == 0:
|
||||
return None
|
||||
vinfos = []
|
||||
for video in data:
|
||||
duration = 0
|
||||
if video.get("duration"):
|
||||
duration = int(float(video["duration"]))
|
||||
if video.get("title"):
|
||||
name = video["title"] + "_" + str(duration)
|
||||
else:
|
||||
name = "优酷未知_{}".format(video["id"]) + "_" + str(duration)
|
||||
vinfos.append([name, duration, video["id"]])
|
||||
return vinfos
|
||||
#-------------------------------------------youku--------------------------------------------
|
||||
Reference in New Issue
Block a user