├── src └── danmaku_tools │ ├── __init__.py │ ├── danmaku_tools.py │ ├── cut_danmaku.py │ ├── he_video.py │ ├── merge_danmaku.py │ ├── analyze_danmaku.py │ └── danmaku_energy_map.py ├── pyproject.toml ├── requirements.txt ├── setup.cfg ├── README.md └── LICENSE /src/danmaku_tools/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ 3 | "setuptools>=42", 4 | "wheel" 5 | ] 6 | build-backend = "setuptools.build_meta" -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | matplotlib~=3.3.3 2 | numpy~=1.18.5 3 | scipy~=1.5.4 4 | python-dateutil~=2.8.1 5 | srt~=3.4.1 6 | tqdm~=4.53.0 7 | textrank4zh~=0.3 -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | name = danmaku-tools 3 | version = 0.0.8 4 | author = Jackie Yang 5 | author_email = jackie@jackieyang.me 6 | description = Process XML Danmaku File from BililiveRecorder 7 | long_description = file: README.md 8 | long_description_content_type = text/markdown 9 | url = https://github.com/valkjsaaa/danmaku_tools 10 | project_urls = 11 | Bug Tracker = https://github.com/valkjsaaa/danmaku_tools/issues 12 | classifiers = 13 | Development Status :: 3 - Alpha 14 | Programming Language :: Python :: 3 15 | License :: OSI Approved :: GNU General Public License v3 (GPLv3) 16 | Operating System :: OS Independent 17 | 18 | [options] 19 | package_dir = 20 | = src 21 | packages = find: 22 | python_requires = >=3.7 23 | install_requires = 24 | matplotlib 25 | numpy 26 | scipy 27 | python-dateutil 28 | srt 29 | tqdm 30 | textrank4zh 31 | 32 | [options.packages.find] 33 | where = src 34 | -------------------------------------------------------------------------------- /src/danmaku_tools/danmaku_tools.py: -------------------------------------------------------------------------------- 1 | import xml.etree.ElementTree as ET 2 | import json 3 | 4 | 5 | def read_danmaku_file(file_path, guard=False): 6 | xmlp = ET.XMLParser(encoding="utf-8") 7 | tree = ET.parse(file_path, parser=xmlp) 8 | root = tree.getroot() 9 | 10 | all_children = [child for child in root if child.tag in ['gift', 'sc', 'd'] + (['guard'] if guard else [])] 11 | return all_children 12 | 13 | 14 | def get_time(child: ET.Element): 15 | # noinspection PyBroadException 16 | try: 17 | if child.tag == 'd': 18 | return float(child.attrib['p'].split(',')[0]) 19 | elif child.tag == 'gift' or child.tag == 'sc': 20 | return float(child.attrib['ts']) 21 | except: 22 | print(f"error getting time from {child}") 23 | return 0 24 | 25 | 26 | def get_value(child: ET.Element): 27 | # noinspection PyBroadException 28 | try: 29 | if child.tag == 'd': 30 | return 1 31 | elif child.tag == 'gift': 32 | raw_data = json.loads(child.attrib['raw']) 33 | return raw_data['total_coin'] / 1000 / 10 34 | elif child.tag == 'sc': 35 | raw_data = json.loads(child.attrib['raw']) 36 | return raw_data['price'] / 10 37 | elif child.tag == 'guard': 38 | raw_data = json.loads(child.attrib['raw']) 39 | return raw_data['price'] / 1000 / 10 40 | except: 41 | print(f"error getting value from {child}") 42 | return 0 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Bilibili Live Danmaku Tools 哔哩哔哩直播弹幕处理工具 2 | =========================== 3 | 4 | 本工具可用于处理 B站录播姬 产生的弹幕 XML。具体功能有: 5 | 1. 分切 弹幕 XML 6 | 2. 合并 弹幕 XML 7 | 3. 分析 弹幕 XML 中的弹幕数量以及礼物价格 8 | 4. 分析 弹幕 XML 中的高能点(主要用于生成录播) 9 | 10 | ### 安装 11 | 12 | ```bash 13 | pip3 install danmaku_tools 14 | ``` 15 | 16 | ### 典型使用例子 17 | 18 | #### 合并 19 | 20 | 根据 flv 文件的长度合并 XML 21 | ```bash 22 | python3 -m danmaku_tools.merge_danmaku video_1.xml video_2.xml video_3.xml --video_time ".flv" --output video_combined.xml 23 | ``` 24 | 25 | 经常和类似这样的视频合并命令同时使用 26 | ```bash 27 | echo "file video_1.flv\n file video_2.flv" > video.input.txt 28 | ffmpeg -f concat -safe 0 -i video_input.txt video_combined.flv 29 | ``` 30 | 31 | 根据 XML 开始时间合并 XML 32 | ```bash 33 | python3 -m danmaku_tools.merge_danmaku video_1.xml video_2.xml video_3.xml --output video_combined.xml 34 | ``` 35 | 36 | #### 剪切 37 | 38 | 从 123.45 秒开始剪切 XML 39 | ```bash 40 | python3 -m danmaku_tools.cut_danmaku --start_time 123.45 video_input.xml --output video_output.xml 41 | ``` 42 | 43 | 从 123.45 秒到 567.89 开始剪切 XML 44 | ```bash 45 | python3 -m danmaku_tools.cut_danmaku --start_time 123.45 --end_time 567.89 video_input.xml --output video_output.xml 46 | ``` 47 | 48 | 经常和类似这样的视频剪切命令同时使用 49 | ```bash 50 | ffmpeg -ss 123.45 -to 567.89 -i video_input.flv video_output.flv 51 | ``` 52 | 53 | #### 分析流水 54 | 55 | ```bash 56 | python3 -m danmaku_tools.analyze_danmaku video.xml 57 | ``` 58 | 输出如下: 59 | ``` 60 | 弹幕:46541条 61 | 醒目留言:15294.0元 62 | 礼物:7366.440000000309元 63 | 大航海:10116.0元 64 | 大航海类别:{'舰长': 41, '提督': 1} 65 | 总流水 32776.44000000031元 66 | ``` 67 | 68 | #### 分析高能 69 | 70 | ```bash 71 | python3 -m danmaku_tools.danmaku_energy_map video.xml `# 输入 XML 文件` \ 72 | --graph video.he.png `# 高能进度条 png` \ 73 | --he_map he_list.txt `# 高能列表` \ 74 | --sc_list sc_list.txt `# 醒目留言列表` \ 75 | --sc_srt sc.srt `# 醒目留言字幕` \ 76 | --he_time he_time.txt `# 最高能时间点` \ 77 | --he_range he_range.txt `# 最高能时间段` 78 | ``` 79 | -------------------------------------------------------------------------------- /src/danmaku_tools/cut_danmaku.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import argparse 4 | import xml.etree.ElementTree as ET 5 | 6 | from dateutil.parser import parse 7 | 8 | parser = argparse.ArgumentParser(description='Merge BiliLiveReocrder XML') 9 | parser.add_argument('xml_files', type=str, help='path to the danmaku file') 10 | parser.add_argument('--start_time', type=float, help='use video length as the duration of the file', default=0) 11 | parser.add_argument('--end_time', type=float, help='use video length as the duration of the file', default=float('inf')) 12 | parser.add_argument('--output', type=str, default=None, help='output path for the output XML', required=True) 13 | 14 | 15 | def get_root_time(root_xml): 16 | record_info = root_xml.findall('BililiveRecorderRecordInfo')[0] 17 | record_start_time_str = record_info.attrib['start_time'] 18 | record_start_time = parse(record_start_time_str) 19 | return record_start_time 20 | 21 | 22 | def process_root(orig_root, start_time, end_time): 23 | new_root = ET.Element('i') 24 | for child in orig_root: 25 | if child.tag in ['sc', 'gift', 'guard']: 26 | orig_time = float(child.attrib['ts']) 27 | if start_time <= orig_time <= end_time: 28 | new_time = orig_time - start_time 29 | new_time_str = str(new_time) 30 | child.set('ts', new_time_str) 31 | new_root.append(child) 32 | elif child.tag in ['d']: 33 | orig_parameters_str = child.attrib['p'].split(',') 34 | orig_time = float(orig_parameters_str[0]) 35 | if start_time <= orig_time <= end_time: 36 | new_time = orig_time - start_time 37 | new_parameters_str = [str(new_time)] + orig_parameters_str[1:] 38 | child.set('p', ','.join(new_parameters_str)) 39 | new_root.append(child) 40 | else: 41 | new_root.append(child) 42 | return new_root 43 | 44 | 45 | if __name__ == '__main__': 46 | args = parser.parse_args() 47 | 48 | tree = ET.parse(args.xml_files) 49 | root = tree.getroot() 50 | new_root_offset = 0 51 | root_time = get_root_time(root) 52 | all_flv = "" 53 | 54 | new_root = process_root(root, args.start_time, args.end_time) 55 | 56 | ET.ElementTree(new_root).write(args.output, encoding='UTF-8', xml_declaration=True) 57 | -------------------------------------------------------------------------------- /src/danmaku_tools/he_video.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | import sys 4 | 5 | import ffmpeg 6 | from ffmpeg_smart_trim.trim import TrimVideo 7 | 8 | 9 | # parser = argparse.ArgumentParser(description='Cut HE range in BiliBili live recordings') 10 | # parser.add_argument('--he_range', type=str, help='path to he range file') 11 | # parser.add_argument('--video', type=str, help='path to video to cut') 12 | # 13 | # args = parser.parse_args() 14 | class args: 15 | name = "128308-20210427-224046" 16 | he_range = f"/Users/jackie/Downloads/{name}.all.he_range.txt" 17 | video = f"/Users/jackie/Downloads/{name}.all.bar.mp4" 18 | output = f"/Users/jackie/Downloads/{name}.he.all.bar.mp4" 19 | 20 | 21 | # %% 22 | with open(args.he_range, "r") as he_file: 23 | he_range = json.load(he_file) 24 | 25 | if len(he_range) == 0: 26 | sys.exit(1) 27 | 28 | EXPAND_TIME = 10 29 | expanded_he_range = [(current_range[0] - EXPAND_TIME, current_range[1] + EXPAND_TIME) for current_range in he_range] 30 | 31 | he_range = [] 32 | last_range = None 33 | 34 | for current_range in expanded_he_range: 35 | if last_range is None: 36 | last_range = current_range 37 | continue 38 | else: 39 | if last_range[1] >= current_range[0]: 40 | last_range = (last_range[0], current_range[1]) 41 | else: 42 | he_range += [last_range] 43 | last_range = current_range 44 | 45 | # noinspection PyUnboundLocalVariable 46 | he_range += [current_range] 47 | 48 | # %% 49 | print("Parsing video file...") 50 | video = TrimVideo(args.video, time_range=(he_range[0][0], he_range[-1][1])) 51 | 52 | files, fast_trims, slow_trims = [], [], [] 53 | 54 | for i, current_he_range in enumerate(he_range): 55 | current_files, current_fast_trims, current_slow_trims \ 56 | = video.generate_trim(current_he_range[0], current_he_range[1], prefix=str(i)) 57 | files += current_files 58 | fast_trims += current_fast_trims 59 | slow_trims += current_slow_trims 60 | print("Trimming video file...") 61 | if len(fast_trims) > 0: 62 | print(ffmpeg.merge_outputs(*fast_trims).compile()) 63 | ffmpeg.merge_outputs(*fast_trims).run(overwrite_output=True) 64 | if len(slow_trims) > 0: 65 | print(ffmpeg.merge_outputs(*slow_trims).compile()) 66 | ffmpeg.merge_outputs(*slow_trims).run(overwrite_output=True) 67 | temp_merge_path = os.path.join(video.temp_dir, "merged.mp4") 68 | merge_cmd = video.generate_merge(files, temp_merge_path) 69 | print(merge_cmd.compile()) 70 | print("Merging video file...") 71 | merge_cmd.run(overwrite_output=True) 72 | merged_input = ffmpeg.input(temp_merge_path) 73 | copy_cmd = ffmpeg.output(merged_input, args.output, c='copy') 74 | print("Copying video to destination...") 75 | print(copy_cmd.compile()) 76 | copy_cmd.run(overwrite_output=True) 77 | video.clean_temp() 78 | -------------------------------------------------------------------------------- /src/danmaku_tools/merge_danmaku.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import subprocess 3 | import xml.etree.ElementTree as ET 4 | from dateutil.parser import parse 5 | 6 | parser = argparse.ArgumentParser(description='Merge BiliLiveReocrder XML') 7 | parser.add_argument('xml_files', type=str, nargs='+', help='path to the danmaku file') 8 | parser.add_argument('--video_time', type=str, default="", help='use video length as the duration of the file') 9 | parser.add_argument('--output', type=str, default=None, help='output path for the output XML', required=True) 10 | 11 | 12 | def get_root_time(root_xml): 13 | record_info = root_xml.findall('BililiveRecorderRecordInfo')[0] 14 | record_start_time_str = record_info.attrib['start_time'] 15 | record_start_time = parse(record_start_time_str) 16 | return record_start_time 17 | 18 | 19 | def add_root(orig_root, new_root, new_offset): 20 | for child in new_root: 21 | if child.tag in ['sc', 'gift', 'guard']: 22 | orig_time = float(child.attrib['ts']) 23 | new_time = orig_time + new_offset 24 | new_time_str = str(new_time) 25 | child.set('ts', new_time_str) 26 | orig_root.append(child) 27 | if child.tag in ['d']: 28 | orig_parameters_str = child.attrib['p'].split(',') 29 | orig_time = float(orig_parameters_str[0]) 30 | new_time = orig_time + new_offset 31 | new_parameters_str = [str(new_time)] + orig_parameters_str[1:] 32 | child.set('p', ','.join(new_parameters_str)) 33 | orig_root.append(child) 34 | 35 | 36 | if __name__ == '__main__': 37 | args = parser.parse_args() 38 | 39 | if len(args.xml_files) == 0: 40 | print("At least one XML files have to be passed as input.") 41 | 42 | tree = ET.parse(args.xml_files[0]) 43 | root = tree.getroot() 44 | new_root_offset = 0 45 | root_time = get_root_time(root) 46 | all_flv = "" 47 | 48 | for i in range(len(args.xml_files) - 1): 49 | new_root = ET.parse(args.xml_files[i + 1]).getroot() 50 | if args.video_time == "": 51 | new_root_offset = (get_root_time(new_root) - root_time).total_seconds() 52 | else: 53 | prev_xml_path = args.xml_files[i] 54 | base_file_path = prev_xml_path.rpartition('.')[0] 55 | flv_file_path = base_file_path + args.video_time 56 | total_seconds_str = subprocess.check_output( 57 | f'ffprobe -v error -show_entries format=duration ' 58 | f'-of default=noprint_wrappers=1:nokey=1 "{flv_file_path}"', shell=True 59 | ) 60 | all_flv += flv_file_path + "\n" 61 | new_root_offset += float(total_seconds_str) 62 | add_root(root, new_root, new_root_offset) 63 | 64 | tree.write(args.output, encoding='UTF-8', xml_declaration=True) 65 | -------------------------------------------------------------------------------- /src/danmaku_tools/analyze_danmaku.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import argparse 4 | import json 5 | 6 | from danmaku_tools.danmaku_tools import read_danmaku_file, get_value 7 | 8 | parser = argparse.ArgumentParser(description='Get gift analytics for BiliBili Live XML') 9 | parser.add_argument('danmaku', type=str, help='path to the danmaku file') 10 | # parser.add_argument('--graph', type=str, default=None, help='output graph path, leave empty if not needed') 11 | # parser.add_argument('--he_map', type=str, default=None, help='output high density timestamp, leave empty if not needed') 12 | # parser.add_argument('--sc_list', type=str, default=None, help='output super chats, leave empty if not needed') 13 | 14 | 15 | if __name__ == '__main__': 16 | args = parser.parse_args() 17 | xml_list = read_danmaku_file(args.danmaku, guard=True) 18 | total_d = 0 19 | total_sc = 0 20 | total_gift = 0 21 | total_guard = 0 22 | guard_map = {} 23 | 24 | for item in xml_list: 25 | if item.tag == 'd': 26 | total_d += 1 27 | elif item.tag == 'sc': 28 | total_sc += get_value(item) * 10 29 | elif item.tag == 'gift': 30 | total_gift += get_value(item) * 10 31 | elif item.tag == 'guard': 32 | total_guard += get_value(item) * 10 33 | raw_data = json.loads(item.attrib['raw']) 34 | gift_name = raw_data["gift_name"] 35 | if gift_name in guard_map: 36 | guard_map[gift_name] += 1 37 | else: 38 | guard_map[gift_name] = 1 39 | 40 | print(f"弹幕:{total_d}条") 41 | print(f"醒目留言:{total_sc}元") 42 | print(f"礼物:{total_gift}元") 43 | print(f"大航海:{total_guard}元") 44 | print(f"大航海类别:{guard_map}") 45 | print(f"总流水 {total_gift + total_guard + total_sc}元") 46 | 47 | 48 | 49 | # if args.graph is not None: 50 | # heat_time, heat_value_gaussian, heat_value_gaussian2, he_points = get_heat_time(xml_list) 51 | # 52 | # fig = plt.figure(figsize=(heat_time[0][-1] / 1000, 4)) 53 | # 54 | # draw_he_line(fig.gca(), heat_time, heat_value_gaussian, heat_value_gaussian2) 55 | # 56 | # for name, name_chn in {'d': "danmaku", 'sc': "superchat", 'gift': "gift", 'guard': 'guard'}.items(): 57 | # part_xml_list = [element for element in xml_list if element.tag == name] 58 | # heat_time, heat_value_gaussian, heat_value_gaussian2, _ = get_heat_time(part_xml_list) 59 | # if name in ['sc', 'gift']: 60 | # draw_he_line(fig.gca(), heat_time, heat_value_gaussian * 10, heat_value_gaussian2 * 10, name=name_chn) 61 | # 62 | # part_xml_list = [element for element in xml_list if element.tag in ['sc', 'gift']] 63 | # heat_time, heat_value_gaussian, heat_value_gaussian2, he_points = get_heat_time(part_xml_list) 64 | # draw_he_annotate(fig.gca(), heat_time, he_points) 65 | # 66 | # t_x = heat_time[0][::1000] 67 | # 68 | # t = [convert_time(time) for time in t_x] 69 | # 70 | # plt.xticks(t_x, t) 71 | # 72 | # plt.legend() 73 | # 74 | # plt.savefig(args.graph) 75 | -------------------------------------------------------------------------------- /src/danmaku_tools/danmaku_energy_map.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import argparse 4 | import json 5 | import traceback 6 | import random 7 | from datetime import timedelta 8 | 9 | import srt 10 | import xml.etree.ElementTree as ET 11 | from collections import deque 12 | 13 | import matplotlib.pyplot as plt 14 | import numpy as np 15 | from scipy.ndimage.filters import convolve 16 | from scipy.stats import halfnorm 17 | 18 | from danmaku_tools.danmaku_tools import read_danmaku_file, get_value, get_time 19 | 20 | from textrank4zh import TextRank4Sentence 21 | from tqdm import tqdm 22 | 23 | parser = argparse.ArgumentParser(description='Process bilibili Danmaku') 24 | parser.add_argument('danmaku', type=str, help='path to the danmaku file') 25 | parser.add_argument('--graph', type=str, default=None, help='output graph path, leave empty if not needed') 26 | parser.add_argument('--he_map', type=str, default=None, help='output high density timestamp, leave empty if not needed') 27 | parser.add_argument('--sc_list', type=str, default=None, help='output super chats, leave empty if not needed') 28 | parser.add_argument('--sc_srt', type=str, default=None, help='output super chats srt, leave empty if not needed') 29 | parser.add_argument('--he_time', type=str, default=None, help='output highest density timestamp, leave empty if not ' 30 | 'needed') 31 | parser.add_argument('--he_range', type=str, default=None, help='output he_range, leave empty if not needed') 32 | parser.add_argument('--user_xml', type=str, default=None, help='output danmaku xml with username, leave empty if not ' 33 | 'needed') 34 | 35 | 36 | def half_gaussian_filter(value, sigma): 37 | space = np.linspace(-4, 4, sigma * 8) 38 | neg_space = np.linspace(4 * 10, -4 * 10, sigma * 8) 39 | kernel = (halfnorm.pdf(space) + halfnorm.pdf(neg_space)) / sigma 40 | offset_value = np.concatenate((value, np.zeros(45))) 41 | return convolve(offset_value, kernel)[45:] 42 | 43 | 44 | def get_heat_time(all_children): 45 | interval = 2 46 | 47 | center = 0 48 | 49 | cur_entry = 0 50 | 51 | final_time = get_time(all_children[-1]) 52 | 53 | cur_heat = 0 54 | 55 | danmaku_queue = deque() 56 | 57 | heat_time = [[], []] 58 | 59 | while True: 60 | if center > final_time: 61 | break 62 | 63 | start = center - interval 64 | end = center + interval 65 | 66 | while cur_entry < len(all_children) and get_time(all_children[cur_entry]) < end: 67 | cur_danmaku = all_children[cur_entry] 68 | danmaku_queue.append(cur_danmaku) 69 | cur_heat += get_value(cur_danmaku) 70 | cur_entry += 1 71 | 72 | while len(danmaku_queue) != 0 and get_time(danmaku_queue[0]) < start: 73 | prev_danmaku = danmaku_queue.popleft() 74 | cur_heat -= get_value(prev_danmaku) 75 | 76 | heat_time[0] += [center] 77 | heat_time[1] += [cur_heat] 78 | center += 1 79 | 80 | heat_value = heat_time[1] 81 | heat_value_gaussian = half_gaussian_filter(heat_value, sigma=50) 82 | heat_value_gaussian2 = half_gaussian_filter(heat_value, sigma=1000) * 1.2 83 | 84 | he_points = [[], []] 85 | cur_highest = -1 86 | highest_idx = -1 87 | he_start = -1 88 | he_range = [] 89 | 90 | for i in range(len(heat_value_gaussian)): 91 | if highest_idx != -1: 92 | assert he_start != -1 93 | if heat_value_gaussian[i] < heat_value_gaussian2[i]: 94 | he_points[0] += [highest_idx] 95 | he_points[1] += [cur_highest] 96 | he_range += [(he_start, i)] 97 | highest_idx = -1 98 | he_start = -1 99 | else: 100 | if heat_value_gaussian[i] > cur_highest: 101 | cur_highest = heat_value_gaussian[i] 102 | highest_idx = i 103 | else: 104 | assert he_start == -1 105 | if heat_value_gaussian[i] > heat_value_gaussian2[i]: 106 | cur_highest = heat_value_gaussian[i] 107 | highest_idx = i 108 | he_start = i 109 | 110 | # Usually the HE point at the end of a live stream is just to say goodbye 111 | # if highest_idx != -1: 112 | # he_points[0] += [highest_idx] 113 | # he_points[1] += [cur_highest] 114 | 115 | return heat_time, heat_value_gaussian / np.sqrt(heat_value_gaussian2), np.sqrt( 116 | heat_value_gaussian2), he_points, he_range 117 | 118 | 119 | def convert_time(secs): 120 | minutes = secs // 60 121 | reminder_secs = secs % 60 122 | return f"{minutes}:{reminder_secs:02d}" 123 | 124 | 125 | def draw_he_line(ax: plt.Axes, heat_time, heat_value_gaussian, heat_value_gaussian2, name='all', no_average=False): 126 | ax.plot(heat_time[0], heat_value_gaussian, label=f"{name}") 127 | if not no_average: 128 | ax.plot(heat_time[0], heat_value_gaussian2, label=f"{name} average") 129 | 130 | 131 | def draw_he_area(ax: plt.Axes, current_time: float, heat_time, heat_value_gaussian, heat_value_gaussian2, name='all', 132 | no_average=False): 133 | total_len = len(heat_time[0]) 134 | change_pos_list = [0] 135 | low_area_begin_pos_list = [] 136 | high_area_begin_pos_list = [] 137 | if heat_value_gaussian[0] - heat_value_gaussian2[0] < 0: 138 | low_area_begin_pos_list.append(0) 139 | else: 140 | high_area_begin_pos_list.append(0) 141 | for i in range(1, total_len - 1): 142 | prev_diff = heat_value_gaussian[i - 1] - heat_value_gaussian2[i - 1] 143 | after_diff = heat_value_gaussian[i + 1] - heat_value_gaussian2[i + 1] 144 | if prev_diff * after_diff < 0: 145 | change_pos_list.append(i) 146 | if prev_diff < 0: 147 | high_area_begin_pos_list.append(len(change_pos_list) - 1) 148 | else: 149 | low_area_begin_pos_list.append(len(change_pos_list) - 1) 150 | change_pos_list.append(total_len - 1) 151 | 152 | for begin_pos_i in low_area_begin_pos_list: 153 | begin_pos = change_pos_list[begin_pos_i] 154 | end_pos = change_pos_list[begin_pos_i + 1] 155 | if end_pos < total_len - 1: 156 | end_pos += 1 157 | if current_time <= begin_pos: 158 | ax.fill_between(heat_time[0][begin_pos:end_pos], heat_value_gaussian[begin_pos:end_pos], color="#f0e442c0", 159 | edgecolor="none") 160 | elif current_time > end_pos: 161 | ax.fill_between(heat_time[0][begin_pos:end_pos], heat_value_gaussian[begin_pos:end_pos], color="#999999c0", 162 | edgecolor="none") 163 | else: 164 | ax.fill_between(heat_time[0][begin_pos:current_time], heat_value_gaussian[begin_pos:current_time], 165 | color="#999999c0", edgecolor="none") 166 | ax.fill_between(heat_time[0][current_time:end_pos], heat_value_gaussian[current_time:end_pos], 167 | color="#f0e442c0", edgecolor="none") 168 | if not no_average: 169 | for begin_pos_i in high_area_begin_pos_list: 170 | begin_pos = change_pos_list[begin_pos_i] 171 | end_pos = change_pos_list[begin_pos_i + 1] 172 | if end_pos < total_len - 1: 173 | end_pos += 1 174 | if current_time <= begin_pos: 175 | ax.fill_between(heat_time[0][begin_pos:end_pos], heat_value_gaussian[begin_pos:end_pos], 176 | color="#e69f00c0", edgecolor="none") 177 | elif current_time > end_pos: 178 | ax.fill_between(heat_time[0][begin_pos:end_pos], heat_value_gaussian[begin_pos:end_pos], 179 | color="#737373c0", edgecolor="none") 180 | else: 181 | ax.fill_between(heat_time[0][begin_pos:current_time], heat_value_gaussian[begin_pos:current_time], 182 | color="#737373c0", edgecolor="none") 183 | ax.fill_between(heat_time[0][current_time:end_pos], heat_value_gaussian[current_time:end_pos], 184 | color="#e69f00c0", edgecolor="none") 185 | 186 | 187 | def draw_he_annotate(ax: plt.Axes, heat_time, he_points): 188 | for i in range(len(he_points[0])): 189 | time = heat_time[0][he_points[0][i]] 190 | time_name = convert_time(time) 191 | height = he_points[1][i] 192 | ax.annotate(time_name, xy=(time, height), xytext=(time, height + 5), 193 | arrowprops=dict(facecolor='black', shrink=0.05)) 194 | 195 | 196 | def draw_he_annotate_line(ax: plt.Axes, current_time: float, heat_time, he_points): 197 | for i in range(len(he_points[0])): 198 | time = heat_time[0][he_points[0][i]] 199 | height = he_points[1][i] 200 | ax.axline((time, height), (time, height - 1), color='#cc79a7c0') 201 | 202 | 203 | def draw_he(he_graph, heat_time, heat_value_gaussian, heat_value_gaussian2, he_points, he_range, current_time=-1): 204 | fig = plt.figure(figsize=(16, 1), frameon=False, dpi=60) 205 | ax = fig.add_axes((0, 0, 1, 1)) 206 | draw_he_area(ax, current_time, heat_time, heat_value_gaussian, heat_value_gaussian2) 207 | # draw_he_annotate_line(ax, current_time, heat_time, he_points) 208 | plt.xlim(heat_time[0][0], heat_time[0][-1]) 209 | plt.ylim(min(heat_value_gaussian), max(heat_value_gaussian)) 210 | 211 | plt.box(False) 212 | plt.savefig(he_graph, transparent=True) 213 | 214 | 215 | TEXT_LIMIT = 900 216 | SEG_CHAR = '\n\n\n\n' 217 | 218 | 219 | def segment_text(text): 220 | lines = text.split('\n') 221 | new_text = "" 222 | new_segment = "" 223 | 224 | for line in lines: 225 | if len(new_segment) + len(line) < TEXT_LIMIT: 226 | new_segment += line + "\n" 227 | else: 228 | if len(line) > TEXT_LIMIT: 229 | print(f"line\"{line}\" too long, omit.") 230 | else: 231 | new_text += new_segment + SEG_CHAR 232 | new_segment = line + "\n" 233 | new_text += new_segment 234 | return new_text 235 | 236 | 237 | def get_danmaku_from_range(all_children, he_range): 238 | start, end = he_range 239 | start += 45 240 | end += 45 241 | return [item.text for item in all_children if item.tag == 'd' and start <= get_time(item) <= end] 242 | 243 | 244 | if __name__ == '__main__': 245 | args = parser.parse_args() 246 | xml_list = read_danmaku_file(args.danmaku) 247 | 248 | if args.sc_list is not None or args.sc_srt is not None: 249 | sc_chats = [element for element in xml_list if element.tag == 'sc'] 250 | 251 | sc_tuple = [] 252 | for sc_chat_element in sc_chats: 253 | try: 254 | price = sc_chat_element.attrib['price'] 255 | message = sc_chat_element.text if sc_chat_element.text is not None else "" 256 | message = message.replace('\n', '\t') 257 | user = sc_chat_element.attrib['user'] 258 | time = float(sc_chat_element.attrib['ts']) 259 | duration = float(sc_chat_element.attrib['time']) 260 | sc_tuple += [(time, price, message, user, duration)] 261 | except: 262 | print(f"superchat processing error {sc_chat_element}") 263 | 264 | if args.sc_list is not None: 265 | if len(sc_tuple) != 0: 266 | sc_text = "醒目留言列表:" 267 | for time, price, message, user, _ in sc_tuple: 268 | sc_text += f"\n {convert_time(int(time))} ¥{price} {user}: {message}" 269 | sc_text += "\n" 270 | sc_text = segment_text(sc_text) 271 | else: 272 | sc_text = "没有醒目留言..." 273 | with open(args.sc_list, "w", encoding='utf8') as file: 274 | file.write(sc_text) 275 | if args.sc_srt is not None: 276 | active_sc = [] 277 | subtitles = [] 278 | cur_time = 0 279 | 280 | 281 | def display_sc(start, end, sc_list): 282 | display_sorted_sc = sorted(sc_list, key=lambda x: (-float(x[0]), -int(x[2]))) 283 | content = "\n".join([sc[3] for sc in display_sorted_sc]) 284 | LIMIT = 100 285 | if len(content) >= LIMIT: 286 | content = content[:LIMIT - 2] + "…" 287 | return srt.Subtitle( 288 | index=0, 289 | start=timedelta(seconds=start), 290 | end=timedelta(seconds=end), 291 | content=content 292 | ) 293 | 294 | 295 | def flush_sc(start_time: float, end_time: float): 296 | current_sc = sorted(active_sc, key=lambda x: x[1]) 297 | subtitle_list = [] 298 | while True: 299 | if len(current_sc) == 0: 300 | break 301 | if current_sc[0][1] < end_time: 302 | if current_sc[0][1] - start_time > 1: 303 | subtitle_list += [display_sc(start_time, current_sc[0][1], current_sc)] 304 | start_time = current_sc[0][1] 305 | else: 306 | break 307 | current_sc.pop(0) 308 | if end_time - start_time > 1: 309 | subtitle_list += [display_sc(start_time, end_time, current_sc)] 310 | start_time = end_time 311 | return current_sc, subtitle_list, start_time 312 | 313 | 314 | for time, price, message, user, duration in sc_tuple: 315 | start = time 316 | end = time + duration * 0.6 317 | content = f"¥{price} {user}: {message}".replace("绑架", "**") 318 | new_sc, new_subtitles, cur_time = flush_sc(start_time=cur_time, 319 | end_time=start) # Flush all the previous SCs 320 | active_sc = new_sc + [(start, end, price, content)] 321 | subtitles += new_subtitles 322 | if len(active_sc): 323 | end_time = max([sc[1] for sc in active_sc]) 324 | _, new_subtitles, _ = flush_sc(start_time=cur_time, end_time=end_time) 325 | subtitles += new_subtitles 326 | with open(args.sc_srt, "w", encoding='utf8') as file: 327 | file.write(srt.compose(subtitles)) 328 | 329 | if args.he_map is not None or args.graph is not None or args.he_time is not None or args.he_range: 330 | heat_values = get_heat_time(xml_list) 331 | 332 | if args.he_range is not None: 333 | with open(args.he_range, "w", encoding='utf8') as file: 334 | json.dump(heat_values[4], file) 335 | 336 | if args.he_map is not None: 337 | he_pairs = heat_values[3] 338 | all_timestamps = heat_values[0][0] 339 | 340 | heat_comments = [] 341 | xml_list_iter = iter(xml_list) 342 | tr4s = TextRank4Sentence() 343 | for start, end in tqdm(heat_values[4]): 344 | comment_list = [] 345 | while True: 346 | try: 347 | element = next(xml_list_iter) 348 | except StopIteration: 349 | break 350 | if get_time(element) <= start + 45: 351 | continue 352 | if get_time(element) > end + 45: 353 | break 354 | if element.tag == 'd': 355 | text = element.text 356 | if text is not None and not text.replace(" ", "").replace("哈", "") == "": 357 | comment_list += [text] 358 | print(len(comment_list)) 359 | if len(comment_list) > 1000: 360 | comment_list = random.sample(comment_list, 1000) 361 | tr4s.analyze("\n".join(comment_list), lower=True, source='no_filter') 362 | key_sentences = tr4s.get_key_sentences(1) 363 | if len(key_sentences) > 0: 364 | top_sentence = key_sentences[0]['sentence'] 365 | else: 366 | top_sentence = "" 367 | heat_comments += [top_sentence] 368 | 369 | if len(he_pairs[0]) == 0: 370 | text = "没有高能..." 371 | else: 372 | # noinspection PyTypeChecker 373 | highest_id = np.argmax(he_pairs[1]) 374 | highest_time_id = he_pairs[0][highest_id] 375 | highest_time = all_timestamps[highest_time_id] 376 | highest_sentence = heat_comments[highest_id] 377 | 378 | other_he_time_list = [all_timestamps[time_id] for time_id in he_pairs[0]] 379 | 380 | text = f"全场最高能:{convert_time(highest_time)}\t{highest_sentence}\n\n其他高能:" 381 | 382 | for i, (start_he_time, end_he_time) in enumerate(heat_values[4]): 383 | text += f"\n {convert_time(start_he_time)} - {convert_time(end_he_time)}\t{heat_comments[i]}" 384 | text += "\n" 385 | text = segment_text(text) 386 | with open(args.he_map, "w", encoding='utf8') as file: 387 | file.write(text) 388 | 389 | if args.he_time is not None: 390 | he_pairs = heat_values[3] 391 | all_timestamps = heat_values[0][0] 392 | if len(he_pairs[0]) == 0: 393 | text = "0" 394 | else: 395 | # noinspection PyTypeChecker 396 | highest_time_id = he_pairs[0][np.argmax(he_pairs[1])] 397 | highest_time = all_timestamps[highest_time_id] 398 | text = str(highest_time) 399 | with open(args.he_time, "w", encoding='utf8') as file: 400 | file.write(text) 401 | 402 | if args.graph is not None: 403 | draw_he(args.graph, *heat_values) 404 | 405 | if args.user_xml is not None: 406 | tree = ET.parse(args.danmaku) 407 | user_cache = {} 408 | 409 | import bilibili_api 410 | 411 | def get_user_follower(user_id): 412 | if user_id in user_cache: 413 | return user_cache[user_id] 414 | else: 415 | user_follower = bilibili_api.user.get_relation_info(user_id)['follower'] 416 | user_cache[user_id] = user_follower 417 | return user_follower 418 | 419 | 420 | for child in tqdm(tree.getroot()): 421 | try: 422 | if child.tag == 'd': 423 | user_name = child.attrib['user'] 424 | raw_data = json.loads(child.attrib['raw']) 425 | user_id = raw_data[2][0] 426 | # follower = get_user_follower(user_id) 427 | follower = 0 428 | user_level = raw_data[3][0] if len(raw_data[3]) > 0 else 0 429 | user_boat = raw_data[7] 430 | display_username = follower >= 1000 or user_level > 25 or user_boat >= 2 431 | if display_username: 432 | print(user_name) 433 | child.text = f"@{user_name}:" + child.text 434 | except Exception as e: 435 | print(e) 436 | print(traceback.format_exc()) 437 | tree.write(args.user_xml, encoding='UTF-8', xml_declaration=True) 438 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 2021 Jackie Yang 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | danmaku_tools Copyright (C) 2021 Jackie Yang 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . --------------------------------------------------------------------------------