Skip to content

Commit

Permalink
Fixed cover image download 403 error.
Browse files Browse the repository at this point in the history
  • Loading branch information
ch010060 committed Jul 16, 2024
1 parent 9837b1e commit 38b2d54
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion dlsite_renamer-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ def nameChange(path, del_flag, cover_flag, recur_flag):
store_path = os.path.join(path, file, "cover.jpg")
if not os.path.isfile(store_path):
print(" 下載封面...\n")
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', USER_AGENT)]
urllib.request.install_opener(opener)
urllib.request.urlretrieve(img_url, store_path)
else:
print("**封面已存在,跳過下載!\n")
Expand Down Expand Up @@ -290,7 +293,7 @@ def dir_path(path):
raise argparse.ArgumentTypeError(f"\"{path}\" is not a valid path!")

def process_command():
parser = argparse.ArgumentParser(description="Renamer for DLsite works v3.5")
parser = argparse.ArgumentParser(description="Renamer for DLsite works v3.6")
parser.add_argument('-d', "--DEL", action='store_true', help='delete string in 【】')
parser.add_argument('-c', "--COVER", action='store_true', help='download cover')
parser.add_argument('-r', "--RECUR", action='store_true', help='recursively processing')
Expand Down
5 changes: 4 additions & 1 deletion dlsite_renamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ def nameChange():
store_path = os.path.join(path, file, "cover.jpg")
if not os.path.isfile(store_path):
text.insert(tk.END, " 下載封面...\n")
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', USER_AGENT)]
urllib.request.install_opener(opener)
urllib.request.urlretrieve(img_url, store_path)
else:
text.insert(tk.END, "**封面已存在,跳過下載!\n")
Expand Down Expand Up @@ -313,7 +316,7 @@ def thread_it(func, *args):


root = tk.Tk() # 實例化object,建立視窗root
root.title('DLsite重命名工具 v3.5') # 給視窗的標題取名字
root.title('DLsite重命名工具 v3.6') # 給視窗的標題取名字
root.eval('tk::PlaceWindow . center')
root.geometry('350x450') # 設定視窗的大小(橫向 * 縱向)

Expand Down

0 comments on commit 38b2d54

Please sign in to comment.