diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy index a5d11141..d304b3c7 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy +++ b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy @@ -83,7 +83,7 @@ String.metaClass.getXml = { new XmlParser().parseText(delegate) } URL.metaClass.get = { delegate.getText() } 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 = { 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 } URL.metaClass.saveAs = { f -> fetch(delegate).saveAs(f) } diff --git a/website/scripts/amc.groovy b/website/scripts/amc.groovy index c06dc8c6..1e5afadc 100644 --- a/website/scripts/amc.groovy +++ b/website/scripts/amc.groovy @@ -212,9 +212,12 @@ if (getRenameLog().isEmpty()) { } // make xbmc or plex scan for new content -xbmc?.each{ - println "Notify XBMC: $it" - invokeScanVideoLibrary(it) +xbmc?.each{ host -> + println "Notify XBMC: $host" + _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{ diff --git a/website/scripts/lib/htpc.groovy b/website/scripts/lib/htpc.groovy index 2678bfbd..9c7dd645 100644 --- a/website/scripts/lib/htpc.groovy +++ b/website/scripts/lib/htpc.groovy @@ -1,19 +1,29 @@ import static net.sourceforge.filebot.WebServices.* +import static groovy.json.StringEscapeUtils.* import groovy.xml.* import net.sourceforge.filebot.mediainfo.* - /** * XBMC helper functions */ -def invokeScanVideoLibrary(host, port = 9090) { - _guarded { - telnet(host, port) { writer, reader -> - writer.println('{"id":1,"method":"VideoLibrary.Scan","params":[],"jsonrpc":"2.0"}') // API call for latest XBMC release - } +def XBMC(host, port = 8080) { + new XBMCJsonRpc(endpoint:new URL("http://${host}:${port}/jsonrpc")) +} + +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}""") } }