Emersont1 / itchio

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

Bugfix/unicode support #77

Open N64Core opened 1 year ago

N64Core commented 1 year ago

Pertains to issue #74

This PR fixes a bug that occurs when downloading files that use UTF-8 characters, the characters they're meant to represent will get "smeared" into a different encoding format, the root cause I believe is this line in utils.py:

#filename_re = re.search(r'filename="(.+)"', cd)

What's going on here has something to do either with re.search returning an ascii formated byte string, or a weird consequence of passing the string through the assignment operator. My memory is a bit hazy on the specifics. in addition to fixing that issue the directory handling code was improved in other sections, using existing functions to replace blocks of code and making the variable names slightly more readable.

Also apologies for the weird duplicate commits on the branch, I'm a little rusty with git.

N64Core commented 1 year ago

The code should be using pathlib, it makes it easier to use throughout the codebase

Should be good now

eibe1014 commented 1 year ago

I used this branch today (pip install https://github.com/N64Core/itchio/archive/refs/heads/bugfix/unicode_support.zip) and try to download my full lib and get into this issues:

When downloading: Downloaded Moonlight on Roseville Beach | A Visitor's Guide to Cruisin! (180 of 6320) Traceback (most recent call last): File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\downloader\__main__.py", line 75, in <module> main() File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\downloader\__main__.py", line 71, in main lib.download_library(args.platform) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\library.py", line 108, in download_library for _ in r: File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 609, in result_iterator yield fs.pop().result() File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 439, in result return self.__get_result() File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 391, in __get_result raise self._exception File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\library.py", line 99, in dl g.download(self.login, platform) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\game.py", line 91, in download self.do_download(d, token) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\game.py", line 120, in do_download if md5 == d["md5_hash"]: KeyError: 'md5_hash'

When restart downloading (so it will use local files?):

Downloaded You're having a normal day and OH NO, GOBLINS! (8 of 6320) Traceback (most recent call last): File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\downloader\__main__.py", line 75, in <module> main() File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\downloader\__main__.py", line 71, in main lib.download_library(args.platform) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\library.py", line 108, in download_library for _ in r: File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 609, in result_iterator yield fs.pop().result() File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 446, in result return self.__get_result() File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 391, in __get_result raise self._exception File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\library.py", line 99, in dl g.download(self.login, platform) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\game.py", line 91, in download self.do_download(d, token) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\game.py", line 143, in do_download filename.rename(old_dir / f"{timestamp}-{filename}") AttributeError: 'str' object has no attribute 'rename'

N64Core commented 1 year ago

I used this branch today (pip install https://github.com/N64Core/itchio/archive/refs/heads/bugfix/unicode_support.zip) and try to download my full lib and get into this issues:

When downloading: Downloaded Moonlight on Roseville Beach | A Visitor's Guide to Cruisin! (180 of 6320) Traceback (most recent call last): File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\downloader\__main__.py", line 75, in <module> main() File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\downloader\__main__.py", line 71, in main lib.download_library(args.platform) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\library.py", line 108, in download_library for _ in r: File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 609, in result_iterator yield fs.pop().result() File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 439, in result return self.__get_result() File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 391, in __get_result raise self._exception File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\library.py", line 99, in dl g.download(self.login, platform) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\game.py", line 91, in download self.do_download(d, token) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\game.py", line 120, in do_download if md5 == d["md5_hash"]: KeyError: 'md5_hash'

When restart downloading (so it will use local files?):

Downloaded You're having a normal day and OH NO, GOBLINS! (8 of 6320) Traceback (most recent call last): File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\downloader\__main__.py", line 75, in <module> main() File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\downloader\__main__.py", line 71, in main lib.download_library(args.platform) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\library.py", line 108, in download_library for _ in r: File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 609, in result_iterator yield fs.pop().result() File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 446, in result return self.__get_result() File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 391, in __get_result raise self._exception File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\library.py", line 99, in dl g.download(self.login, platform) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\game.py", line 91, in download self.do_download(d, token) File "C:\Users\*\AppData\Local\Programs\Python\Python310\lib\site-packages\itchiodl\game.py", line 143, in do_download filename.rename(old_dir / f"{timestamp}-{filename}") AttributeError: 'str' object has no attribute 'rename'

I need to test this, but I think I understand what's going on here, it's trying to call rename on an object that still purely a string and not a Path