Page 1 of 1

[POC] Custom Format Server

Posted: 19 Dec 2021, 04:28
by rednoah
Proof of Concept:

Externalize format logic to a remote custom service.



Client Format:

Format: Select all

{ json('http://localhost:8080/'.toURL(f:f)) }

:!: json() will cache the response. Add System.currentTimeMillis() to the URL as cache buster during development:

Format: Select all

{ json('http://localhost:8080/'.toURL(f:f, time:System.currentTimeMillis())) }


Client Command:

Console Output: Select all

$ filebot -rename *.mp4 --db file --format "{ json('http://localhost:8080/'.toURL(f:f)) }" --action TEST --log INFO
[TEST] from [The.Man.from.Earth.2007.mp4] to [THE_MAN_FROM_EARTH_2007.mp4]


Server Log:

Console Output: Select all

$ ./server-node.js
{ src: 'The.Man.from.Earth.2007', dst: 'THE_MAN_FROM_EARTH_2007' }


Server Code:

javascript: Select all

#!/usr/bin/env node

const http = require('http')
const url = require('url')
const path = require('path')


const handler = (request, response) => {
	const query = url.parse(request.url, true).query
	const f = query['f']

	const src = path.parse(f).name
	const dst = src.toUpperCase().replace(/[^A-Z0-9]/g, '_')

	console.log({src: src, dst: dst})

	response.writeHead(200)
	response.end(JSON.stringify(dst))
}


const server = http.createServer(handler)
server.listen(8080)