m13253 / danmaku2ass

Convert comments from Niconico/AcFun/bilibili to ASS format
http://m13253.blogspot.com/2013/11/play-danmaku-offline-danmaku2ass.html
GNU General Public License v3.0
556 stars 92 forks source link

无法判断带有BOM的弹幕文件的站点来源信息 #24

Closed chenxuuu closed 8 years ago

chenxuuu commented 8 years ago

信息: F:\Desktop\danmaku2ass-master>python danmaku2ass.py -o 1.ass -s 640x480 -fn "MS PGothic" -fs 48 -a 0.8 -dm 5 -ds 5 1.xml Traceback (most recent call last): File "danmaku2ass.py", line 845, in main() File "danmaku2ass.py", line 841, in main Danmaku2ASS(args.file, args.output, width, height, args.protect, args.font, args.fontsize, args.alpha, args.duration_marquee, args.duration_still, args.redu ce) File "danmaku2ass.py", line 779, in Danmaku2ASS comments = ReadComments(input_files, fontsize) File "danmaku2ass.py", line 806, in ReadComments raise ValueError(('Unknown comment file format: %s') % i) ValueError: Unknown comment file format: 1.xml

F:\Desktop\danmaku2ass-master>pause 请按任意键继续. . .

然后发现不支持utf8有BOM格式。。

m13253 commented 8 years ago

嗯。谢谢你的汇报。 因为从B站下载的XML都是没有BOM的,所以我就懒得写BOM检测了。 最近我比较忙,如果你有时间解决这个问题,那么我欢迎你提交 Pull Request。

alexvong243f commented 8 years ago

@chenxuuu Could you please upload the file with BOM format? So that I can try fixing it. Or are you preferred to fix it yourself?

chenxuuu commented 8 years ago

可能是因为弹幕文件比较早吧。。。(有人收集的合集)另外有些老弹幕格式也有些不兼容, 比如 链接:http://pan.baidu.com/s/1jGLaGYy 密码:dniu 有bom头的文件样本:链接:http://pan.baidu.com/s/1pJ07HSR 密码:ihvt 我用的批量去bom头软件:链接:http://pan.baidu.com/s/1sjrGklZ 密码:v9wo

chenxuuu commented 8 years ago

抱歉我不怎么会Python→_→

↑ 当我没说→_→

m13253 commented 8 years ago

我用的批量去bom头软件:链接:http://pan.baidu.com/s/1sjrGklZ 密码:v9wo

fin = open("input.xml", "r", "utf-8-bom")
fout = open("output.xml", "w", "utf-8")
fout.write(fin.read())
fin.close()
fout.close()

这是一个去 BOM 的 Python 代码。

另外如果你需要使用 Danmaku2ASS 播放 B 站现在还能观看的视频,可以使用 BiliDan 封装好了下载、转换、播放功能。调用的是 mpv 播放器。

Windows 下安装 mpv 播放器需要一点点动手能力。效果如图。 可惜我的 Windows 虚拟机卸载了,所以没办法给你提供懒人包了。 截图.jpg

chenxuuu commented 8 years ago

@m13253 我刚提交了个Pull Request。。。另外我电脑上用的是bililocal→_→

m13253 commented 8 years ago

@m13253 我刚提交了个Pull Request。。。另外我电脑上用的是bililocal→_→

我回复了 #25 了。请查看。

如果是要下载B站视频用来收藏,尤其是版权视频或者有限制的视频,可以试试看 @cnBeining 的 Biligrab ,有各种黑科技,偶尔能下载到比B站直接观看更高清的视频。还能自动调用 Danmaku2ASS 来生成字幕。

m13253 commented 8 years ago

大概说一下问题的来源:

ProbeCommentFormat 这个函数会读取文件的开头几个字符(越少越好),来猜测这个文件是从哪个网站上下载下来的。因为B站官方下载的 XML 弹幕文件开头几个字符的排版格式是不变的,所以这么判断一直没出过什么问题。 然而你从网络上下载的这些弹幕文件,是经过后期处理的,所以排版可能发生了改变,也可能加入了 BOM 头。这个函数就挂了。 然后程序会根据 ProbeCommentFormat 的结果来调用对应的函数处理各个不同网站的字幕。

这个问题影响比较大: #8 #9 #15 #24 都是这个问题影响的。 我的想法是,能不能加一个启动参数,让用户决定强行让 Danmaku2ASS 以B站(或者其他站点)的模式来处理弹幕,绕过 ProbeCommentFormat 的 bug? 你觉得这个解决方案如何?可惜我已经没有时间和精力了。 :joy:

chenxuuu commented 8 years ago

@m13253 泥垢,这代码我都是拼来的 我哪会Python→_→

m13253 commented 8 years ago

@m13253 泥垢,这代码我都是拼来的 我哪会Python→_→

嗯。好吧。等我放假就动手改一下吧。 现在你先用你自己改的那个版本顶着。 我们学院一门挂科就直接退学,不敢怠慢。 :new_moon_with_face:

m13253 commented 8 years ago

当年的代码太乱我也不知道怎么修了。

试试把 829 行:

            CommentProcessor = GetCommentProcessor(f)

末尾加个 or 'Bilibili',改成:

            CommentProcessor = GetCommentProcessor(f) or 'Bilibili'

看看,这样识别不出来的文件就统统当 Bilibili 格式处理。

这改法太猎奇我不敢推源里(笑)