Skip to content

Commit

Permalink
[fix] #27
Browse files Browse the repository at this point in the history
[feat] save username as default
  • Loading branch information
findix committed May 4, 2023
1 parent 8d7df67 commit 24351ec
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/ArtStationDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Copyright 2018 Sean Feng([email protected])
"""

__version__ = "0.3.0"
__version__ = "0.3.1"
# $Source$

import argparse
Expand Down
30 changes: 21 additions & 9 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand All @@ -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),
Expand Down
26 changes: 15 additions & 11 deletions src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 24351ec

Please sign in to comment.