def parse(url, config): # 获取标题 CONFIG.update(config) spider.set_cookies(config["cookies"]) title = get_title(url) print(title) # 创建所需目录结构 CONFIG["base_dir"] = touch_dir( os.path.join(CONFIG['dir'], repair_filename(title + " - bilibili"))) CONFIG["video_dir"] = touch_dir(os.path.join(CONFIG['base_dir'], "Videos")) if CONFIG["playlist_type"] == "dpl": CONFIG['playlist'] = Dpl(os.path.join(CONFIG['base_dir'], 'Playlist.dpl'), path_type=CONFIG["playlist_path_type"]) elif CONFIG["playlist_type"] == "m3u": CONFIG['playlist'] = M3u(os.path.join(CONFIG['base_dir'], 'Playlist.m3u'), path_type=CONFIG["playlist_path_type"]) else: CONFIG['playlist'] = None # 获取需要的信息 videos = get_videos(url) CONFIG["videos"] = videos if CONFIG['playlist'] is not None: CONFIG['playlist'].flush() # 解析并过滤不需要的选集 episodes = parse_episodes(CONFIG["episodes"], len(videos)) videos = list(filter(lambda video: video.id in episodes, videos)) CONFIG["videos"] = videos # 解析片段信息及视频 url for i, video in enumerate(videos): print("{:02}/{:02} parsing segments info...".format(i, len(videos)), end="\r") parse_segment_info(video) # 导出下载所需数据 exports.update({"videos": videos, "video_dir": CONFIG["video_dir"]})
def convert_danmaku(video_path_list): """ 将视频文件夹下的 xml 弹幕转换为 ass 弹幕 """ # 检测插件是否已经就绪 plugin_url = "https://raw.githubusercontent.com/m13253/danmaku2ass/master/danmaku2ass.py" plugin_path = "plugins/danmaku2ass.py" touch_dir(os.path.dirname(plugin_path)) touch_file(os.path.join(os.path.dirname(plugin_path), "__init__.py")) if not os.path.exists(plugin_path): print("下载插件中……") res = requests.get(plugin_url) with open(plugin_path, "w", encoding="utf8") as f: f.write(res.text) # 使用插件进行转换 from plugins.danmaku2ass import Danmaku2ASS for video_path in video_path_list: name = os.path.splitext(video_path)[0] print("convert {} ".format(os.path.split(name)[-1]), end="\r") if not os.path.exists(name+".mp4") or \ not os.path.exists(name+".xml"): continue cap = cv2.VideoCapture(name + ".mp4") __, frame = cap.read() h, w, __ = frame.shape Danmaku2ASS(name + ".xml", "autodetect", name + ".ass", w, h, reserve_blank=0, font_face=_('(FONT) sans-serif')[7:], font_size=w / 40, text_opacity=0.8, duration_marquee=15.0, duration_still=10.0, comment_filter=None, is_reduce_comments=False, progress_callback=None)