|
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): |
|
|
|
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) |
|
|
|
|
|
existing_file_before_download = list(os.listdir(download_folder)) |
|
|
|
|
|
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') |
|
|
|
|
|
|
|
result = subprocess.run(cmd, check=True, capture_output=True, text=True) |
|
|
|
existing_file_after_download = list(os.listdir(download_folder)) |
|
|
|
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 |
|
|
|
|