Emersont1 / itchio

https://pypi.org/project/itchiodl/
MIT License
105 stars 17 forks source link

Crash when a game file changes name when downloaded due to filename character restrictions #74

Open dph121 opened 1 year ago

dph121 commented 1 year ago

One of the files in the game https://ladyorthetiger.itch.io/platonic-pirates is named Platonic Pirates — Light.pdf. When I run the program, either as a complete library download or downloading just the game, the file is stored on my computer as Platonic Pirates — Light.pdf, after which the program crashes with the following dialogue:

(base) C:\Daphne\itchio>python -m itchiodl.downloader -k REDACTED --download-game https://ladyorthetiger.itch.io/platonic-pirates platonic-pirates is a purchased game. Loading page 1 Downloading Platonic Pirates Downloading Platonic Pirates — Light.pdf Downloading Platonic Pirates - Platonic Pirates — Light.pdf Downloaded Platonic Pirates â Light.pdf Traceback (most recent call last): File "C:\Users\flipw\anaconda3\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\flipw\anaconda3\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\flipw\anaconda3\lib\site-packages\itchiodl\downloader__main.py", line 66, in main() File "C:\Users\flipw\anaconda3\lib\site-packages\itchiodl\downloader__main__.py", line 62, in main lib.download_library(args.platform) File "C:\Users\flipw\anaconda3\lib\site-packages\itchiodl\library.py", line 108, in downloadlibrary for in r: File "C:\Users\flipw\anaconda3\lib\concurrent\futures_base.py", line 609, in result_iterator yield fs.pop().result() File "C:\Users\flipw\anaconda3\lib\concurrent\futures_base.py", line 446, in result return self.get_result() File "C:\Users\flipw\anaconda3\lib\concurrent\futures_base.py", line 391, in __get_result raise self._exception File "C:\Users\flipw\anaconda3\lib\concurrent\futures\thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "C:\Users\flipw\anaconda3\lib\site-packages\itchiodl\library.py", line 99, in dl g.download(self.login, platform) File "C:\Users\flipw\anaconda3\lib\site-packages\itchiodl\game.py", line 75, in download self.do_download(d, token) File "C:\Users\flipw\anaconda3\lib\site-packages\itchiodl\game.py", line 187, in do_download if utils.md5sum(out_file) != d["md5_hash"]: File "C:\Users\flipw\anaconda3\lib\site-packages\itchiodl\utils.py", line 51, in md5sum with path.open("rb") as f: File "C:\Users\flipw\anaconda3\lib\pathlib.py", line 1252, in open return io.open(self, mode, buffering, encoding, errors, newline, File "C:\Users\flipw\anaconda3\lib\pathlib.py", line 1120, in _opener return self._accessor.open(self, flags, mode) FileNotFoundError: [Errno 2] No such file or directory: 'ladyorthetiger\platonic-pirates\Platonic Pirates — Light.pdf'

My bughunt lead me to line 95 in game.py producing an "output filename" string that doesn't match what the actual filename is in the output folder. This results in line 99 assuming a file has not been downloaded, and line 187 crashing the program by trying to determine a checksum of a file that does not exist.

This is on Windows 11, so the specific filename replacement might not be reproduced on other machines. I am capable of downloading many other files.

Emersont1 commented 1 year ago

Oh. That looks like that's a utf8 dash in the filename as opposed to a hypen. I think I may need to revisit the path escaping code

N64Core commented 1 year ago

Hi!

I believe I have a fix for smeared unicode characters in this branch here: https://github.com/N64Core/itchio/commit/7c7a70d9fe606819698865af9c81fdd4a9ded7b2

I only hazily remember what the issue is, I believe it has something to do with how the = operator and unicode strings interact, but it's been several months.

Once my existing PR gets merged in I can submit it upstream

Edit: Confirmed that title generates the filename correctly on that branch:

image