@classmethod
def download_animate_simple_example(cls, url, ep, j):
"""
這是一個下載動漫簡單範例,肯定會發生請求錯誤,請自己修改邏輯判斷。
:return:
"""
# 取得白色相簿2的基本資訊。
animate_info = cls.animate_total_info(url=url)
ep = ep-1
# 我要下載第一集,所以先拿出第一集的資料。
episode1_info = animate_info['video'][ep]
# 拿 vpx 資料。
vpx_json = cls.get_vpx_json(url=episode1_info['url'])
# 整理 host 順序,我個人猜測 weight 越高的越好。
host = sorted(vpx_json['host'], key=lambda x: x.get('weight'), reverse=True)
# 將 weight 最高的 host 與 720p m3u8網址拿出來,組成完整 m3u8 網址。
m3u8_url = f"{host[0]['host']}{vpx_json['video']['720p']}"
if aria2c == True:
cmd = f'yt-dlp --output "%(title)s.%(ext)s" --downloader aria2c --downloader-args aria2c:"-j {j}" {m3u8_url}'
else:
cmd = f'yt-dlp --output "%(title)s.%(ext)s" {m3u8_url}'
print('準備下載 ' + str(animate_info['name']) + ' ' + str(animate_info['video'][ep]['name']))
subprocess.call(cmd, shell=True)
os.rename('720p.mp4', str(animate_info['name']) + ' ' + str(animate_info['video'][ep]['name']) + '.mp4')
old_path = './' + str(animate_info['name']) + ' ' + str(animate_info['video'][ep]['name']) + '.mp4'
new_path = './' + str(animate_info['name']) + '/' + str(animate_info['name']) + ' ' + str(animate_info['video'][ep]['name']) + '.mp4'
try:
os.rename(old_path, new_path)
except:
os.mkdir('./' + str(animate_info['name']))
os.rename(old_path, new_path)
def hello(DL_all, aria2c):
print('MyselfAnimeDownloader ver 0.1')
print('============================================')
if DL_all == True:
print('下載模式:全集')
else:
print('下載模式:單集')
if aria2c == True:
print('請務必確認aria2c已經啟動,否則將無法下載')
print('============================================')
if __name__ == "__main__":
config = configparser.ConfigParser()
config.read('config.ini')
DL_mode = config['DL_MODE'].getboolean('all')
aria2c = config['DL_MODE'].getboolean('aria2c')
if aria2c == True:
x = config['aria2c'].getint('x')
j = config['aria2c'].getint('j')
hello(DL_all=DL_mode, aria2c=aria2c)
id = input('id? ')
ep = int(input('episode? '))
url= 'https://myself-bbs.com/thread-' + id + '-1-1.html'
Myself.animate_total_info(url=url)
Myself.download_animate_simple_example(url=url, ep=ep , j=j)
只要調高aria2c下載的線程數,就能幾乎滿速下載,應該也不會佔用太多記憶體。不過以我的技術力最多只能改到這裡,GUI的部分就很有困難了,希望大大有空可以評估一下這種做法的可行性。
謝謝。