File size: 3,215 Bytes
65effbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
"""把新下载的 B 站素材出处追加到 D:\\SFDP-Viedo\\训练素材清单.txt(去重,可反复运行)。"""
import json
import os

ROOT = r"D:\SFDP-Viedo"
META = os.path.join(ROOT, "音乐MV", "sources_bili.json")
TXT = os.path.join(ROOT, "训练素材清单.txt")
MARK = os.path.join(ROOT, ".listed_bvids.json")
EXTRA_DIRS = [os.path.join(ROOT, "二次元MV"), os.path.join(ROOT, "真人MV")]
VIDEO_EXT = (".mp4", ".mkv", ".webm", ".mov", ".flv")


def load(p, d):
    try:
        with open(p, "r", encoding="utf-8") as f:
            return json.load(f)
    except Exception:
        return d


HEADER = """训练数据声明
----------------
本模型在训练过程中未分发、未再发布任何原始视频、音频或视频帧。训练仅使用从公开网络
获取的视频中抽取的灰度切片,且全部监督信号由 Easy4K 自研的 SFDP 四阶判重判决器
(像素差 / dHash / QR 码 / Farneback 光流)自动生成,不含人工标注。
视频著作权归原作者所有。本清单仅用于说明数据来源,不构成对原作品的授权或再分发。
若权利人认为其作品不应被用于本研究,请提交 issue,我们将在 72 小时内从清单中移除,
并在后续版本训练中排除该来源。
模型权重以 CC BY-NC 4.0 发布,仅限研究与非商业用途。

"""


def ensure_header():
    old = ""
    if os.path.exists(TXT):
        with open(TXT, "r", encoding="utf-8") as f:
            old = f.read()
    if "训练数据声明" in old:
        return
    with open(TXT, "w", encoding="utf-8") as f:
        f.write(HEADER + old)


ensure_header()

listed = set(load(MARK, []))
meta = load(META, [])
new = [m for m in meta if m.get("bvid") and m["bvid"] not in listed]
if new:
    with open(TXT, "a", encoding="utf-8") as f:
        f.write("\n== 新增 B 站素材(自动采集,出处可溯) ==\n")
        for i, m in enumerate(new, 1):
            f.write("%3d. %s\n" % (i, m.get("file") or m["bvid"]))
            f.write("     标题:%s\n" % m.get("title", ""))
            f.write("     作者:%s | 时长:%ss | 清晰度:%s | 切片:待统计\n" % (
                m.get("author", ""), m.get("duration", ""), m.get("qn", "")))
            f.write("     来源:https://www.bilibili.com/video/%s\n" % m["bvid"])
    listed |= {m["bvid"] for m in new}
    with open(MARK, "w", encoding="utf-8") as f:
        json.dump(sorted(listed), f, ensure_ascii=False)
    print("APPENDED", len(new), "entries", flush=True)

for d in EXTRA_DIRS:
    if not os.path.isdir(d):
        continue
    changed = False
    for n in sorted(os.listdir(d)):
        if os.path.splitext(n)[1].lower() not in VIDEO_EXT:
            continue
        key = "manual:" + os.path.basename(d) + "/" + n
        if key in listed:
            continue
        with open(TXT, "a", encoding="utf-8") as f:
            f.write("\n[手动素材] %s\\%s\n     来源:用户投放(待补充出处)\n" % (os.path.basename(d), n))
        listed.add(key)
        changed = True
    if changed:
        with open(MARK, "w", encoding="utf-8") as f:
            json.dump(sorted(listed), f, ensure_ascii=False)