Beastwick18/nyaa

[Bug] backslashes in magnet

Disonantemus opened this issue · 6 comments

From ~/.config/nyaa/config.toml:
I did change first line to just copy magnet to X11 clipboard:

torrent_client_cmd = 'echo "{magnet}" | xsel -ib'

Didn't work, because output has many extra \ (backslashes) that aren't in the original link, this is not expected.

Workaround:
I did use tr to remove backslashes:

torrent_client_cmd = 'echo "{magnet}" | tr -d "\\" 2> /dev/null | xsel -ib'

And seems to work.

I use this with a mimi shell script to download magnets from clipboard with aria2.


nyaa v0.6.3
distro: Arch Linux x86_64
kernel: 6.1.52-1-lts
shell: bash 5.2.26
term: tmux

Interesting, I didn't think this would break anything. This is using the crate shellwords to escape all special characters when in POSIX shells, it should work just fine if you remove the quotes. Which torrent client do you use by the way? Next release should have support for a direct connection to torrent clients, which should remove most cases for the torrent_client_cmd option. Currently, I've only implemented qBittorrent.

Now that I think about it, I'll likely remove escaping completely. The reason it was there before is because commands were forced to look like:

bash -c "echo {magnet} > file.txt"

in order to get shell functions like piping and redirection. This introduced an extra layer of quotes which made escaping more convenient as a workaround.

But that was changed recently. The command is by default run with sh -c, with no quotes required.

Looking at your config, it does seem more intuitive to put quotes around the magnet link, which is likely what others have tried and ultimately led to an error. Changing this should be more in line with what people will expect.

Which torrent client do you use by the way?

I use aria2, with a simple shell script that downloads magnet from clipboard.
Is the more minimal that I know.


From terminal options, I know:

  • rtorrent
  • transmission-cli
  • qbittorrent-nox

I think all of them should allow, to watch a folder for torrents to download (same with GUI, like: qbittorrent, deluge, transmission). Maybe there are other ways to communicate with them, like RPC.

qBittorrent-nox should use the same API as normal qBittorrent, so that should already be working.

I'll look into rtorrent, transmission-cli, and deluge to see if they have any relevant API.

As for the backslashes, I've removed escaping on main in commit ab1db55. You can build it from source in the meantime if you want to keep the quotes, or just remove the quotes around magnet to fix any issues.

I'll be closing this issue for now, as the original issue is solved on main, but let me know if something else is not working as intended :)

Also, if the fix on main isn't working as intended either, feel free to re-open this issue.

I'm using it under Windows and i had to put "{magnet}" to make it works good passing the data to the system clipboard. But i'm having problem concatenating another command like this one:

'echo "{magnet}" | clip && start {torrent}'

which doesn't work.

By the way it could be usefull a direct key binding for auto copy torrent/magnet links to the clipboard directly and open the relative link page directly in the browser if needed. (https://nyaa.si/view/xxxxx)

'echo "{magnet}" | clip && start {torrent}'

which doesn't work.

The reason this doesn't work is because the command is by default run with Powershell, which doesn't support chaining commands with &&. You should be able to run this with a semi-colon ; though, like: 'echo "{magnet}" | clip ; start {torrent}'. I'll see about adding an option for which shell you want to use so features you may want from another shell can be accessed. Something like:

shell_cmd = "cmd /c"
# or
shell_cmd = "powershell -Command"

By the way it could be useful a direct key binding for auto copy torrent/magnet links to the clipboard directly and open the relative link page directly in the browser if needed. (https://nyaa.si/view/xxxxx)

This is for sure something I'll look into adding for the next release. Probably the y key to match vim for copying and the b key for opening https://nyaa.si/view/xxxxx in the default browser.