Last active
August 29, 2015 13:57
-
-
Save Pyppe/9446546 to your computer and use it in GitHub Desktop.
Simple scala script for wrapping `transmission-remote`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
exec scala -savecompiled "$0" "$@" | |
!# | |
// Given all torrents are paused, this script starts the first one | |
import sys.process._ | |
val host = "127.0.0.1:9091" | |
val auth = "myuser:mypassword" | |
def run(cmd: String): String = { | |
val sb = new StringBuilder | |
Process(cmd) ! ProcessLogger({out: String => sb.append(out + "\n")}) | |
sb.toString | |
} | |
def runTorrentCmd(cmd: String): String = | |
run(s"transmission-remote $host --auth $auth $cmd") | |
val lines = runTorrentCmd("--list").split("\n").toList | |
if (lines.size > 2) { | |
val torrents = lines.drop(1).dropRight(1) | |
val stopped = torrents.filter(_.contains(" Stopped ")) | |
println(s"${torrents.size} torrents, ${stopped.size} of them stopped") | |
if (stopped.size == torrents.size) { | |
stopped.head.split("([ ]{2,})").map(_.trim).filter(_.nonEmpty) match { | |
case Array(id, percentDone, downloaded, eta, up, down, ratio, status, name) => | |
println(s"Starting torrent $id: $name") | |
println(runTorrentCmd(s"--torrent $id --start")) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
time ./data/scripts/start-paused-torrent.scala | |
6 torrents, 6 of them stopped | |
Starting torrent 51: jdk-7u51-linux-x64.tar.gz | |
127.0.0.1:9091/transmission/rpc/ responded: "success" | |
real 0m0.278s | |
user 0m0.236s | |
sys 0m0.048s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment