From 85550ce1adac9888a7e8e2dc3e7b2b65ea69413a Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Fri, 13 Mar 2015 23:39:35 +0100 Subject: [PATCH] auto add new library sources to kodi database --- resources/lib/LibrarySync.py | 21 +++++++++++---------- resources/lib/Utils.py | 21 +++++++++++++++++---- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index 5bc2587a..217ad190 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -12,6 +12,7 @@ import urllib from datetime import datetime, timedelta, time import urllib2 import os + from xml.etree.ElementTree import Element, SubElement, Comment, tostring from xml.etree import ElementTree from xml.dom import minidom @@ -198,11 +199,11 @@ class LibrarySync(): root = Element("movie") SubElement(root, "id").text = item["Id"] - SubElement(root, "tag").text = item["Id"] + SubElement(root, "tag").text = "all mediabrowser movies" # TODO --> use tags to assign user view SubElement(root, "thumb").text = downloadUtils.getArtwork(item, "poster") - SubElement(root, "fanart").text = timeInfo.get('Backdrop') + SubElement(root, "fanart").text = downloadUtils.getArtwork(item, "Backdrop") SubElement(root, "title").text = item["Name"].encode('utf-8').decode('utf-8') - SubElement(root, "originaltitle").text = item["Id"] + SubElement(root, "originaltitle").text = item["Name"].encode('utf-8').decode('utf-8') SubElement(root, "year").text = str(item.get("ProductionYear")) SubElement(root, "runtime").text = str(timeInfo.get('Duration')) @@ -210,14 +211,14 @@ class LibrarySync(): fileinfo = SubElement(root, "fileinfo") streamdetails = SubElement(fileinfo, "streamdetails") video = SubElement(streamdetails, "video") - SubElement(video, "duration").text = str(timeInfo.get('totaltime')) - SubElement(video, "aspect").text = timeInfo.get('aspectratio') - SubElement(video, "codec").text = timeInfo.get('videocodec') - SubElement(video, "width").text = str(timeInfo.get('width')) - SubElement(video, "height").text = str(timeInfo.get('height')) + SubElement(video, "duration").text = str(mediaStreams.get('totaltime')) + SubElement(video, "aspect").text = mediaStreams.get('aspectratio') + SubElement(video, "codec").text = mediaStreams.get('videocodec') + SubElement(video, "width").text = str(mediaStreams.get('width')) + SubElement(video, "height").text = str(mediaStreams.get('height')) audio = SubElement(streamdetails, "audio") - SubElement(audio, "codec").text = timeInfo.get('audiocodec') - SubElement(audio, "channels").text = timeInfo.get('channels') + SubElement(audio, "codec").text = mediaStreams.get('audiocodec') + SubElement(audio, "channels").text = mediaStreams.get('channels') SubElement(root, "plot").text = API().getOverview(item).decode('utf-8') diff --git a/resources/lib/Utils.py b/resources/lib/Utils.py index dd6dca90..52e2220b 100644 --- a/resources/lib/Utils.py +++ b/resources/lib/Utils.py @@ -8,6 +8,8 @@ import xbmcaddon import xbmcvfs import json import os + +import sqlite3 import inspect from xml.etree.ElementTree import Element, SubElement, Comment, tostring from xml.etree import ElementTree @@ -70,10 +72,10 @@ def checkKodiSources(): rebootRequired = False if not "mediabrowser_movies" in allKodiSources: - addKodiSource("mediabrowser_movies",movieLibrary) + addKodiSource("mediabrowser_movies",movieLibrary,"movies") rebootRequired = True if not "mediabrowser_tvshows" in allKodiSources: - addKodiSource("mediabrowser_tvshows",tvLibrary) + addKodiSource("mediabrowser_tvshows",tvLibrary,"tvshows") rebootRequired = True if rebootRequired: @@ -81,7 +83,7 @@ def checkKodiSources(): if ret: xbmc.executebuiltin("RestartApp") -def addKodiSource(name, path): +def addKodiSource(name, path, type): userDataPath = xbmc.translatePath( "special://profile" ) sourcesFile = os.path.join(userDataPath,'sources.xml') @@ -103,8 +105,19 @@ def addKodiSource(name, path): source = SubElement(videosources,'source') SubElement(source, "name").text = name SubElement(source, "path").text = path - tree.write(sourcesFile) + + #add new source to database + dbPath = xbmc.translatePath("special://userdata/Database/MyVideos90.db") + connection = sqlite3.connect(dbPath) + cursor = connection.cursor( ) + cursor.execute("select coalesce(max(idPath),0) as pathId from path") + pathId = cursor.fetchone()[0] + pathId = pathId + 1 + pathsql="insert into path(idPath, strPath, strContent, strScraper, strHash, scanRecursive) values(?, ?, ?, ?, ?, ?)" + cursor.execute(pathsql, (pathId,path + "\\",type,"metadata.local",None,2147483647)) + connection.commit() + cursor.close() def checkAuthentication(): #check authentication