KawaiiLab/azusa

多行同时间的LRC在A25无法正常使用

Oyami-Srk opened this issue · 3 comments

例:

[00:00.87]We have always stood on the borderland.
[00:03.33]我们始终踱步于境戒线之上
[00:03.33]I'm enjoying the view from here.
[00:06.17]皆因此境风景独好
[00:06.17]Eeny, meeny, miny, moe…much the same
[00:11.51]一,二,三,四...其实都一样

只会显示第一句相同时间的歌词,以上显示效果如下:

We have always stood on the borderland.
我们始终踱步于境戒线之上
皆因此境风景独好
一,二,三,四...其实都一样

且翻译和原歌词时间不对应

#!python3
import re
import os
import sys

r = re.compile(r'^(\[\d*:\d*\.\d*\])(.*)$')

in_dir = sys.argv[-2]
out_dir = sys.argv[-1]

DEBUG = True


def proc(fn: str, out_dir: str):
    with open(fn, 'r') as f:
        ls = f.readlines()
        lrc = ""
        lines = len(ls)
        i = 0
        tup = []
        while True:
            c = r.findall(ls[i])[0]
            n = r.findall(ls[i + 1])[0]
            if c[0] == n[0]:
                tup.append((i, i + 1))
            i = i + 1
            if i >= lines - 1:
                break
        tn = 0
        i = 0
        if DEBUG:
            print(tup)
        while True:
            if tn < len(tup) and tup[tn][0] == i:
                lrc += r.findall(ls[i])[0][1] + '\n'
            elif tn < len(tup) and tup[tn][1] == i:
                if i == lines - 1:
                    break
                if r.findall(ls[i])[0][1] == '':
                    lrc += '\n'
                else:
                    lrc += ls[i].strip('\n') + ' \\ '
                tn += 1
            else:
                if tn < len(tup) and i + 1 == tup[tn][0]:
                    lrc += ls[i].strip('\n') + ' \\ '
                else:
                    lrc += ls[i]
            i = i + 1
            if i >= lines:
                break

        if not DEBUG:
            with open(out_dir + "/" + os.path.basename(fn), "w") as o:
                o.write(lrc)
        else:
            print(lrc)


if __name__ == "__main__":
    if not DEBUG:
        fs = os.listdir(in_dir)
        for f in fs:
            f = in_dir + '/' + f
            if not os.path.isfile(f):
                continue
            if os.path.splitext(f)[1] != '.lrc':
                continue
            if os.path.getsize(f) == 0:
                continue
            print(f)
            proc(f, out_dir)
    else:
        proc(in_dir + '/' + '722013.lrc', '')

写了一个脚本合并原句和翻译,但是对于一些特殊情况如歌曲ID722013的歌词存在Bug

意识到了在A25这种小屏机器上我看个锤子的歌词

非常抱歉不小心 unwatch 了这个项目导致看不到 issue 提醒

正好使用 Node 重构了一遍,看到 issue 之后就加了这个功能,可以尝试一下