self cursor
This commit is contained in:
parent
47beade09a
commit
75414f5f07
1 changed files with 303 additions and 324 deletions
|
@ -1,325 +1,304 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
import utils
|
import utils
|
||||||
import clientinfo
|
import clientinfo
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
|
|
||||||
class Embydb_Functions():
|
class Embydb_Functions():
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, embycursor):
|
def __init__(self, embycursor):
|
||||||
|
|
||||||
self.embycursor = embycursor
|
self.embycursor = embycursor
|
||||||
|
|
||||||
self.clientInfo = clientinfo.ClientInfo()
|
self.clientInfo = clientinfo.ClientInfo()
|
||||||
self.addonName = self.clientInfo.getAddonName()
|
self.addonName = self.clientInfo.getAddonName()
|
||||||
|
|
||||||
def logMsg(self, msg, lvl=1):
|
def logMsg(self, msg, lvl=1):
|
||||||
|
|
||||||
className = self.__class__.__name__
|
className = self.__class__.__name__
|
||||||
utils.logMsg("%s %s" % (self.addonName, className), msg, lvl)
|
utils.logMsg("%s %s" % (self.addonName, className), msg, lvl)
|
||||||
|
|
||||||
def getViews(self):
|
def getViews(self):
|
||||||
|
|
||||||
embycursor = self.embycursor
|
views = []
|
||||||
views = []
|
|
||||||
|
query = ' '.join((
|
||||||
query = ' '.join((
|
|
||||||
|
"SELECT view_id",
|
||||||
"SELECT view_id",
|
"FROM view"
|
||||||
"FROM view"
|
))
|
||||||
))
|
self.embycursor.execute(query)
|
||||||
embycursor.execute(query)
|
rows = self.embycursor.fetchall()
|
||||||
rows = embycursor.fetchall()
|
for row in rows:
|
||||||
for row in rows:
|
views.append(row[0])
|
||||||
views.append(row[0])
|
|
||||||
|
return views
|
||||||
return views
|
|
||||||
|
def getView_byId(self, viewid):
|
||||||
def getView_byId(self, viewid):
|
|
||||||
|
|
||||||
embycursor = self.embycursor
|
query = ' '.join((
|
||||||
|
|
||||||
query = ' '.join((
|
"SELECT view_name, media_type, kodi_tagid",
|
||||||
|
"FROM view",
|
||||||
"SELECT view_name, media_type, kodi_tagid",
|
"WHERE view_id = ?"
|
||||||
"FROM view",
|
))
|
||||||
"WHERE view_id = ?"
|
self.embycursor.execute(query, (viewid,))
|
||||||
))
|
view = self.embycursor.fetchone()
|
||||||
embycursor.execute(query, (viewid,))
|
|
||||||
view = embycursor.fetchone()
|
return view
|
||||||
|
|
||||||
return view
|
def getView_byType(self, mediatype):
|
||||||
|
|
||||||
def getView_byType(self, mediatype):
|
views = []
|
||||||
|
|
||||||
embycursor = self.embycursor
|
query = ' '.join((
|
||||||
views = []
|
|
||||||
|
"SELECT view_id, view_name",
|
||||||
query = ' '.join((
|
"FROM view",
|
||||||
|
"WHERE media_type = ?"
|
||||||
"SELECT view_id, view_name",
|
))
|
||||||
"FROM view",
|
self.embycursor.execute(query, (mediatype,))
|
||||||
"WHERE media_type = ?"
|
rows = self.embycursor.fetchall()
|
||||||
))
|
for row in rows:
|
||||||
embycursor.execute(query, (mediatype,))
|
views.append({
|
||||||
rows = embycursor.fetchall()
|
|
||||||
for row in rows:
|
'id': row[0],
|
||||||
views.append({
|
'name': row[1]
|
||||||
|
})
|
||||||
'id': row[0],
|
|
||||||
'name': row[1]
|
return views
|
||||||
})
|
|
||||||
|
def getView_byName(self, tagname):
|
||||||
return views
|
|
||||||
|
query = ' '.join((
|
||||||
def getView_byName(self, tagname):
|
|
||||||
|
"SELECT view_id",
|
||||||
embycursor = self.embycursor
|
"FROM view",
|
||||||
|
"WHERE view_name = ?"
|
||||||
query = ' '.join((
|
))
|
||||||
|
self.embycursor.execute(query, (tagname,))
|
||||||
"SELECT view_id",
|
try:
|
||||||
"FROM view",
|
view = self.embycursor.fetchone()[0]
|
||||||
"WHERE view_name = ?"
|
|
||||||
))
|
except TypeError:
|
||||||
embycursor.execute(query, (tagname,))
|
view = None
|
||||||
try:
|
|
||||||
view = embycursor.fetchone()[0]
|
return view
|
||||||
|
|
||||||
except TypeError:
|
def addView(self, embyid, name, mediatype, tagid):
|
||||||
view = None
|
|
||||||
|
query = (
|
||||||
return view
|
'''
|
||||||
|
INSERT INTO view(
|
||||||
def addView(self, embyid, name, mediatype, tagid):
|
view_id, view_name, media_type, kodi_tagid)
|
||||||
|
|
||||||
query = (
|
VALUES (?, ?, ?, ?)
|
||||||
'''
|
'''
|
||||||
INSERT INTO view(
|
)
|
||||||
view_id, view_name, media_type, kodi_tagid)
|
self.embycursor.execute(query, (embyid, name, mediatype, tagid))
|
||||||
|
|
||||||
VALUES (?, ?, ?, ?)
|
def updateView(self, name, tagid, mediafolderid):
|
||||||
'''
|
|
||||||
)
|
query = ' '.join((
|
||||||
self.embycursor.execute(query, (embyid, name, mediatype, tagid))
|
|
||||||
|
"UPDATE view",
|
||||||
def updateView(self, name, tagid, mediafolderid):
|
"SET view_name = ?, kodi_tagid = ?",
|
||||||
|
"WHERE view_id = ?"
|
||||||
query = ' '.join((
|
))
|
||||||
|
self.embycursor.execute(query, (name, tagid, mediafolderid))
|
||||||
"UPDATE view",
|
|
||||||
"SET view_name = ?, kodi_tagid = ?",
|
def removeView(self, viewid):
|
||||||
"WHERE view_id = ?"
|
|
||||||
))
|
query = ' '.join((
|
||||||
self.embycursor.execute(query, (name, tagid, mediafolderid))
|
|
||||||
|
"DELETE FROM view",
|
||||||
def removeView(self, viewid):
|
"WHERE view_id = ?"
|
||||||
|
))
|
||||||
query = ' '.join((
|
self.embycursor.execute(query, (viewid,))
|
||||||
|
|
||||||
"DELETE FROM view",
|
def getItem_byId(self, embyid):
|
||||||
"WHERE view_id = ?"
|
|
||||||
))
|
query = ' '.join((
|
||||||
self.embycursor.execute(query, (viewid,))
|
|
||||||
|
"SELECT kodi_id, kodi_fileid, kodi_pathid, parent_id, media_type, emby_type",
|
||||||
def getItem_byId(self, embyid):
|
"FROM emby",
|
||||||
|
"WHERE emby_id = ?"
|
||||||
embycursor = self.embycursor
|
))
|
||||||
|
try:
|
||||||
query = ' '.join((
|
self.embycursor.execute(query, (embyid,))
|
||||||
|
item = self.embycursor.fetchone()
|
||||||
"SELECT kodi_id, kodi_fileid, kodi_pathid, parent_id, media_type, emby_type",
|
return item
|
||||||
"FROM emby",
|
except: return None
|
||||||
"WHERE emby_id = ?"
|
|
||||||
))
|
def getItem_byWildId(self, embyid):
|
||||||
try:
|
|
||||||
embycursor.execute(query, (embyid,))
|
query = ' '.join((
|
||||||
item = embycursor.fetchone()
|
|
||||||
return item
|
"SELECT kodi_id, media_type",
|
||||||
except: return None
|
"FROM emby",
|
||||||
|
"WHERE emby_id LIKE ?"
|
||||||
def getItem_byWildId(self, embyid):
|
))
|
||||||
|
self.embycursor.execute(query, (embyid+"%",))
|
||||||
embycursor = self.embycursor
|
items = self.embycursor.fetchall()
|
||||||
|
|
||||||
query = ' '.join((
|
return items
|
||||||
|
|
||||||
"SELECT kodi_id, media_type",
|
def getItem_byView(self, mediafolderid):
|
||||||
"FROM emby",
|
|
||||||
"WHERE emby_id LIKE ?"
|
query = ' '.join((
|
||||||
))
|
|
||||||
embycursor.execute(query, (embyid+"%",))
|
"SELECT kodi_id",
|
||||||
items = embycursor.fetchall()
|
"FROM emby",
|
||||||
|
"WHERE media_folder = ?"
|
||||||
return items
|
))
|
||||||
|
self.embycursor.execute(query, (mediafolderid,))
|
||||||
def getItem_byView(self, mediafolderid):
|
items = self.embycursor.fetchall()
|
||||||
|
|
||||||
embycursor = self.embycursor
|
return items
|
||||||
|
|
||||||
query = ' '.join((
|
def getItem_byKodiId(self, kodiid, mediatype):
|
||||||
|
|
||||||
"SELECT kodi_id",
|
query = ' '.join((
|
||||||
"FROM emby",
|
|
||||||
"WHERE media_folder = ?"
|
"SELECT emby_id, parent_id",
|
||||||
))
|
"FROM emby",
|
||||||
embycursor.execute(query, (mediafolderid,))
|
"WHERE kodi_id = ?",
|
||||||
items = embycursor.fetchall()
|
"AND media_type = ?"
|
||||||
|
))
|
||||||
return items
|
self.embycursor.execute(query, (kodiid, mediatype,))
|
||||||
|
item = self.embycursor.fetchone()
|
||||||
def getItem_byKodiId(self, kodiid, mediatype):
|
|
||||||
|
return item
|
||||||
embycursor = self.embycursor
|
|
||||||
|
def getItem_byParentId(self, parentid, mediatype):
|
||||||
query = ' '.join((
|
|
||||||
|
query = ' '.join((
|
||||||
"SELECT emby_id, parent_id",
|
|
||||||
"FROM emby",
|
"SELECT emby_id, kodi_id, kodi_fileid",
|
||||||
"WHERE kodi_id = ?",
|
"FROM emby",
|
||||||
"AND media_type = ?"
|
"WHERE parent_id = ?",
|
||||||
))
|
"AND media_type = ?"
|
||||||
embycursor.execute(query, (kodiid, mediatype,))
|
))
|
||||||
item = embycursor.fetchone()
|
self.embycursor.execute(query, (parentid, mediatype,))
|
||||||
|
items = self.embycursor.fetchall()
|
||||||
return item
|
|
||||||
|
return items
|
||||||
def getItem_byParentId(self, parentid, mediatype):
|
|
||||||
|
def getItemId_byParentId(self, parentid, mediatype):
|
||||||
embycursor = self.embycursor
|
|
||||||
|
query = ' '.join((
|
||||||
query = ' '.join((
|
|
||||||
|
"SELECT emby_id, kodi_id",
|
||||||
"SELECT emby_id, kodi_id, kodi_fileid",
|
"FROM emby",
|
||||||
"FROM emby",
|
"WHERE parent_id = ?",
|
||||||
"WHERE parent_id = ?",
|
"AND media_type = ?"
|
||||||
"AND media_type = ?"
|
))
|
||||||
))
|
self.embycursor.execute(query, (parentid, mediatype,))
|
||||||
embycursor.execute(query, (parentid, mediatype,))
|
items = self.embycursor.fetchall()
|
||||||
items = embycursor.fetchall()
|
|
||||||
|
return items
|
||||||
return items
|
|
||||||
|
def getChecksum(self, mediatype):
|
||||||
def getItemId_byParentId(self, parentid, mediatype):
|
|
||||||
|
query = ' '.join((
|
||||||
embycursor = self.embycursor
|
|
||||||
|
"SELECT emby_id, checksum",
|
||||||
query = ' '.join((
|
"FROM emby",
|
||||||
|
"WHERE emby_type = ?"
|
||||||
"SELECT emby_id, kodi_id",
|
))
|
||||||
"FROM emby",
|
self.embycursor.execute(query, (mediatype,))
|
||||||
"WHERE parent_id = ?",
|
items = self.embycursor.fetchall()
|
||||||
"AND media_type = ?"
|
|
||||||
))
|
return items
|
||||||
embycursor.execute(query, (parentid, mediatype,))
|
|
||||||
items = embycursor.fetchall()
|
def getMediaType_byId(self, embyid):
|
||||||
|
|
||||||
return items
|
query = ' '.join((
|
||||||
|
|
||||||
def getChecksum(self, mediatype):
|
"SELECT emby_type",
|
||||||
|
"FROM emby",
|
||||||
embycursor = self.embycursor
|
"WHERE emby_id = ?"
|
||||||
|
))
|
||||||
query = ' '.join((
|
self.embycursor.execute(query, (embyid,))
|
||||||
|
try:
|
||||||
"SELECT emby_id, checksum",
|
itemtype = self.embycursor.fetchone()[0]
|
||||||
"FROM emby",
|
|
||||||
"WHERE emby_type = ?"
|
except TypeError:
|
||||||
))
|
itemtype = None
|
||||||
embycursor.execute(query, (mediatype,))
|
|
||||||
items = embycursor.fetchall()
|
return itemtype
|
||||||
|
|
||||||
return items
|
def sortby_mediaType(self, itemids, unsorted=True):
|
||||||
|
|
||||||
def getMediaType_byId(self, embyid):
|
sorted_items = {}
|
||||||
|
|
||||||
embycursor = self.embycursor
|
for itemid in itemids:
|
||||||
|
|
||||||
query = ' '.join((
|
mediatype = self.getMediaType_byId(itemid)
|
||||||
|
if mediatype:
|
||||||
"SELECT emby_type",
|
sorted_items.setdefault(mediatype, []).append(itemid)
|
||||||
"FROM emby",
|
elif unsorted:
|
||||||
"WHERE emby_id = ?"
|
sorted_items.setdefault('Unsorted', []).append(itemid)
|
||||||
))
|
|
||||||
embycursor.execute(query, (embyid,))
|
return sorted_items
|
||||||
try:
|
|
||||||
itemtype = embycursor.fetchone()[0]
|
def addReference(self, embyid, kodiid, embytype, mediatype, fileid=None, pathid=None,
|
||||||
|
parentid=None, checksum=None, mediafolderid=None):
|
||||||
except TypeError:
|
query = (
|
||||||
itemtype = None
|
'''
|
||||||
|
INSERT OR REPLACE INTO emby(
|
||||||
return itemtype
|
emby_id, kodi_id, kodi_fileid, kodi_pathid, emby_type, media_type, parent_id,
|
||||||
|
checksum, media_folder)
|
||||||
def sortby_mediaType(self, itemids, unsorted=True):
|
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
sorted_items = {}
|
'''
|
||||||
|
)
|
||||||
for itemid in itemids:
|
self.embycursor.execute(query, (embyid, kodiid, fileid, pathid, embytype, mediatype,
|
||||||
|
parentid, checksum, mediafolderid))
|
||||||
mediatype = self.getMediaType_byId(itemid)
|
|
||||||
if mediatype:
|
def updateReference(self, embyid, checksum):
|
||||||
sorted_items.setdefault(mediatype, []).append(itemid)
|
|
||||||
elif unsorted:
|
query = "UPDATE emby SET checksum = ? WHERE emby_id = ?"
|
||||||
sorted_items.setdefault('Unsorted', []).append(itemid)
|
self.embycursor.execute(query, (checksum, embyid))
|
||||||
|
|
||||||
return sorted_items
|
def updateParentId(self, embyid, parent_kodiid):
|
||||||
|
|
||||||
def addReference(self, embyid, kodiid, embytype, mediatype, fileid=None, pathid=None,
|
query = "UPDATE emby SET parent_id = ? WHERE emby_id = ?"
|
||||||
parentid=None, checksum=None, mediafolderid=None):
|
self.embycursor.execute(query, (parent_kodiid, embyid))
|
||||||
query = (
|
|
||||||
'''
|
def removeItems_byParentId(self, parent_kodiid, mediatype):
|
||||||
INSERT OR REPLACE INTO emby(
|
|
||||||
emby_id, kodi_id, kodi_fileid, kodi_pathid, emby_type, media_type, parent_id,
|
query = ' '.join((
|
||||||
checksum, media_folder)
|
|
||||||
|
"DELETE FROM emby",
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
"WHERE parent_id = ?",
|
||||||
'''
|
"AND media_type = ?"
|
||||||
)
|
))
|
||||||
self.embycursor.execute(query, (embyid, kodiid, fileid, pathid, embytype, mediatype,
|
self.embycursor.execute(query, (parent_kodiid, mediatype,))
|
||||||
parentid, checksum, mediafolderid))
|
|
||||||
|
def removeItem_byKodiId(self, kodiid, mediatype):
|
||||||
def updateReference(self, embyid, checksum):
|
|
||||||
|
query = ' '.join((
|
||||||
query = "UPDATE emby SET checksum = ? WHERE emby_id = ?"
|
|
||||||
self.embycursor.execute(query, (checksum, embyid))
|
"DELETE FROM emby",
|
||||||
|
"WHERE kodi_id = ?",
|
||||||
def updateParentId(self, embyid, parent_kodiid):
|
"AND media_type = ?"
|
||||||
|
))
|
||||||
query = "UPDATE emby SET parent_id = ? WHERE emby_id = ?"
|
self.embycursor.execute(query, (kodiid, mediatype,))
|
||||||
self.embycursor.execute(query, (parent_kodiid, embyid))
|
|
||||||
|
def removeItem(self, embyid):
|
||||||
def removeItems_byParentId(self, parent_kodiid, mediatype):
|
|
||||||
|
query = "DELETE FROM emby WHERE emby_id = ?"
|
||||||
query = ' '.join((
|
self.embycursor.execute(query, (embyid,))
|
||||||
|
|
||||||
"DELETE FROM emby",
|
def removeWildItem(self, embyid):
|
||||||
"WHERE parent_id = ?",
|
|
||||||
"AND media_type = ?"
|
query = "DELETE FROM emby WHERE emby_id LIKE ?"
|
||||||
))
|
self.embycursor.execute(query, (embyid+"%",))
|
||||||
self.embycursor.execute(query, (parent_kodiid, mediatype,))
|
|
||||||
|
|
||||||
def removeItem_byKodiId(self, kodiid, mediatype):
|
|
||||||
|
|
||||||
query = ' '.join((
|
|
||||||
|
|
||||||
"DELETE FROM emby",
|
|
||||||
"WHERE kodi_id = ?",
|
|
||||||
"AND media_type = ?"
|
|
||||||
))
|
|
||||||
self.embycursor.execute(query, (kodiid, mediatype,))
|
|
||||||
|
|
||||||
def removeItem(self, embyid):
|
|
||||||
|
|
||||||
query = "DELETE FROM emby WHERE emby_id = ?"
|
|
||||||
self.embycursor.execute(query, (embyid,))
|
|
||||||
|
|
||||||
def removeWildItem(self, embyid):
|
|
||||||
|
|
||||||
query = "DELETE FROM emby WHERE emby_id LIKE ?"
|
|
||||||
self.embycursor.execute(query, (embyid+"%",))
|
|
||||||
|
|
Loading…
Reference in a new issue