Tag Archives: bilibili

The bilibilibili cache video cache batch converted to MP4 format Python code

It is recommended to use virtual machine or Android mobile phone to download the cache

After the conversion, play more free, I hope to help you

Default cache location: Android – Data – ta.danmaku.bili – Download

How to use: put the script in the same directory as the cache, input the file name after execution, and then convert instantly

Only tested Mac, win should be universal, no test

Before conversion – after conversion:

import os, shutil #Import the required more reports
work_dir = os.getcwd() #Get the working directory


def main():
    old_dir = input("Enter the name of the directory to process") # Prompt for a filename similar to : 34387218
    new_dir = old_dir+"_MP4" # Enter the name of the file to be stored
    if(os.path.exists(new_dir)): # determine if it exists, if so delete and rebuild
        print(new_dir+"already exists, already rebuilt")
        shutil.rmtree(new_dir) 
        os.mkdir(new_dir)
    else:
        print(new_dir+"Created successfully")
        os.mkdir(new_dir)

    for i in os.listdir(os.path.join(work_dir, old_dir)): # Loop through
        if(i == ".DS_Store"): # Skip the file created by Apple by default
            continue
        for o in os.listdir(os.path.join(work_dir, old_dir, i)): # Start loop inside
            if(o == ".DS_Store"): # Skip files created by Apple by default
                continue
            if(os.path.isdir(os.path.join(work_dir, old_dir, i, o))): # Enter second level loop
                for p in os.listdir(os.path.join(work_dir, old_dir, i, o)): # Start the operation loop
                    if(o == ".DS_Store"): # Skip the file created by Apple by default
                        continue
                    file_name = os.path.basename(p) # Get the name of the file
                    if file_name.endswith(".blv"): # Determine if the name format is correct
                        f_file_name = file_name.split('.') # Split the file name
                        index = int(f_file_name[0]) + 1
                        old_file = os.path.join(work_dir, old_dir, i, o, p) # Get the old file
                        shutil.move(old_file,new_dir) # move the file
                        new_file = str(i)+"_"+str(index)+".mp4" # customize the new file name
                        os.rename(os.path.join(work_dir, new_dir,file_name), os.path.join(work_dir, new_dir, new_file)) # Perform rename
                    
                        
if __name__ == "__main__":
    main()