Skip to content

Instantly share code, notes, and snippets.

@mipsparc

mipsparc/multimp3.py

Last active Apr 16, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.