This repository has been archived by the owner on May 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
raw_xbmc_database.py
92 lines (82 loc) · 3.03 KB
/
raw_xbmc_database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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(str):
global _RawXbmcDb__conn
if _RawXbmcDb__conn is None:
_RawXbmcDb__conn = _findXbmcDb()
Debug("[RawXbmcDb] query: "+str)
cursor = _RawXbmcDb__conn.cursor()
cursor.execute(str)
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(str):
return RawXbmcDb.query(str)
def _findXbmcDb():
import re
type = None
host = None
port = 3306
name = 'MyVideos'
user = None
passwd = None
version = re.findall( "<field>((?:[^<]|<(?!/))*)</field>", xbmc.executehttpapi("QueryVideoDatabase(SELECT idVersion FROM version)"),)[0]
Debug(version)
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")
files = os.listdir(path)
latest = ""
for file in files:
if file[:8] == 'MyVideos' and file[-3:] == '.db':
if file > latest:
latest = file
host = os.path.join(path,latest)
else:
host += version+".db"
Debug("[RawXbmcDb] Found sqlite3db: "+str(host))
import sqlite3
return sqlite3.connect(host)
if type == 'mysql':
if version >= 60:
database = name+version
else:
database = name
Debug("[RawXbmcDb] Found mysqldb: "+str(host)+":"+str(port)+", "+str(database))
import mysql.connector
return mysql.connector.Connect(host = str(host), port = int(port), database = str(database), user = str(user), password = str(passwd))