diff --git a/src/ArtStationDownloader.py b/src/ArtStationDownloader.py index 8afa880..112c03b 100644 --- a/src/ArtStationDownloader.py +++ b/src/ArtStationDownloader.py @@ -6,7 +6,7 @@ Copyright 2018 Sean Feng(sean@fantablade.com) """ -__version__ = "0.3.0" +__version__ = "0.3.1" # $Source$ import argparse diff --git a/src/app.py b/src/app.py index bd70c50..63ec532 100644 --- a/src/app.py +++ b/src/app.py @@ -10,13 +10,18 @@ class App: def __init__(self, version): self.core = Core(self.log) - self.user_settings = sg.UserSettings() + self.user_config = sg.UserSettings( + os.path.join(os.path.abspath("."), "config.ini"), + use_config_file=True, + convert_bools_and_none=True, + ) + self.user_settings = self.user_config["Settings"] # 兼容模式 - if not self.user_settings.exists("root_path"): - root_path = config.read_config("config.ini", "Paths", "root_path") - if root_path: - self.user_settings.set("root_path", root_path) + root_path = self.user_config["Paths"]["root_path"] + if root_path: + self.user_settings["root_path"] = root_path + self.user_config["Paths"].delete_section() self.root_path = self.user_settings.get( "root_path", os.path.join(os.path.expanduser("~"), "ArtStation") @@ -39,6 +44,7 @@ def __init__(self, version): lambda: self.download_txt(args), "" ), "-DOWNLOAD-SORTING-": self._set_download_sorting, + "-BROWSE-": self.browse_directory, "log": self._log, "popup": self._popup, "set_download_buttons": self._set_download_buttons, @@ -82,6 +88,7 @@ def download(self): usernames, self.window["-TYPE-"].get(), self.download_sorting ) self.window.write_event_value("set_download_buttons", True) + self.user_settings.set("default_username", username_text) def get_download_txt_file(self): self.window.write_event_value("set_download_buttons", False) @@ -111,7 +118,7 @@ def download_txt(self, filename): self.window.write_event_value("set_download_buttons", True) def browse_directory(self): - root_path = sg.popup_get_folder("Select a folder") + root_path = sg.popup_get_folder("Select a folder", default_path=self.root_path) if root_path: self.root_path = root_path self.window["-PATH-"].update(root_path) @@ -120,7 +127,12 @@ def browse_directory(self): def create_layout(self): sg.theme("Dark Blue 3") layout = [ - [sg.Text('Usernames (split by ","):'), sg.InputText(key="-USERNAME-")], + [ + sg.Text('Usernames (split by ","):'), + sg.InputText( + self.user_settings.get("default_username", ""), key="-USERNAME-" + ), + ], [ sg.Text("Type:"), sg.Combo( @@ -141,8 +153,8 @@ def create_layout(self): ], [ sg.Text("Path:"), - sg.InputText(key="-PATH-", default_text=self.root_path), - sg.FolderBrowse("Browse", key="-BROWSE-"), + sg.InputText(key="-PATH-", default_text=self.root_path, disabled=True), + sg.Button("Browse", key="-BROWSE-", bind_return_key=True), ], [ sg.Button("Download", key="-DOWNLOAD-", bind_return_key=True), diff --git a/src/core.py b/src/core.py index 2935681..d9ed8c6 100644 --- a/src/core.py +++ b/src/core.py @@ -9,7 +9,7 @@ from concurrent import futures from multiprocessing import cpu_count from urllib.parse import urlparse -import http.client +import http.client as http_client from bs4 import BeautifulSoup import pafy import requests @@ -44,24 +44,26 @@ def __init__(self, log_print=None): self.futures = [] self._session = requests.session() self.proxy_setup() - + def http_client_get(self, url): try: headers = { - 'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36", - 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", - 'Accept-Language': "en-US,en;q=0.5", - 'Accept-Encoding': "gzip, deflate, br", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.5", + "Accept-Encoding": "gzip, deflate, br", } parsed_url = urlparse(url) - conn = http.client.HTTPSConnection(parsed_url.netloc) - conn.request("GET", parsed_url.path+"?"+parsed_url.query, headers=headers) + conn = http_client.HTTPSConnection(parsed_url.netloc) + conn.request( + "GET", parsed_url.path + "?" + parsed_url.query, headers=headers + ) r = conn.getresponse() except: - print(f'Error in http_client_get') - + print(f"Error in http_client_get") + return r def http_get(self, url): @@ -173,7 +175,9 @@ def get_projects(self, username): else: self.log(err + "Unknown error") break - channel = BeautifulSoup(r.read().decode("utf-8"), "lxml-xml").rss.channel + channel = BeautifulSoup( + r.read().decode("utf-8"), "lxml-xml" + ).rss.channel links = channel.select("item > link") if len(links) == 0: break