Skip to content

Instantly share code, notes, and snippets.

@lxfly2000
Last active October 12, 2023 12:38
Show Gist options
  • Save lxfly2000/52ad1c81b22d81d9f94433d6fedbd3f6 to your computer and use it in GitHub Desktop.
Save lxfly2000/52ad1c81b22d81d9f94433d6fedbd3f6 to your computer and use it in GitHub Desktop.

Revisions

  1. lxfly2000 revised this gist Oct 12, 2023. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions restore_bili_video.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Python 3.9

    import sys

    def restore_bili_video(video_path):
  2. lxfly2000 revised this gist Oct 12, 2023. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions restore_bili_video.py
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,10 @@ 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:
  3. lxfly2000 created this gist Oct 12, 2023.
    24 changes: 24 additions & 0 deletions restore_bili_video.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    import sys

    def restore_bili_video(video_path):
    print("Restoring... "+video_path)
    ext=video_path[video_path.rfind("."):]
    fin=open(video_path,"rb")
    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]+" <video1> [video2] ...")
    else:
    for i in range(1,len(sys.argv)):
    restore_bili_video(sys.argv[i])