* added plex integration sample

This commit is contained in:
Reinhard Pointner 2012-07-10 05:14:43 +00:00
parent 2217eed537
commit 24ea7ab334
2 changed files with 15 additions and 1 deletions

View File

@ -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 = { 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, 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) } URL.metaClass.saveAs = { f -> fetch(delegate).saveAs(f) }
String.metaClass.saveAs = { f, csn = "utf-8" -> Charset.forName(csn).encode(delegate).saveAs(f) } String.metaClass.saveAs = { f, csn = "utf-8" -> Charset.forName(csn).encode(delegate).saveAs(f) }

View File

@ -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()
}
}