AlphaSlayer1964 / kemono-dl

A simple kemono.party downloader using python.
509 stars 83 forks source link

Absolute path in --dirname-pattern fails on linux #186

Open catthou opened 1 year ago

catthou commented 1 year ago

Version

Version: 2022-04-28

Your Command

Two particular commands fail.

python3 /home/catthou/.sys/apps/kemono-dl/kemono-dl.py --extract-links --dirname-pattern '/b/asteroid/kemono-dl/{service}/{username} [{user_id}]' --from-file '/home/catthou/Development/downloads/default.kemono-dl' --cookies '/home/catthou/bin/kemono/kemono.party_cookies.txt'

The above command fails to write the file into /b/... and instead writes it into {current directory}/b/...

Next we try to cd into the root directory so {current directory}/b is /b, but this fails for a different reason:

cd / && python3 /home/catthou/.sys/apps/kemono-dl/kemono-dl.py --extract-links --dirname-pattern '/b/asteroid/kemono-dl/{service}/{username} [{user_id}]' --from-file '/home/catthou/Development/downloads/default.kemono-dl' --cookies '/home/catthou/bin/kemono/kemono.party_cookies.txt'

Description of bug

The first command simply tries to reference /b (folder 'b' in the root directory of the OS). It fails because the directory you run kemono-dl from is ALWAYS appended to the front, so /b becomes {current directory}/b instead of root-directory/b.

The second command fails because kemono-dl tries to write debug.log in {current directory}.

Error messages and tracebacks

Off the first command, there are no errors, per se. Files download, but into the wrong directory (into /home/catthou/b/... instead of /b/...)

Off the second command, we crash because we can't write the log file to the root directory:

Traceback (most recent call last):
  File "/home/catthou/.sys/apps/kemono-dl/kemono-dl.py", line 1, in <module>
    from src.main import main
  File "/home/catthou/.sys/apps/kemono-dl/src/main.py", line 15, in <module>
    from .logger import logger
  File "/home/catthou/.sys/apps/kemono-dl/src/logger.py", line 26, in <module>
    file_handler = logging.FileHandler('debug.log', encoding="utf-16")
  File "/usr/lib/python3.10/logging/__init__.py", line 1169, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/lib/python3.10/logging/__init__.py", line 1201, in _open
    return open_func(self.baseFilename, self.mode,
PermissionError: [Errno 13] Permission denied: '/debug.log'

Additional comments

Dumping a file with a non-descriptive filename (debug.log) in a random directory is bad practice to begin with. At the very least it should try typical log directories (like /var/log or $XDG_CACHE_HOME/kemono-dl) and use a name that indicates who's writing it. $XDG_CACHE_HOME/kemono-dl/debug.log or /var/log/kemono-dl.log would be two practical, expected filenames for logs on linux.