2020-05-09, 04:27
I just spent like four hours trying to get this seemingly simple task to work and after much banging of the head, it works. I figure why not document it here for anybody who might run across the same problems I did and how I got around them. If for nothing else, it's a handy place for me to find it again when I invariably forget and need it.
I've used linux a long time but I would never consider myself an expert, so some of this is probably "hackey". That's fine with me. Maybe there's a better way, but this worked.
Background on the need: I wanted a way to reset the watched status of a specific TV show without needing to do it one by one on every episode (some shows have lots of episodes!). I also only use kodi in "file mode", not "library mode". Right or wrong, maybe this is easier with a library or mysql setup, but I like it this way. It seems kodi used to be able to do this by marking an entire folder as watched, but that ability is gone in Krypton, so basically this is just a goofy workaround.
I also wanted it to be editable from the interface itself so that I could fairly quickly add a new "reset" function for a new TV series I may add in the future. Also, it would have to be somewhat intuitive so my wife can reset the status if she chooses (as opposed to me SSHing in to run a script).
I found this wonderful thread in my journey that told me everything I needed to know:
https://forum.kodi.tv/showthread.php?tid=346358
But the problem is, being a kodi novice, I really didn't know how to do any of the things it mentioned. That's what I'm trying to document here. Even simple things like when to use quotes and whatnot should all be captured here with exact syntax to make it work.
Things to know:
0. This is clunky, I know.
1. You'll need an add-on to "run" the command. "XBMC Commands" works perfectly.
2. You'll need a bash script to do the database "reset".
3. You'll need a python script to call the bash script. The reason for this is we need to pass it a parameter and you can't do that with system.exec and a bash script, so we need to call the python script with the parameter, which will then call the bash script with the parameter.
4. This is probably vulnerable to SQL injection because it happily passes the parameter onto the bash script. If your kodi is open to the world, this could be a very bad idea unless you sanitize the input first.
5. The library reset is admittedly a lazy hack. All it does is blast the records out of the path table where it finds a match to your parameter, it does NOT touch the file records. But because it'll get a new path record when you start watching the series again, the primary key will be new and all those file records will be "orphaned" and new ones created. This could be improved by joining path and files in the bash script for the delete, but I'm lazy.
On to the guts:
STEP 1:
Install the XBMC Commands add-on
STEP 2:
Create the bash script:
nano ~/.kodi/reset-library.sh
In the file, paste the following and CTRL-X,Y,Enter to save:
sqlite3 ~/.kodi/userdata/Database/MyVideos107.db "delete from path where strPath like \"%$1%\";"
I don't honestly remember if I needed to make it executable or not, so maybe for good measure:
chmod +x reset-library.sh
STEP 3:
Create the python script:
nano ~/.kodi/reset-library.py
In the file, paste the following and CTRL-X,Y,Enter to save:
#!/usr/bin/python
import os
import sys
os.system("~/.kodi/reset-library.sh '" + sys.argv[1]+"'")
STEP 4:
Now we just have to tell the scripts which TV show you want to clear the status for. I'm going to use the made-up "My Fab Show", you should edit this as necessary. NOTE - it will reset the status for all shows that have "My Fab Show" in the file PATH.
Back in the kodi interface, go into the XBMC Commands add-on:
1. Add command
2. Choose "Enter command"
3. Give it a title like "Reset My Fab Show"
4. Now for the command, this is where I had the most trouble of all, this needs to be exact AND what I found is that you can NOT use ~/.kodi. You MUST do /storage/.kodi! This is the exact syntax:
runscript(/storage/.kodi/reset-library.py, "My Fab Show")
Hit OK to save it and test it out, it should work!
I've used linux a long time but I would never consider myself an expert, so some of this is probably "hackey". That's fine with me. Maybe there's a better way, but this worked.
Background on the need: I wanted a way to reset the watched status of a specific TV show without needing to do it one by one on every episode (some shows have lots of episodes!). I also only use kodi in "file mode", not "library mode". Right or wrong, maybe this is easier with a library or mysql setup, but I like it this way. It seems kodi used to be able to do this by marking an entire folder as watched, but that ability is gone in Krypton, so basically this is just a goofy workaround.
I also wanted it to be editable from the interface itself so that I could fairly quickly add a new "reset" function for a new TV series I may add in the future. Also, it would have to be somewhat intuitive so my wife can reset the status if she chooses (as opposed to me SSHing in to run a script).
I found this wonderful thread in my journey that told me everything I needed to know:
https://forum.kodi.tv/showthread.php?tid=346358
But the problem is, being a kodi novice, I really didn't know how to do any of the things it mentioned. That's what I'm trying to document here. Even simple things like when to use quotes and whatnot should all be captured here with exact syntax to make it work.
Things to know:
0. This is clunky, I know.
1. You'll need an add-on to "run" the command. "XBMC Commands" works perfectly.
2. You'll need a bash script to do the database "reset".
3. You'll need a python script to call the bash script. The reason for this is we need to pass it a parameter and you can't do that with system.exec and a bash script, so we need to call the python script with the parameter, which will then call the bash script with the parameter.
4. This is probably vulnerable to SQL injection because it happily passes the parameter onto the bash script. If your kodi is open to the world, this could be a very bad idea unless you sanitize the input first.
5. The library reset is admittedly a lazy hack. All it does is blast the records out of the path table where it finds a match to your parameter, it does NOT touch the file records. But because it'll get a new path record when you start watching the series again, the primary key will be new and all those file records will be "orphaned" and new ones created. This could be improved by joining path and files in the bash script for the delete, but I'm lazy.
On to the guts:
STEP 1:
Install the XBMC Commands add-on
STEP 2:
Create the bash script:
nano ~/.kodi/reset-library.sh
In the file, paste the following and CTRL-X,Y,Enter to save:
sqlite3 ~/.kodi/userdata/Database/MyVideos107.db "delete from path where strPath like \"%$1%\";"
I don't honestly remember if I needed to make it executable or not, so maybe for good measure:
chmod +x reset-library.sh
STEP 3:
Create the python script:
nano ~/.kodi/reset-library.py
In the file, paste the following and CTRL-X,Y,Enter to save:
#!/usr/bin/python
import os
import sys
os.system("~/.kodi/reset-library.sh '" + sys.argv[1]+"'")
STEP 4:
Now we just have to tell the scripts which TV show you want to clear the status for. I'm going to use the made-up "My Fab Show", you should edit this as necessary. NOTE - it will reset the status for all shows that have "My Fab Show" in the file PATH.
Back in the kodi interface, go into the XBMC Commands add-on:
1. Add command
2. Choose "Enter command"
3. Give it a title like "Reset My Fab Show"
4. Now for the command, this is where I had the most trouble of all, this needs to be exact AND what I found is that you can NOT use ~/.kodi. You MUST do /storage/.kodi! This is the exact syntax:
runscript(/storage/.kodi/reset-library.py, "My Fab Show")
Hit OK to save it and test it out, it should work!