2020-04-04, 12:07
Hi
I am currently running daily builds of LibrELEC with a Docker container running Emby server. I prefer to use Kodi when on the device for its database, navigation etc but Emby is to facilitate usage on another tv in the house. This works well other than I end up with playcounts of videos that are out of sync so i have to remember what i have and haven't watched or go and look where I am up to at times. Currently the Emby for Kodi addon doesnt support Python 3 so i cant even investigate if that would be the solution so in the interim I had hoped a basic Pythoin script running within cron would solve my problem seeing as all the media is on the same paths I could cross match and fix the playcounts automatically. For some reason the script calculates the correct playcounts, runs the update table queries seemingly succesfully but still the apps (Kodi and Emby) are both out of sync. Can anyone see what I am doing wrong here for both or at least the Kodi side of this?
Thanks
I am currently running daily builds of LibrELEC with a Docker container running Emby server. I prefer to use Kodi when on the device for its database, navigation etc but Emby is to facilitate usage on another tv in the house. This works well other than I end up with playcounts of videos that are out of sync so i have to remember what i have and haven't watched or go and look where I am up to at times. Currently the Emby for Kodi addon doesnt support Python 3 so i cant even investigate if that would be the solution so in the interim I had hoped a basic Pythoin script running within cron would solve my problem seeing as all the media is on the same paths I could cross match and fix the playcounts automatically. For some reason the script calculates the correct playcounts, runs the update table queries seemingly succesfully but still the apps (Kodi and Emby) are both out of sync. Can anyone see what I am doing wrong here for both or at least the Kodi side of this?
Thanks
python:
#!/usr/bin/env python3
import sqlite3
import os
import time
import datetime
os.system('docker stop emby')
os.system('systemctl stop kodi')
os.system('systemctl stop kodi')
time.sleep(15)
conK = sqlite3.connect('/storage/.kodi/userdata/Database/MyVideos116.db')
curK = conK.cursor()
conE = sqlite3.connect('/storage/.emby/data/library.db')
curE = conE.cursor()
curK.execute("select strPath || strFilename path, playcount, f.idfile from files f join path p on p.iDpath = f.idPath where path like '%' order by path;")
curE.execute("select path, playcount, u.userdatakeyid from mediaitems m join userdatas u on m.userdatakeyid = u.userdatakeyid where path like '%' order by path;")
p = {}
k = {}
e = {}
for rowK in curK:
r = rowK[0].lower()
if str(rowK[1]) == 'None':
p[r] = 0
else:
p[r] = rowK[1]
k[r] = rowK[2]
for rowE in curE:
r = rowE[0].lower()
if str(rowE[1]) == 'None':
if not r in p:
p[r] = 0
else:
if r in p:
if rowE[1] > p[r]:
p[r] = rowE[1]
else:
p[r] = rowE[1]
e[r] = rowE[2]
for key in k:
conK.execute('update files set lastplayed = "2020-01-01 00:00:00", playcount = ' + str(p[key]) + ' where idfile = ' + str(k[key]) + ';')
for key in e:
conE.execute('update userdatas set played = 1, playcount = ' + str(p[key]) + ' where userdatakeyid = ' + str(e[key]) + ';')
curK.close()
conK.close()
curE.close()
conE.close()
time.sleep(5)
os.system('systemctl start kodi')
os.system('systemctl start kodi')
os.system('docker start emby')