Skip to content

Instantly share code, notes, and snippets.

@mipsparc
Last active April 16, 2016 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mipsparc/1d48d3c4845e0ea85eda2ebefc7845be to your computer and use it in GitHub Desktop.
Save mipsparc/1d48d3c4845e0ea85eda2ebefc7845be to your computer and use it in GitHub Desktop.
simultaneously download nicovideo
#!/usr/bin/env python3
import multiprocessing
import subprocess
accounts =[
{'id':'1@example.com', 'pass':'password'},
{'id':'2@example.com', 'pass':'password'},
]
def download(account, download_urls):
for url in download_urls:
url = url.strip()
cmd = './nicomp3.sh {} {} {}'.format(url, account['id'], account['pass'])
print('{} started downloading from {}'.format(account['id'], url))
subprocess.call(cmd, shell=True)
if __name__ == '__main__':
urls = open('list.txt','r').readlines()
url_num = len(urls)
accounts_num = len(accounts)
worksPerAccount = url_num//accounts_num
rest = url_num % accounts_num
jobs = []
for account in accounts:
if rest >= 1:
myworks = worksPerAccount + 1
rest -= 1
else:
myworks = worksPerAccount
download_urls = urls[:myworks]
del urls[:myworks]
p = multiprocessing.Process(target=download, args=(account,
download_urls))
jobs.append(p)
p.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment