fedarovich / qbittorrent-cli

Command line interface for QBittorrent
MIT License
303 stars 16 forks source link

Pause torrent with specified category #24

Closed foxi69 closed 4 years ago

foxi69 commented 4 years ago

Like qbt torrent pause ALL -c CategoryName

does it possible?

fedarovich commented 4 years ago

Well, it is possible, though not directly, but with some shell magic.

Basically, you should do the following steps:

  1. Get the list of torrents filtered by category in some parceable format, e.g. JSON.
  2. Extract the torrent hashes from it.
  3. Pass the hashes to qbt torrent pause one by one.

For powershell you can use something like that:

 (qbt torrent list -c MyCategory -F json | ConvertFrom-Json).hash | foreach { qbt torrent resume $_ }

In bash it is easier to use CSV format as you can use awk to extract the hash. You can use the following script:

qbt torrent list -c MyCategory -F csv | awk -F "," 'NR > 1 {print $1}' | xargs -n 1 qbt torrent pause

I will probably add some additional output formats in the next qbt versions to make similar scenarios easier.

foxi69 commented 4 years ago

Oh thanks.

Can u help me how can i make a script what pause the torrent and unrar after downloaded + delete the rar files after unrar complete :|

Like this one: cmd /c timeout /t 15 & "E:\Programok\WinRAR\RAR.exe" x -r "%F*.rar" "%F" && del /f "%F*.r'[0-9]{2}'" && del /f "%F*.sfv*"

but i dont know how to open powershell in the background to pause first :/

fedarovich commented 4 years ago

In order to run a command in powershell you can use the following:

powershell -Command "<command>"

So, if I correctly understand what you'd like to achieve, you can use something like that:

powershell -Command "(qbt torrent list -c MyCategory -F json | ConvertFrom-Json).hash | foreach { qbt torrent resume $_ }" && cmd /c timeout /t 15 & "E:\Programok\WinRAR\RAR.exe" x -r "%F*.rar" "%F" && del /f "%F*.r'[0-9]{2}'" && del /f "%F*.sfv*"
foxi69 commented 4 years ago

Works with a batch file what i run from qBitorrent :)

\RUN.bat "%I" "%F"

powershell -Command "(qbt torrent list --url http://localhost:8080 -c MyCategory -F json | ConvertFrom-Json).hash | foreach { qbt torrent pause $_ --url http://localhost:8080 }" && cmd /c timeout /t 15 & "E:\Programok\WinRAR\RAR.exe" x -r "%2*.rar" "%2" && del /f "%2*.r" && del /f "%2*.sfv"

foxi69 commented 4 years ago

I wanted to pause the torrent what downloaded already, but with this code it will stop every torrent in the specified category after one torrent downloaded in that category :/

foxi69 commented 4 years ago

After it unrar the torrent, how can i delete only the rar,r01....r99 files? :)

powershell Get-ChildItem $Path | Where{$_.Name -Match "*.r[0-9]{2}"} | Remove-Item it doesnt work :(

foxi69 commented 4 years ago

I have been created my own script with Powershell and works great with your program :) Thanks @fedarovich