Last active
February 16, 2019 12:26
-
-
Save hephyr/d4a38461315b1626324b8028246d68c9 to your computer and use it in GitHub Desktop.
Download the pictures in your Pixiv bookmarks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import os | |
import time | |
from pixivpy3 import * | |
from multiprocessing import Pool | |
api = AppPixivAPI() | |
username = 'account' | |
password = 'password' | |
path = u'your path' | |
pixiv_id = 123456 | |
os.chdir(path) | |
t = time.strftime('%Y-%m') | |
if not os.path.exists(t): | |
os.mkdir(t) | |
def downloadImg(url): | |
print(url) | |
dp = os.path.join(path, t) | |
api.download(url, path=dp) | |
def dirFiles(path): | |
files = [i[2] for i in os.walk(path)] | |
result = [] | |
for i in files: | |
result.extend(i) | |
return result | |
def main(): | |
api.login(username=username, password=password) | |
files = dirFiles(path) | |
favorite = api.user_bookmarks_illust(pixiv_id) | |
fav_res = favorite['illusts'] | |
image_urls = [] | |
for i in fav_res: | |
if i['meta_single_page'].has_key("original_image_url"): | |
image_urls.append(i['meta_single_page']['original_image_url']) | |
elif len(i['meta_pages']) != 0: | |
image_urls.extend([u['image_urls']['original'] for u in i['meta_pages']]) | |
urls = filter(lambda x: os.path.basename(x) not in files, image_urls) | |
print image_urls | |
print urls | |
p = Pool(10) | |
p.map(downloadImg, urls) | |
p.close() | |
p.join() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace
username
password
andpath