0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[python]ニコニコ動画のダウンロード mylistから一括

Posted at

ニコニコ動画のダウンロード マイリストから一括
ただのメモに近い。

# -*- 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()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?