[Python] 纯文本查看 复制代码 import os
from time import sleep
def call_N_m3u8(m3u8url,videoname = '',key = '',path = './Downlodas'):
videoname = videoname.replace('/','.').replace('\\','.').replace(':','.').replace('*','.').replace('?','.').replace('<','.').replace('>','.').replace('|','.')
if videoname == '':
videoname = m3u8url.split('/')[-1]
with open('temp.bat','w',encoding='utf-8') as f:
f.write('@echo off\n::Created by N_m3u8DL-CLI-SimpleG\nchcp 65001 >nul\n')
f.write(f'TITLE {videoname}\n')
f.write(f'N_m3u8DL-CLI_v2.9.3.exe "{m3u8url}" --workDir "{path}" --saveName "{videoname}" --useKeyBase64 "{key}" --enableDelAfterDone\n')
f.write('cmd')
# name = datetime.now().strftime('%Y-%m-%d %H.%M.%S')
cmd = 'start temp.bat'
os.system(cmd)
while os.path.exists(f'{path}/{videoname}.mp4') == False:
sleep(0.5)
print(videoname, '下载完成!')
通过@细水流长 提供的代码,能够成功下载,但是下载之后执行不了“--enableDelAfterDone”,导致很多下载ts文件夹需要手动删除,并且cmd窗口需要手动关闭。
求解决方法 |