* support XBMC Frodo JSON-RPC calls: VideoLibrary.Scan, GUI.ShowNotification

This commit is contained in:
Reinhard Pointner 2013-02-26 19:40:24 +00:00
parent 2d672c17c7
commit 07f6bb9ec3
3 changed files with 23 additions and 10 deletions

View File

@ -83,7 +83,7 @@ String.metaClass.getXml = { new XmlParser().parseText(delegate) }
URL.metaClass.get = { delegate.getText() } URL.metaClass.get = { delegate.getText() }
URL.metaClass.post = { Map parameters -> post(delegate.openConnection(), parameters) } URL.metaClass.post = { Map parameters -> post(delegate.openConnection(), parameters) }
URL.metaClass.post = { byte[] data, contentType = 'application/octet-stream' -> post(delegate.openConnection(), data, contentType) } URL.metaClass.post = { byte[] data, contentType = 'application/octet-stream' -> post(delegate.openConnection(), data, contentType) }
URL.metaClass.post = { String text, csn = 'utf-8' -> delegate.post(text.getBytes(csn), 'text/plain') } URL.metaClass.post = { String text, contentType = 'text/plain', csn = 'utf-8' -> delegate.post(text.getBytes(csn), contentType) }
ByteBuffer.metaClass.saveAs = { f -> f = f as File; f = f.absoluteFile; f.parentFile.mkdirs(); writeFile(delegate.duplicate(), f); f } ByteBuffer.metaClass.saveAs = { f -> f = f as File; f = f.absoluteFile; f.parentFile.mkdirs(); writeFile(delegate.duplicate(), f); f }
URL.metaClass.saveAs = { f -> fetch(delegate).saveAs(f) } URL.metaClass.saveAs = { f -> fetch(delegate).saveAs(f) }

View File

@ -212,9 +212,12 @@ if (getRenameLog().isEmpty()) {
} }
// make xbmc or plex scan for new content // make xbmc or plex scan for new content
xbmc?.each{ xbmc?.each{ host ->
println "Notify XBMC: $it" println "Notify XBMC: $host"
invokeScanVideoLibrary(it) _guarded{
XBMC(host, 8080).showNotification('FileBot', "Finished processing ${tryQuietly { ut_title } ?: input*.dir.name.unique()} (${getRenameLog().size()} files).", 'http://filebot.sourceforge.net/images/icon.png')
XBMC(host, 8080).scanVideoLibrary()
}
} }
plex?.each{ plex?.each{

View File

@ -1,19 +1,29 @@
import static net.sourceforge.filebot.WebServices.* import static net.sourceforge.filebot.WebServices.*
import static groovy.json.StringEscapeUtils.*
import groovy.xml.* import groovy.xml.*
import net.sourceforge.filebot.mediainfo.* import net.sourceforge.filebot.mediainfo.*
/** /**
* XBMC helper functions * XBMC helper functions
*/ */
def invokeScanVideoLibrary(host, port = 9090) { def XBMC(host, port = 8080) {
_guarded { new XBMCJsonRpc(endpoint:new URL("http://${host}:${port}/jsonrpc"))
telnet(host, port) { writer, reader ->
writer.println('{"id":1,"method":"VideoLibrary.Scan","params":[],"jsonrpc":"2.0"}') // API call for latest XBMC release
} }
class XBMCJsonRpc {
def endpoint
def invoke(json) {
endpoint.post(json.getBytes('UTF-8'), 'application/json').text
}
def scanVideoLibrary() {
invoke("""{"jsonrpc":"2.0","method":"VideoLibrary.Scan","id":1}""")
}
def showNotification(title, message, image) {
invoke("""{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"${escapeJavaScript(title)}","message":"${escapeJavaScript(message)}", "image":"${escapeJavaScript(image)}"},"id":1}""")
} }
} }