Hey everyone, I wanted to share a solution I came up with for automating Kodi library rescans. I found that sending direct curl commands through rules or bindings was too cumbersome due to character escaping issues. So, I decided to create a shell script to handle the rescan process. Here’s how I did it:
Step 1: Create the Shell Script
I wrote a simple bash script called kodi_rescan.sh that sends a JSON command to Kodi’s JSON-RPC endpoint. Here’s the script:
bash
#!/bin/bash
Kodi Video Library Scan
curl --data-binary ‘{ “jsonrpc”: “2.0”, “method”: “VideoLibrary.Scan”, “id”: “mybash”}’ -H ‘content-type: application/json;’ http://[user]:[pass]@[ip]:[port]/jsonrpc
Make sure to replace [user], [pass], [ip], and [port] with your Kodi machine’s actual credentials and IP address.
Step 2: Configure the Item and Sitemap
I added a new item in my .items file to represent the rescan button:
plaintext
Switch i_Kodi_Rescan “Video Library”
Then, I mapped this item in my .sitemap for easy access:
plaintext
Switch item=i_Kodi_Rescan mappings=[ON=“Rescan”]
Step 3: Set Up the Rule
Finally, I created a rule in my .rules file to execute the shell script when the button is pressed:
plaintext
rule “Kodi Video Library Scan”
when
Item i_Kodi_Rescan received command
then
val result = executeCommandLine(“/home/user/kodi_rescan.sh”, 5000)
logInfo(“Kodi Library Scan”, result)
end
This setup has been working perfectly for me, and I thought it might be helpful for others looking to automate their Kodi library rescans. Let me know if you have any questions or suggestions for improvement!
Cheers,
[Your Name]