From 24ea7ab33463b27293f0641dd357648cc16cbb49 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 10 Jul 2012 05:14:43 +0000 Subject: [PATCH] * added plex integration sample --- .../sourceforge/filebot/cli/ScriptShell.lib.groovy | 2 +- website/scripts/lib/plex.groovy | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 website/scripts/lib/plex.groovy diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy index 6833abf1..4a1235d3 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy +++ b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy @@ -75,7 +75,7 @@ URL.metaClass.post = { Map parameters -> post(delegate.openConnection(), paramet 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') } -ByteBuffer.metaClass.saveAs = { f -> f = f as File; f.parentFile.mkdirs(); writeFile(delegate.duplicate(), f); f.absoluteFile } +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) } String.metaClass.saveAs = { f, csn = "utf-8" -> Charset.forName(csn).encode(delegate).saveAs(f) } diff --git a/website/scripts/lib/plex.groovy b/website/scripts/lib/plex.groovy new file mode 100644 index 00000000..7ceac9b7 --- /dev/null +++ b/website/scripts/lib/plex.groovy @@ -0,0 +1,14 @@ +// plex functions +def refreshPlexLibrary(server, port = 32400, files = null) { + def sections = new URL("http://$server:$port/plex").getXml() + def locations = sections.Directory.Location.collect{ [path:it.'@path', key:it.parent().'@key'] } + + // limit refresh locations + if (files != null) { + locations = locations.findAll{ loc -> files.find{ it.path; it.path.startsWith(loc.path) }} + } + + locations*.key.unique().each{ key -> + new URL("http://$server:$port/library/sections/$key/refresh/").get() + } +}