Skip to content

Commit

Permalink
[add] allow comment in txt
Browse files Browse the repository at this point in the history
  • Loading branch information
findix committed Jul 7, 2018
1 parent 53f5c02 commit a8df7d0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
33 changes: 28 additions & 5 deletions ArtStationDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
Copyright 2018 Sean Feng([email protected])
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
Expand Down Expand Up @@ -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]
Expand All @@ -144,15 +156,26 @@ 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")

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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -44,6 +45,7 @@ https://www.artstation.com/xrnothing 或者 xrnothing
只需要在输入他们的 URL 或用户名时,在中间加入英文的","即可

或者,你也可以新建一个文本文件(.txt),每一行输入一位作者的信息。
(允许使用 Python 风格的注释,即 # 后的内容会被忽略,空白符与空行同样也会被忽略)

然后点击 Download txt 按钮选择文件即可。

Expand Down

0 comments on commit a8df7d0

Please sign in to comment.