ニコニコ動画のダウンロード マイリストから一括
ただのメモに近い。
# -*- config: utf-8 -*-
#------------------------------------------------------------------------------
# import
#------------------------------------------------------------------------------
from niconico import NicoNico
import pprint
import concurrent.futures
import time
# 並列用のラッパー
def wapper_x(line_list, max, b):
for i in range(len(line_list)):
if i % max == b:
url = line_list[i][1]
with client.video.get_video(url) as video:
video.download(f"{video.video.id} - {video.video.title}.mp4")
return 0
URL = "<マイリストのURL>"
client = NicoNico()
for mylist in client.video.get_mylist(URL):
line_list = []
for line in mylist.items:
line_list.append([line.video.id, line.video.url, line.video.title])
pprint.pprint(line_list, width=300)
futures = []
max = 5
executor = concurrent.futures.ThreadPoolExecutor(max_workers=max)
# concurrent execution
for a in range(max):
#print(a)
#wapper_x(line_list, max, a)
futures.append(executor.submit(wapper_x, line_list, max, a))
time.sleep(1)
# wait
for future in concurrent.futures.as_completed(futures):
True
exit()