Introduction
Station B is very simple for downloading a single video. You can install plug-ins in the browser, which will not be covered here. This paper mainly introduces the batch download and resource integration of multi-P video.
There are two ways:
- Execute py script
- Run exe tool
preparation
1. Download B station client in windows store
2. Install ffmpeg software, add path environment variable, download address: https://ffmpeg.zeranoe.com/builds/ . Add environment variable method here is no longer specific introduction, do not understand Baidu.
3.pip Install ffmpy3 module (not required with exe tool)
Video download
Open the client, you can set the download path by yourself, support multiple sets of batch downloads, and the download format supports MP4 and flv formats
But the downloaded cache files have problems with each format, which is why this tool is produced.
1. The MP4 format of files downloaded in batch is audio and video segmentation;
2.flv The long format video is divided into several short videos;
3. Video file name is digital string code
Downloaded files
Function introduction
1. Rename the downloaded MP4 format file for voice and video synthesis. It takes a long time to process. It eats cpu and memory. Downloading this format is not recommended
2. Splice and rename the downloaded flv format file
Access method
1. Script source file
Video processing script of station B1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 """ 4 This script is used for batch processing Windows Shop B Station client downloads the file. 5 explain: 6 1.Files downloaded in bulk MP4 The format is audio video segmentation; 7 2.flv The long format video is divided into several short videos; 8 3.Video file name is digital string code 9 Environmental preparation: 10 1. download ffmpeg Software and load environment variables, download address: https://ffmpeg.zeranoe.com/builds/ 11 2. pip install ffmpy3 modular 12 Function: 13 1. For downloaded MP4 Format file voice, video synthesis, rename. Processing time is long, downloading this format is not recommended 14 2. For downloaded flv Splicing and renaming of format files 15 """ 16 import json, os, datetime 17 from ffmpy3 import FFmpeg 18 19 # Source video download path 20 source_dir = str(input("Please enter the video source folder:")) 21 # Output path of processed video, and create a new video title folder 22 target_dir = str(input("Please enter the output folder:")) 23 24 25 def file_handler(root, files): 26 output_dir = "" 27 audio_path = "" 28 video_path = "" 29 flv_list = [] 30 31 for file in files: 32 33 if file.endswith(".info"): 34 file_name, dir_name = get_video_info(root, file) 35 save_dir = os.path.join(target_dir, dir_name) 36 if not os.path.exists(save_dir): 37 os.mkdir(save_dir) 38 output_dir = os.path.join(save_dir, file_name) 39 40 if file.startswith("audio"): 41 audio_path = os.path.join(root, file) 42 if file.startswith("video"): 43 video_path = os.path.join(root, file) 44 if file.endswith(".flv"): 45 flv_list.append(os.path.join(root, file)) 46 return output_dir, audio_path, video_path, flv_list 47 48 49 def get_video_info(root, file): 50 json_dir = os.path.join(root, file) 51 with open(json_dir, "r", encoding="utf-8")as f: 52 info_dic = json.load(f) 53 file_name = info_dic['PartName'] 54 file_name = file_name.replace(" ", "") 55 dir_name = info_dic['Title'] 56 return file_name, dir_name 57 58 59 def mp4_handler(video_path, audio_path, output_dir): 60 ff = FFmpeg(inputs={str(video_path): None, str(audio_path): None}, 61 outputs={str(output_dir + '.mp4'): '-c:v h264 -c:a ac3 -v quiet -y'}) 62 # print(ff.cmd) 63 ff.run() 64 65 66 def creat_flv_list_file(root, flv_list): 67 flv_list_dir = os.path.join(root, "flv_list.txt") 68 with open(flv_list_dir, 'a', encoding='utf-8')as f: 69 for i in flv_list: 70 f.write("file '{}'\n".format(i)) 71 return flv_list_dir 72 73 74 def flv_concat(flv_list_dir, output_dir): 75 # No safe Parameter error,-v quiet Processing is not displayed,-y Overwrite already exists 76 ff = FFmpeg(global_options="-f concat -safe 0 ", inputs={str(flv_list_dir): None}, 77 outputs={output_dir + '.flv': "-c copy -v quiet -y"}) 78 # print(ff.cmd) 79 ff.run() 80 81 82 def flv_handler(root, flv_list, output_dir): 83 flv_list_dir = creat_flv_list_file(root, flv_list) 84 flv_concat(flv_list_dir, output_dir) 85 if os.path.exists(flv_list_dir): 86 os.remove(flv_list_dir) 87 88 89 if __name__ == '__main__': 90 start = datetime.datetime.now() 91 total = 0 92 count = 0 93 94 for root, dirs, files in os.walk(source_dir): 95 runtime = datetime.datetime.now() - start 96 if not total: 97 total = len(dirs) 98 print("\r Processing: No{}individual " 99 "Total:{}individual " 100 "Time used:{}".format(count, total, runtime), end='') 101 count += 1 102 103 is_video = file_handler(root, files) 104 if is_video: 105 output_dir, audio_path, video_path, flv_list = is_video 106 if video_path and audio_path and output_dir: 107 mp4_handler(video_path, audio_path, output_dir) 108 if output_dir and flv_list: 109 # print(flv_list) 110 flv_handler(root, flv_list, output_dir) 111 print("\n All processing completed!")