File size: 1,350 Bytes
da6e788 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
from toolbox import update_ui, get_conf, promote_file_to_downloadzone, update_ui_lastest_msg, generate_file_link
def download_bilibili(video_id, only_audio, user_name, chatbot, history):
# run : docker run --rm -v $(pwd)/downloads:/downloads bbdown BV1LSSHYXEtv --use-app-api --work-dir /downloads
import os
import subprocess
from toolbox import get_log_folder
download_folder_rel = get_log_folder(user=user_name, plugin_name="shared")
download_folder = os.path.abspath(download_folder_rel)
# Get list of existing files before download
existing_file_before_download = list(os.listdir(download_folder))
# Construct the docker command
cmd = [
'docker', 'run', '--rm',
'-v', f'{download_folder}:/downloads',
'bbdown',
video_id,
'--use-app-api',
'--work-dir', '/downloads'
]
if only_audio:
cmd.append('--audio-only')
# Execute the command
result = subprocess.run(cmd, check=True, capture_output=True, text=True)
# print(f"Successfully downloaded video {video_id}")
existing_file_after_download = list(os.listdir(download_folder))
# get the difference
downloaded_files = [os.path.join(download_folder_rel, f) for f in existing_file_after_download if f not in existing_file_before_download]
return downloaded_files
|