[POC] Custom Format Server

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
User avatar
The Source
Posts: 22974
Joined: 16 Nov 2011, 08:59
Location: Taipei

[POC] Custom Format Server

Post 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})


const server = http.createServer(handler)
:idea: Please read the FAQ and How to Request Help.
Post Reply