[toy] obtain the audio clip of station B video

The thing is, I have a little hobby that is not consistent with the social status of social animals - listening to musicals.

Basically, I click to open the video on station B. I don't want to listen to music on Netease cloud or QQ, but on these music software, I either charge for the clips I want to listen to, or the version is not what I like, or I can't find them at all.

Moreover, in a musical, there are always some clips I like very much, but some clips are not very interested. If you listen to it on station B, you always have to listen to these uninterested places, which is very inefficient.

Then just make a gadget! Put it on the server, call it directly with the interface, and then return the processed audio file. In this way, you don't have to download the whole video locally and cut it manually, which is fast and elegant~

As a senior developer for Baidu / github development, this demand is not difficult for me. I soon found a simple and easy-to-use video download tool for station B. the address is here: https://github.com/nilaoda/BBDown (thanks to BBDown, the developer of the library, for his boundless merit in benefiting the people)

Then write a small script to call the BBDown tool for video download:

#! /bin/sh

#usage method
#. / bilicut.sh bv No. start time end time output file name P option (optional)
#For example:
#. / bilicut.sh BV1uz4y1S7oG 00:00:20 00:00:30 les miserables 0301 3
# Parameter description
# 1: bv number
# 2: Start time
# 3: End time
# 4: Output file name
# 5: Sub P index

#Description of environmental requirements:
#This script uses the BBDown download tool and needs to be placed in the same directory as the BBDown execution file
#Bbdown portal: https://github.com/nilaoda/BBDown
#FFmpeg environment needs to be installed in advance. See https://blog.csdn.net/weixin_36155936/article/details/116988522
#Audio only option -- audio only

if [ ! -d "/root/download" ]; then
	mkdir /root/download
if [ ! -d "/root/output" ]; then
	mkdir /root/output


echo "Downloading..."
if [ $5 > 0 ] ; then
	echo "branch P choice: P${5}"
	#Determine whether there is already a cache file
	if [ ! -d "/root/download/${1}" ]; then
		mkdir /root/download/$1
	if [ ! -d "/root/download/${1}/P${5}" ]; then
		mkdir /root/download/$1/P$5
		results=`./BBDown ${biliUrl}${1} -p ${5} --work-dir /root/download/${1}/P${5} --audio-only`
	#echo "there is no sub-P option"
	#Determine whether there is already a cache file
	if [ ! -d "/root/download/${1}" ]; then
		mkdir /root/download/$1
		results=`./BBDown ${1} --work-dir /root/download/${4} --audio-only`
if [ $downloadFlag -eq 0 ] ; then
	echo "Using cache files"
	echo "Download complete"	

files=$(ls $path)
echo "The document title is ${files}"
echo "Slice time interval ${2} - ${3}"
echo "Start processing......"
ffmpeg -ss $2 -i "${path}/${files}" -c copy -t $3 "/root/output/${4}.mp4" -loglevel quiet
ffmpeg -i "/root/output/${4}.mp4" -vn -codec copy "/root/output/${4}".m4a -loglevel quiet
echo "Processing complete output file /root/output/${4}.m4a"

(uploaded to GitHub, available for Windows: https://github.com/heng4719/BBCut)

At the end of the script, you can also see that ffmpeg is used to clip and format convert the video, and finally output the audio file to the / root/output / directory.


In fact, the main functions have been completed. Call this script to pass in the specified video bv number and other parameters, and the requirements can be perfectly realized.

But not elegant enough!

Do I have to connect to the server to write commands manually every time I want to cut the video?

Not elegant!

So I wrote a front-end page to call:

So far, you can download the video and music clips you want anytime and anywhere, elegant~

Posted by MannyG on Fri, 03 Dec 2021 11:29:44 -0800