styper / qbit_automatch

15 stars 2 forks source link

Linux support #1

Open slrslr opened 3 years ago

slrslr commented 3 years ago

Hello, i am not a coder, but to support Linux let me know if you need any particular command output or an example output that the script would expect, maybe i can figure out Linux command to deliver it in case you are missing it and can use it in the script.

styper commented 3 years ago

Thanks, I've just replaced the TASKLIST WIndows call for a lib called psutil which is cross platform, it should work on linux. I guess I just need to check the default location of BT_backup folder which is where qBittorrent stores .torrent and .fastresume files.

Can you check if this folder exists in your system? ~/.local/share/data/qBittorrent/BT_backup

slrslr commented 3 years ago

~/.local/share/data/qBittorrent/BT_backup

that does not exist on my system, but this does exist:

~/.local/share/qBittorrent/BT_backup i have feeling that qbt would recognize both locations, but upon start said that mine mentioned location is correct, IMBW

slrslr commented 3 years ago

https://github.com/qbittorrent/qBittorrent/wiki/Frequently-Asked-Questions#where-does-qbittorrent-save-its-settings

styper commented 3 years ago

Nice find, thanks, I'll adapt the code and let you know

styper commented 3 years ago

@slrslr It's done, on Linux it defaults to ~/.local/share/data/qBittorrent/BT_backup Can you check if it's working?

styper commented 3 years ago

BTW, since your path is different than the default one you can call the script by passing the extra parameter --bt_backup "/home//.local/share/qBittorrent/BT_backup"

slrslr commented 3 years ago

Can you check if it's working?

i have tried to run it without python prefix out of curiosity, my computer was stuck for nearly half minute.

$ ./qbit_automatch.py

^C^C./qbit_automatch.py: line 5: from: command not found
./qbit_automatch.py: line 6: from: command not found
./qbit_automatch.py: line 8: try:: command not found
./qbit_automatch.py: line 10: except: command not found
./qbit_automatch.py: line 11: syntax error near unexpected token `('
./qbit_automatch.py: line 11: `    raise SystemExit('Error: The bencode.py module is needed, you can install it with this command: python -m pip install bencode.py')'
$ python ./qbit_automatch.py
Error: The bencode.py module is needed, you can install it with this command: python -m pip install bencode.py
$ python -m pip install bencode.py
Defaulting to user installation because normal site-packages is not writeable
Collecting bencode.py
  Using cached bencode.py-4.0.0-py2.py3-none-any.whl (18 kB)
Installing collected packages: bencode.py
Successfully installed bencode.py-4.0.0
$ python ./qbit_automatch.py
Traceback (most recent call last):
  File "/home/me/apps/./qbit_automatch.py", line 67, in <module>
    if not os.path.isdir(args.search_dir):
  File "/usr/lib/python3.9/genericpath.py", line 42, in isdir
    st = os.stat(s)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

python3 prefix is same result:

$ which python3
/usr/bin/python3
$ /usr/bin/python3 ./qbit_automatch.py
Traceback (most recent call last):
  File "/home/me/apps/./qbit_automatch.py", line 67, in <module>
    if not os.path.isdir(args.search_dir):
  File "/usr/lib/python3.9/genericpath.py", line 42, in isdir
    st = os.stat(s)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

when i have defined all parameters, the output was:

hash..........: myhashhere
search_dir....: /home/me/Downloads/mydirname (link)/
BT_backup.....: /home/me/.local/share/qBittorrent/BT_backup
qBt_savePath..: /home/me/Downloads
torrent.......: /home/me/.local/share/qBittorrent/BT_backup/myhashhere.torrent
fastresume....: /home/me/.local/share/qBittorrent/BT_backup/myhashhere.fastresume
fastresume_bkp: /home/me/.local/share/qBittorrent/BT_backup/myhashhere.fastresume.bkp
Traceback (most recent call last):
  File "/home/me/apps/./qbit_automatch.py", line 96, in <module>
    found_file=find_file(search_dir_cache, td_file_length, td_file_extension, td_filename)
  File "/home/me/apps/./qbit_automatch.py", line 57, in find_file
    raise FileNotFoundError('File ' + filename + ' not found!')
FileNotFoundError: One File file name without extension here not found!
styper commented 3 years ago

@slrslr In this last run in your log it worked as expected as the script needs both the hash and the search_dir, I built in that FileNotFoundError because the script needs to find every file of the torrent or it doesn't work. Are you sure the search_dir contains all the files from the torrent?

The search_dir provided is a symlink? I haven't tested with those yet

slrslr commented 3 years ago

Are you sure the search_dir contains all the files from the torrent?

no, it contains only some files, also the torrent partially downloaded some files, but these are gone. So only some files are in that folder and are complete.

script needs to find every file of the torrent or it doesn't work

i see, sorry i have overlooked this in the README.md

Maybe can be handy if script return more user friendly error in this regard and also when some or all script parameters like hash searchdir are missing (output from my previous comment).

styper commented 3 years ago

no, it contains only some files, also the torrent partially downloaded some files, but these are gone. So only some files are in that folder and are complete.

I'm still not sure what to do in these cases, because qBittorrent(or libtorrent?) organizes the files in the .fastresume file in a very simplistic manner Instead of storing them as a dictionary: Torrent File 1 -> Disk File 1 It just stores them in the same sequence as the torrent file, so if torrent file is File1,File2,File3 I have to organize them in the same manner in the .fastresume file like File1,RenamedFile2,File3 I guess I could just point not found files to _search_dir//_ I haven't tried this yet because I wanted to make sure I wasn't breaking anything in completed torrent files.

Maybe can be handy if script return more user friendly error in this regard and also when some or all script parameters like hash searchdir are missing (output from my previous comment).

I can do that. I'll add a check if both (hash and search_dir) parameters are provided and replace the FileNotFound exception with proper message

styper commented 3 years ago

@slrslr I've improved the error messages, the --help and the README, should be more user friendly. Now it properly tells you that required arguments are missing: usage: qbit_automatch.py [-h] -a HASH -s PATH [-b PATH] [-f N] [-d] qbit_automatch.py: error: the following arguments are required: -a/--hash, -s/--search_dir

I still don't know what to do with incomplete torrents though

slrslr commented 3 years ago

without any prefix, parameters the script again frozen my Linux desktop interface for like 80 seconds, during that i did a few Ctrl+C commands to interrupt the run:

$ /home/me/apps/qbit_automatch.py

dd^C^C^C/home/me/apps/qbit_automatch.py: line 5: from: command not found
/home/me/apps/qbit_automatch.py: line 6: from: command not found
/home/me/apps/qbit_automatch.py: line 8: try:: command not found
^C/home/me/apps/qbit_automatch.py: line 10: except: command not found
/home/me/apps/qbit_automatch.py: line 11: syntax error near unexpected token `('
/home/me/apps/qbit_automatch.py: line 11: `    raise SystemExit('Error: The bencode.py module is needed, you can install it with this command: python -m pip install bencode.py')'

dstat command on other terminal tab missed its output during that

but when running like this: python /home/me/apps/qbit_automatch.py

then the command says missing parameters, which is good, user friendly also the README is good and explains the things well.