* support XBMC Frodo JSON-RPC calls: VideoLibrary.Scan, GUI.ShowNotification
This commit is contained in:
parent
2d672c17c7
commit
07f6bb9ec3
|
@ -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) }
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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}""")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue