From a8df7d0ab6aa373e738f6c8ec45cc80b9d20e0fa Mon Sep 17 00:00:00 2001 From: Sean Feng Date: Sun, 8 Jul 2018 00:54:06 +0800 Subject: [PATCH] [add] allow comment in txt --- ArtStationDownloader.py | 33 ++++++++++++++++++++++++++++----- README.md | 2 ++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/ArtStationDownloader.py b/ArtStationDownloader.py index 18ab9c5..8f04143 100644 --- a/ArtStationDownloader.py +++ b/ArtStationDownloader.py @@ -5,8 +5,16 @@ Copyright 2018 Sean Feng(sean@FantaBlade.com) +CHANGELOG + +20180611 0.1.0-alpha1 +允许在txt中使用Python风格的注释,即以#开头的内容会被忽略 +对txt中的空白符进行处理 +保存路径不再强制包含 ArtStation +默认保存路径现在为用户根路径 + """ -__version__ = "$Revision: 0.1.0-alpha$" +__version__ = "0.1.0-alpha1" # $Source$ from urllib.parse import urlparse @@ -116,8 +124,12 @@ def download_by_usernames(self, usernames): max_workers = 20 if self.executor is None: self.executor = futures.ThreadPoolExecutor(max_workers) + # 去重与处理网址 + username_set = set() for username in usernames: username = username.strip().split('/')[-1] + username_set.add(username) + for username in username_set: data = self.get_projects(username) if len(data) is not 0: args = [project['hash_id'] for project in data] @@ -144,7 +156,18 @@ def download_txt(self): filetypes=(('text files', '*.txt'), ("all files", "*.*")))) if filename is not '.': with open(filename, "r") as f: - usernames = f.readlines() + usernames = [] + # 预处理,去掉注释与空白符 + for username in f.readlines(): + username = username.strip() + if len(username) is 0: + continue + sharp_at = username.find('#') + if sharp_at is 0: + continue + if sharp_at is not -1: + username = username[:sharp_at] + usernames.append(username.strip()) self.download_by_usernames(usernames) self.btn_download.configure(state="normal") self.btn_download_txt.configure(state="normal") @@ -152,7 +175,7 @@ def download_txt(self): def browse_directory(self): dir = os.path.normpath(filedialog.askdirectory()) if dir is not '': - self.root_path = os.path.join(dir, 'ArtStation') + self.root_path = dir Config.write_config('config.ini', 'Paths', 'root_path', self.root_path) self.entry_path.delete(0, END) @@ -199,11 +222,11 @@ def createWidgets(self): def __init__(self, master=None): Frame.__init__(self, master) - master.title('ArtStation Downloader 0.1.0-alpha') # 定义窗体标题 + master.title('ArtStation Downloader ' + __version__) # 定义窗体标题 root_path_config = Config.read_config( 'config.ini', 'Paths', 'root_path') self.root_path = os.path.join( - os.path.expanduser("~"), 'Desktop', 'ArtStation') if root_path_config is '' else root_path_config + os.path.expanduser("~")) if root_path_config is '' else root_path_config self.executor = None self.executor_ui = futures.ThreadPoolExecutor(1) self.executor_video = futures.ThreadPoolExecutor(1) diff --git a/README.md b/README.md index 47f2455..8cc44e7 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ You can download more then one artists' whole works at one time. Just input all the URL or usernames split with ','. or you can create a txt file with These, one artist one line. +(you can use python style comment, any text after # will be ignored, space charactor and empty line are also ignored) and click the Download txt button to select file. @@ -44,6 +45,7 @@ https://www.artstation.com/xrnothing 或者 xrnothing 只需要在输入他们的 URL 或用户名时,在中间加入英文的","即可 或者,你也可以新建一个文本文件(.txt),每一行输入一位作者的信息。 +(允许使用 Python 风格的注释,即 # 后的内容会被忽略,空白符与空行同样也会被忽略) 然后点击 Download txt 按钮选择文件即可。