From c919b3bd7e7187b6ae053f0500807c528db1717f Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 12 May 2022 20:59:01 +0800 Subject: [PATCH] [feat] download 4k images --- src/ArtStationDownloader.py | 2 +- src/core.py | 27 +++++++++++---------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/ArtStationDownloader.py b/src/ArtStationDownloader.py index 3b2f91b..87e6f6b 100644 --- a/src/ArtStationDownloader.py +++ b/src/ArtStationDownloader.py @@ -6,7 +6,7 @@ Copyright 2018 Sean Feng(sean@fantablade.com) """ -__version__ = "0.2.0" +__version__ = "0.2.1" # $Source$ import argparse diff --git a/src/core.py b/src/core.py index 21e7fa8..fe15ac2 100644 --- a/src/core.py +++ b/src/core.py @@ -49,6 +49,7 @@ def __init__(self, log_print=None): self.session.proxies.update(proxys) def download_file(self, url, file_path, file_name): + url = url.replace("/large/", "/4k/") file_full_path = os.path.join(file_path, file_name) if os.path.exists(file_full_path): self.log("[Exist][image][{}]".format(file_full_path)) @@ -114,11 +115,7 @@ def get_projects(self, username): page = 0 while True: page += 1 - url = ( - "https://{}.artstation.com/rss?page={}".format( - username, page - ) - ) + url = "https://{}.artstation.com/rss?page={}".format(username, page) r = self.session.get(url) if not r.ok: err = "[Error] [{} {}] ".format(r.status_code, r.reason) @@ -129,18 +126,14 @@ def get_projects(self, username): else: self.log(err + "Unknown error") break - j = BeautifulSoup(r.text, "lxml-xml").rss.channel + channel = BeautifulSoup(r.text, "lxml-xml").rss.channel + links = channel.select("item > link") + if len(links) == 0: + break if page == 1: self.log("\n==========[{}] BEGIN==========".format(username)) - data_fragment = j.select("item > link") - if len(data_fragment) == 0: - break - data += data_fragment - self.log( - "\n==========Get page {}==========".format( - page - ) - ) + data += links + self.log("\n==========Get page {}==========".format(page)) return data def download_by_username(self, username): @@ -148,7 +141,9 @@ def download_by_username(self, username): if len(data) != 0: future_list = [] for project in data: - future = self.executor.submit(self.download_project, project.string.split("/")[-1]) + future = self.executor.submit( + self.download_project, project.string.split("/")[-1] + ) future_list.append(future) futures.wait(future_list)