Kodi library update at the end of the task

Support for Synology NAS, QNAP NAS and other Embedded Linux systems
Post Reply
Eluc
Posts: 5
Joined: 04 Nov 2018, 20:57

Kodi library update at the end of the task

Post by Eluc »

Hello,
I'm using FileBot Node on Synology, it works (more or less) nicely except the Kodi library update. I have inserted the IP of the Kodi but it didn't worked. So I tried to insert user:psw@IP with user and psw from kodi webinterface but still it doesn't update library. Any clue what could be wrong ? did I miss a step ?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Kodi library update at the end of the task

Post by rednoah »

Note sure. But if the built-in Kodi feature doesn't work, then you can always use the --def exec parameter (called Execute in FileBot Node) to run arbitrary commands (e.g. curl commands to talk to Kodi).

:idea: Using curl to talk to Kodi yourself would also be the first step in figuring out why FileBot is not working (either by finding the same problem independent of FileBot, or finding it's a FileBot specific problem).
:idea: Please read the FAQ and How to Request Help.
Eluc
Posts: 5
Joined: 04 Nov 2018, 20:57

Re: Kodi library update at the end of the task

Post by Eluc »

I just did a curl command to update library from Windows to my Android Kodi and it works fine. I'll try to investigate more and if nothing else I'll add the command as you suggested.
xIntenso
Posts: 33
Joined: 14 Jan 2018, 23:39

Re: Kodi library update at the end of the task

Post by xIntenso »

Sorry to necro this thread, but did you ever solve this? I am interested in how you achieved this (if you succeeded).
Eluc
Posts: 5
Joined: 04 Nov 2018, 20:57

Re: Kodi library update at the end of the task

Post by Eluc »

xIntenso wrote: 06 Dec 2018, 15:13 Sorry to necro this thread, but did you ever solve this? I am interested in how you achieved this (if you succeeded).
Sorry but I didn't solve it properly. I did a dirty work around with a second task in Synology Task Scheduler that is executed a few minutes after my Filebot script.

I really hope that one day I can trigger Filebot after a torrent is completed and then trigger the library update right after Filebot completed the job but I didn't figure it out yet and I'm not even sure it's possible with a Synology.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Kodi library update at the end of the task

Post by rednoah »

What does your second task do then? Aren't you just calling a curl command? What curl command are you calling?
:idea: Please read the FAQ and How to Request Help.
robwiel
Posts: 41
Joined: 18 Mar 2013, 22:41

Re: Kodi library update at the end of the task

Post by robwiel »

is there a chance to replace kodi=host:port into something which work on password'ed installations? I use synology but windows option is to run this

start curl -i -X POST -d "{\"jsonrpc\": \"2.0\", \"method\": \"VideoLibrary.Scan\", \"id\": \"mybash\"}" -H "content-type:application/json" http://user:[email protected]:8080/jsonrpc > NUL 2>&1
robwiel
Posts: 41
Joined: 18 Mar 2013, 22:41

Re: Kodi library update at the end of the task

Post by robwiel »

Sooo

Code: Select all

filebot --def exec="curl -i -X POST -d "{\"jsonrpc\": \"2.0\", \"method\": \"VideoLibrary.Scan\", \"id\": \"mybash\"}" -H "content-type:application/json" http://user:[email protected]:8080/jsonrpc > NUL 2>&1"
would work?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Kodi library update at the end of the task

Post by rednoah »

For the sake of simplicity, I would create a separate update-kodi.sh bash script that does the job and can be tested independent of FileBot.

If it works, then you can just do:

Code: Select all

--def exec="/path/to/update-kodi.sh"

Unfortunately, the --def kodi parameter does not support username + password authentication. Best to stick with curl requests for that. If you're on Windows 10, then you can use Bash on Windows (i.e. WSL) to run Linux commands (or rewrite the command in PowerShell, or install curl binaries for Windows).
:idea: Please read the FAQ and How to Request Help.
User avatar
Axel Foley
Posts: 23
Joined: 27 Mar 2014, 15:47

Re: Kodi library update at the end of the task

Post by Axel Foley »

This is the ending part of my SortMedia.groovy script, after the filebot magic work ;), that wakes up my kodi host (kabylake intel nuc) via wake-on-lan call, and then starts a video rescan. Hope it's useful for someone.

@rednoah : I don't know if I can publish the complete SortMedia.groovy script somewhere, it could be helpful. I glued several things found in different scripts and added the WOL function.

Code: Select all

        def kodi            = ['kabylake.axel.dom'] // (use [] to not notify any XBMC instances about updates)
        def kodimacaddr     = ['F4:4D:30:6A:62:35']
        
	/*
	 *  make Kodi resume from suspend via WOL
	 */
	kodimacaddr.each { kodimac ->
		// Send Wake On LAN Magic Packet
		def broadcast = '255.255.255.255'
		def int wolport = 9

		// Read MAC address
		String mac = kodimac.replaceAll("-", "").replaceAll(":", "")
		byte[] macBytes = new byte[6]
		for (pos in 0..5) {
			 macBytes[pos] = Integer.valueOf(mac.substring(pos*2,pos*2+2), 16)
		}
		
		// Construct packet data
		byte[] data = new byte[6 + 16 * 6]
		for (i in 0..5) {
			data[i] = 0xff
		}
		for (i in 1..16) {
			System.arraycopy(macBytes, 0, data, i * 6, 6)
		}

		// Send packet
		InetAddress address = InetAddress.getByName(broadcast)
		DatagramPacket packet = new DatagramPacket(data, data.length, address, wolport)
		DatagramSocket socket = new DatagramSocket()
		socket.send(packet)
		socket.close()
		println "Wake-on-LAN sent to Kodi."
		
		// Let's wait 3s for host to resume
		println "Waiting 8s for Kodi to fully resume (network + MySql connection)."
		sleep(8000)
	}

	/*
	 *  make Kodi scan for new content
	 */
	kodi.each { host ->
		telnet(host, 9090) { writer, reader ->
			// API call for latest Kodi release
			msg = '{"id":1,"jsonrpc":"2.0","method":"VideoLibrary.Scan","params":[]}'
			writer.println(msg)
			println "Kodi Library Scan Requested."
		}
	}
eggsplorer
Posts: 12
Joined: 21 Jun 2019, 23:05

Re: Kodi library update at the end of the task

Post by eggsplorer »

---- Edit: ----
I am an Idiot. I worked on my NAS for so long that I used the same IP in order to address Kodi.
--def 'kodi=192.168.X.Y:8080' works like a charm... *embarrassed*
----------------

What does "update-kodi.sh" have to contain?

My routine JDownloader > EventScript > Filebot works as intended and this is how my AMC script looks like:

Code: Select all

#!/bin/sh
##FileBot benötigt diese Variablen
##/bin/mkdir /srv/dev-disk-by-label-WD3TB2/Medien/Downloads/media/testordner
LOG="/srv/dev-disk-by-label-WD3TB2/Medien/Downloads/filebot/amc.log"
EXC="/srv/dev-disk-by-label-WD3TB2/Medien/Downloads/filebot/amc.txt"
SERIEN="/srv/dev-disk-by-label-WD3TB2/Medien/Serien/{n}/Staffel {s}/{n} - {s00e00} - {t}"
FILME="/srv/dev-disk-by-label-WD3TB2/Medien/Downloads/Filme/{n} ({y}) {source}({vf}@{vc}) [{rating}]/{n} ({y}) {source}({vf}@{vc}) [{rating}]"
UNSORTIERT="/srv/dev-disk-by-label-WD3TB2/Medien/Downloads/unsortiert/{file.structurePathTail}" ### Wenn Filebot mal etwas nicht zuordnen kann, dann kannst du es in einen seperaten Ordner verschieben lassen, dann bleibt es im Downloadordner übersichtlich.
##FileBot ausführen
/usr/share/filebot/bin/filebot.sh -script fn:amc --lang de --log-file $LOG --action move "$1" --def "seriesFormat=$SERIEN" "movieFormat=$FILME" "unsortedFormat=$UNSORTIERT" -non-strict --def unsorted=y "artwork=n" --def clean=y --def 'kodi=192.168.2.121:8080'
On my Kodi (LibreElec) control via HTTP is activated and port 8080 was the default. User and Password are blank.
Sadly --def 'kodi=192.168.2.121:8080' doesn't work and results in this log file:

Code: Select all

Notify Kodi: [host:192.168.2.121, port:8080]
POST: http://192.168.2.121:8080/jsonrpc {"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"FileBot finished processing 1 files","message":"\u2022 tvs-mf-dd51-ded-dl-18p-azhd-x264-801\n\u2022 tvs-mf-dd51-ded-dl-18p-azhd-x264-801.part2\n\u2022 tvs-mf-dd51-ded-dl-18p-azhd-x264-801.part3\n\u2022 tvs-mf-dd51-dl-18p-azhd-x264-704.part4","image":"https://app.filebot.net/icon.png"},"id":1}
ConnectException: Verbindungsaufbau abgelehnt (Connection refused)
Is anything wrong with my setup?

Now I'd like to try your suggestion and simply call an "update-kodi.sh".
This is what I tried:

Code: Select all

curl -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"VideoLibrary.Scan","id":1}' http://192.168.2.121:8080/jsonrpc
But testing it results in a similar error:

Code: Select all

curl: (7) Failed to connect to 192.168.2.121 port 8080: Verbindungsaufbau abgelehnt
Any suggestion?

---- Edit: ----
I am an Idiot. I worked on my NAS for so long that I used the same IP in order to address Kodi.
--def 'kodi=192.168.X.Y:8080' works like a charm... *embarrassed*
----------------
Post Reply