# Python 3.9 import sys def restore_bili_video(video_path): print("Restoring... "+video_path) ext=video_path[video_path.rfind("."):] fin=open(video_path,"rb") if fin.read(1)!=b"\xff": print("This file is not encrypted by bilibili.") fin.close() return fout=open(video_path[:-len(ext)]+"_restore"+ext,"wb") is_video_file=False while True: b=fin.read(4096 if is_video_file else 1) if b==b"": break if not is_video_file and b == b"\xff": continue is_video_file=True fout.write(b) fin.close() fout.close() if len(sys.argv) < 2: print("Usage: "+sys.argv[0]+" [video2] ...") else: for i in range(1,len(sys.argv)): restore_bili_video(sys.argv[i])