FurryCoders / FALocalRepo

Pure Python program to download submissions, journals, and user folders from the FurAffinity forum in an easily handled database.
European Union Public License 1.2
21 stars 2 forks source link

[Bug]: Crash while downloading submission #4

Closed NSFWOrangeCat closed 2 years ago

NSFWOrangeCat commented 2 years ago

Version

4.3.0

What happened?

Crash while downloading submission https://www.furaffinity.net/view/12415691/.

OS used is Win10 21H2. Python version is 3.10.4.

How to reproduce the bug?

falocalrepo download submissions 12415691

Relevant log output

Traceback (most recent call last):
  File "D:\Program Files\Python\lib\site-packages\falocalrepo\__main__.py", line 45, in main
    exit(app.main(standalone_mode=False) or 0)
  File "D:\Program Files\Python\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "D:\Program Files\Python\lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "D:\Program Files\Python\lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "D:\Program Files\Python\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "D:\Program Files\Python\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "D:\Program Files\Python\lib\site-packages\click\decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "D:\Program Files\Python\lib\site-packages\falocalrepo\console\download.py", line 301, in download_submissions
    downloader.download_submissions(list(submission_id))
  File "D:\Program Files\Python\lib\site-packages\falocalrepo\downloader.py", line 747, in download_submissions
    self.download_submission(submission_id,
  File "D:\Program Files\Python\lib\site-packages\falocalrepo\downloader.py", line 374, in download_submission
    self.db.submissions.save_submission({**format_entry(dict(submission), self.db.submissions.columns),
  File "D:\Program Files\Python\lib\site-packages\falocalrepo_database\database.py", line 322, in save_submission
    submission[SubmissionsColumns.FILEEXT.value.name] = SubmissionsColumns.FILEEXT.value.to_entry([
  File "D:\Program Files\Python\lib\site-packages\falocalrepo_database\database.py", line 323, in <listcomp>
    self.save_submission_file(
  File "D:\Program Files\Python\lib\site-packages\falocalrepo_database\database.py", line 348, in save_submission_file
    folder.joinpath(f"{name}{n if n > 0 else ''}" + f".{ext}" * bool(ext)).write_bytes(file)
  File "D:\Program Files\Python\lib\pathlib.py", line 1141, in write_bytes
    with self.open(mode='wb') as f:
  File "D:\Program Files\Python\lib\pathlib.py", line 1117, in open
    return self._accessor.open(self, mode, buffering, encoding, errors,
OSError: [Errno 22] Invalid argument: 'D:\\Program Files\\FALocalRepo\\FA.files\\00\\12\\41\\56\\91\\submission.doc|'
MatteoCampinoti94 commented 2 years ago

Thanks for reporting this!

The error was caused by an incorrect parsing of the submission file URL to get the file extension. The program uses it for some filetypes which cannot be recognised easily because their MIME type is non-specific. In your case the .doc file resulted in an application/zip MIME, so the program tried to use the file url, but it parsed the value formatted for the database instead of the original one, so it resulted in an extension with a | in it.

I am using Linux for development and its filesystem its much more lax in regards to filenames, but Windows is quite stricter and won't allow | in a filename, hence the error.

I've fixed the bug in the database library and pushed a patch v5.3.1. It's already online so you can just update it via pip, you can use the falocalrepo updates --shell command to do it :)