-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
…b finding) direct access. Should solve #101, #61 the freezing of xbmc when syncing seen back to xbmc.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import os, xbmc | ||
from utilities import Debug | ||
#provides access to the raw xbmc video database | ||
|
||
|
||
global _RawXbmcDb__conn | ||
_RawXbmcDb__conn = None | ||
class RawXbmcDb(): | ||
|
||
# make a httpapi based XBMC db query (get data) | ||
@staticmethod | ||
def query(query): | ||
global _RawXbmcDb__conn | ||
if _RawXbmcDb__conn is None: | ||
_RawXbmcDb__conn = _findXbmcDb() | ||
|
||
Debug("[RawXbmcDb] query: "+query) | ||
cursor = _RawXbmcDb__conn.cursor() | ||
cursor.execute(query) | ||
|
||
matches = [] | ||
for row in cursor: | ||
matches.append(row) | ||
|
||
Debug("[RawXbmcDb] matches: "+unicode(matches)) | ||
|
||
_RawXbmcDb__conn.commit() | ||
cursor.close() | ||
return matches | ||
|
||
# execute a httpapi based XBMC db query (set data) | ||
@staticmethod | ||
def execute(query): | ||
global _RawXbmcDb__conn | ||
if _RawXbmcDb__conn is None: | ||
_RawXbmcDb__conn = _findXbmcDb() | ||
cursor = _RawXbmcDb__conn.cursor() | ||
Debug("[RawXbmcDb] query: "+query) | ||
cursor.execute(query) | ||
|
||
def _findXbmcDb(): | ||
type = None | ||
host = None | ||
port = 3306 | ||
name = None | ||
user = None | ||
passwd = None | ||
if not os.path.exists(xbmc.translatePath("special://userdata/advancedsettings.xml")): | ||
type = 'sqlite3' | ||
else: | ||
from xml.etree.ElementTree import ElementTree | ||
advancedsettings = ElementTree() | ||
advancedsettings.parse(xbmc.translatePath("special://userdata/advancedsettings.xml")) | ||
settings = advancedsettings.getroot().find("videodatabase") | ||
if settings is not None: | ||
for setting in settings: | ||
if setting.tag == 'type': | ||
type = setting.text | ||
elif setting.tag == 'host': | ||
host = setting.text | ||
elif setting.tag == 'port': | ||
port = setting.text | ||
elif setting.tag == 'name': | ||
name = setting.text | ||
elif setting.tag == 'user': | ||
user = setting.text | ||
elif setting.tag == 'pass': | ||
passwd = setting.text | ||
else: | ||
type = 'sqlite3' | ||
|
||
if type == 'sqlite3': | ||
if host is None: | ||
path = xbmc.translatePath("special://userdata/database") | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
files = os.listdir(path) | ||
latest = "" | ||
for file in files: | ||
if file[:8] == 'MyVideos': | ||
if file > latest: | ||
latest = file | ||
Debug(latest) | ||
host = os.path.join(path,latest) | ||
else: | ||
host += ".db" | ||
import sqlite3 | ||
return sqlite3.connect(host) | ||
if type == 'mysql': | ||
import mysql.connector | ||
return mysql.connector.Connect(host = host, port = port, database = name, user = user, password = passwd) | ||
|
3 comments
on commit 628395e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Been trying to figure out for a while now, how to get rid of the trailing comma python leaves,
18:13:00 T:2931813232 NOTICE: Trakt Utilities: [RawXbmcDb] query: SELECT movie.idFile FROM movie WHERE movie.c09='tt0468569'
18:13:00 T:2931813232 NOTICE: Trakt Utilities: [RawXbmcDb] matches: [(507,)]
18:13:00 T:2931813232 NOTICE: Trakt Utilities: [RawXbmcDb] query: UPDATE files SET playcount=1 WHERE idFile=(507,)
18:13:00 T:2931813232 ERROR: Error Type: <class 'sqlite3.OperationalError'>
18:13:00 T:2931813232 ERROR: Error Contents: near ",": syntax error
any clues on how I can fix this? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.replace(",","") would make the , disappear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better so solution is I'll patch that bit of code tonight, xbmc is actually correct it is a list of tuples, I should be extracting only the first element so the whole, comma and brackets would disappear.
Seems database needs to have upper case d on XBMCbuntu beta 3.