Skip to content

Instantly share code, notes, and snippets.

@mjsilva
Created December 14, 2016 09:28
Show Gist options
  • Save mjsilva/3f71b1f21e62dc354a4578b3ffc11515 to your computer and use it in GitHub Desktop.
Save mjsilva/3f71b1f21e62dc354a4578b3ffc11515 to your computer and use it in GitHub Desktop.
Using transmission-cli remove all torrents with "Error: No data found!"
<?php
$torrents = shell_exec("transmission-remote -n 'transmission:transmission' -l");
$torrents = explode("\n", $torrents);
$torrents = array_map(function($value)
{
$value = str_replace(" ", " ", trim($value));
return explode(" ", $value);
}, $torrents);
foreach ($torrents as $torrent) {
$id = $torrent[0];
if (!$id) {
continue;
}
$id = str_replace("*", "", $torrent[0]);
$info = shell_exec("transmission-remote -n 'transmission:transmission' -t $id -i");
echo "Removing torrent with id $id\n";
if (strpos($info, "Error: No data found!") !== false) {
shell_exec("transmission-remote -n 'transmission:transmission' -t $id -r");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment