本文整理汇总了Python中utils.kodiSQL函数的典型用法代码示例。如果您正苦于以下问题:Python kodiSQL函数的具体用法?Python kodiSQL怎么用?Python kodiSQL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了kodiSQL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_uncached_artwork
def get_uncached_artwork():
"""
Returns a list of URLs that haven't been cached yet
"""
all_urls = []
cached_urls = []
result = []
connection = kodiSQL('video')
cursor = connection.cursor()
# Get all artwork urls
cursor.execute("SELECT url FROM art WHERE media_type != 'actor'")
for url in cursor.fetchall():
all_urls.append(url[0])
connection.close()
connection = kodiSQL('music')
cursor = connection.cursor()
cursor.execute("SELECT url FROM art")
for url in cursor.fetchall():
all_urls.append(url[0])
connection.close()
# Get the cached urls
connection = kodiSQL('texture')
cursor = connection.cursor()
cursor.execute("SELECT url FROM texture")
for url in cursor.fetchall():
cached_urls.append(url[0])
connection.close()
for url in all_urls:
if url not in cached_urls:
result.append(url)
log.info('%s artwork urls have not been cached yet' % len(result))
return result
示例2: refreshViews
def refreshViews(self):
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor()
kodiconn = utils.kodiSQL('video')
kodicursor = kodiconn.cursor()
# Compare views, assign correct tags to items
self.maintainViews(embycursor, kodicursor)
self.dbCommit(kodiconn)
kodicursor.close()
embyconn.commit()
embycursor.close()
示例3: modifyPlaylist
def modifyPlaylist(self, itemids):
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor()
emby_db = embydb.Embydb_Functions(embycursor)
self.logMsg("---*** ADD TO PLAYLIST ***---", 1)
self.logMsg("Items: %s" % itemids, 1)
player = xbmc.Player()
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
for itemid in itemids:
embydb_item = emby_db.getItem_byId(itemid)
try:
dbid = embydb_item[0]
mediatype = embydb_item[4]
except TypeError:
# Item is not found in our database, add item manually
item = self.emby.getItem(itemid)
self.addtoPlaylist_xbmc(playlist, item)
else:
# Add to playlist
self.addtoPlaylist(dbid, mediatype)
self.logMsg("Adding %s to playlist." % itemid, 1)
self.verifyPlaylist()
embycursor.close()
return playlist
示例4: getView_embyId
def getView_embyId(self, itemid):
# Returns ancestors using embyId
viewId = None
url = "{server}/emby/Items/%s/Ancestors?UserId={UserId}&format=json" % itemid
result = self.doUtils(url)
for view in result:
viewtype = view['Type']
if viewtype == "CollectionFolder":
# Found view
viewId = view['Id']
# Compare to view table in emby database
emby = utils.kodiSQL('emby')
cursor_emby = emby.cursor()
query = ' '.join((
"SELECT view_name, media_type",
"FROM view",
"WHERE view_id = ?"
))
cursor_emby.execute(query, (viewId,))
result = cursor_emby.fetchone()
try:
viewName = result[0]
mediatype = result[1]
except TypeError:
viewName = None
mediatype = None
cursor_emby.close()
return [viewName, viewId, mediatype]
示例5: _rate_song
def _rate_song(self):
conn = kodiSQL('music')
cursor = conn.cursor()
query = "SELECT rating FROM song WHERE idSong = ?"
cursor.execute(query, (self.kodi_id,))
try:
value = cursor.fetchone()[0]
current_value = int(round(float(value), 0))
except TypeError:
pass
else:
new_value = dialog("numeric", 0, lang(30411), str(current_value))
if new_value > -1:
new_value = int(new_value)
if new_value > 5:
new_value = 5
if settings('enableUpdateSongRating') == "true":
musicutils.updateRatingToFile(new_value, self.api.get_file_path())
query = "UPDATE song SET rating = ? WHERE idSong = ?"
cursor.execute(query, (new_value, self.kodi_id,))
conn.commit()
finally:
cursor.close()
示例6: deleteCachedArtwork
def deleteCachedArtwork(self, url):
# Only necessary to remove and apply a new backdrop or poster
connection = utils.kodiSQL('texture')
cursor = connection.cursor()
try:
cursor.execute("SELECT cachedurl FROM texture WHERE url = ?", (url,))
cachedurl = cursor.fetchone()[0]
except TypeError:
self.logMsg("Could not find cached url.", 1)
except OperationalError:
self.logMsg("Database is locked. Skip deletion process.", 1)
else: # Delete thumbnail as well as the entry
thumbnails = xbmc.translatePath("special://thumbnails/%s" % cachedurl).decode('utf-8')
self.logMsg("Deleting cached thumbnail: %s" % thumbnails, 1)
xbmcvfs.delete(thumbnails)
try:
cursor.execute("DELETE FROM texture WHERE url = ?", (url,))
connection.commit()
except OperationalError:
self.logMsg("Issue deleting url from cache. Skipping.", 2)
finally:
cursor.close()
示例7: playAll
def playAll(self, itemids, startat):
window = utils.window
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor()
emby_db = embydb.Embydb_Functions(embycursor)
player = xbmc.Player()
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
playlist.clear()
self.logMsg("---*** PLAY ALL ***---", 1)
self.logMsg("Items: %s and start at: %s" % (itemids, startat), 1)
started = False
window('plex_customplaylist', value="true")
if startat != 0:
# Seek to the starting position
window('plex_customplaylist.seektime', str(startat))
with embydb.GetEmbyDB() as emby_db:
for itemid in itemids:
embydb_item = emby_db.getItem_byId(itemid)
try:
dbid = embydb_item[0]
mediatype = embydb_item[4]
except TypeError:
# Item is not found in our database, add item manually
self.logMsg("Item was not found in the database, manually "
"adding item.", 1)
item = PlexFunctions.GetPlexMetadata(itemid)
if item is None or item == 401:
self.logMsg('Could not download itemid %s'
% itemid, -1)
else:
self.addtoPlaylist_xbmc(playlist, item)
else:
# Add to playlist
self.addtoPlaylist(dbid, mediatype)
self.logMsg("Adding %s to playlist." % itemid, 1)
if not started:
started = True
player.play(playlist)
self.verifyPlaylist()
示例8: deleteItem
def deleteItem():
# Serves as a keymap action
if xbmc.getInfoLabel('ListItem.Property(embyid)'): # If we already have the embyid
embyid = xbmc.getInfoLabel('ListItem.Property(embyid)')
else:
dbid = xbmc.getInfoLabel('ListItem.DBID')
itemtype = xbmc.getInfoLabel('ListItem.DBTYPE')
if not itemtype:
if xbmc.getCondVisibility('Container.Content(albums)'):
itemtype = "album"
elif xbmc.getCondVisibility('Container.Content(artists)'):
itemtype = "artist"
elif xbmc.getCondVisibility('Container.Content(songs)'):
itemtype = "song"
elif xbmc.getCondVisibility('Container.Content(pictures)'):
itemtype = "picture"
else:
utils.logMsg("EMBY delete", "Unknown type, unable to proceed.", 1)
return
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor()
emby_db = embydb.Embydb_Functions(embycursor)
item = emby_db.getItem_byKodiId(dbid, itemtype)
embycursor.close()
try:
embyid = item[0]
except TypeError:
utils.logMsg("EMBY delete", "Unknown embyId, unable to proceed.", 1)
return
if utils.settings('skipContextMenu') != "true":
resp = xbmcgui.Dialog().yesno(
heading="Confirm delete",
line1=("Delete file from Emby Server? This will "
"also delete the file(s) from disk!"))
if not resp:
utils.logMsg("EMBY delete", "User skipped deletion for: %s." % embyid, 1)
return
doUtils = downloadutils.DownloadUtils()
url = "{server}/emby/Items/%s?format=json" % embyid
utils.logMsg("EMBY delete", "Deleting request: %s" % embyid, 0)
doUtils.downloadUrl(url, type="DELETE")
示例9: playAll
def playAll(self, itemids, startat):
log = self.logMsg
window = utils.window
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor()
emby_db = embydb.Embydb_Functions(embycursor)
player = xbmc.Player()
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
playlist.clear()
log("---*** PLAY ALL ***---", 1)
log("Items: %s and start at: %s" % (itemids, startat), 1)
started = False
window('emby_customplaylist', value="true")
if startat != 0:
# Seek to the starting position
window('emby_customplaylist.seektime', str(startat))
for itemid in itemids:
embydb_item = emby_db.getItem_byId(itemid)
try:
dbid = embydb_item[0]
mediatype = embydb_item[4]
except TypeError:
# Item is not found in our database, add item manually
log("Item was not found in the database, manually adding item.", 1)
item = self.emby.getItem(itemid)
self.addtoPlaylist_xbmc(playlist, item)
else:
# Add to playlist
self.addtoPlaylist(dbid, mediatype)
log("Adding %s to playlist." % itemid, 1)
if not started:
started = True
player.play(playlist)
self.verifyPlaylist()
embycursor.close()
示例10: playAll
def playAll(self, itemids, startat):
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor()
emby_db = embydb.Embydb_Functions(embycursor)
self.logMsg("---*** PLAY ALL ***---", 1)
self.logMsg("Items: %s" % itemids)
player = xbmc.Player()
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
playlist.clear()
started = False
utils.window('emby_customplaylist', value="true", windowid=10101)
position = 0
for itemid in itemids:
embydb_item = emby_db.getItem_byId(itemid)
try:
dbid = embydb_item[0]
mediatype = embydb_item[4]
except TypeError:
# Item is not found in our database, add item manually
item = self.emby.getItem(itemid)
self.addtoPlaylist_xbmc(playlist, item)
else:
# Add to playlist
self.addtoPlaylist(dbid, mediatype)
self.logMsg("Adding %s to playlist." % itemid, 1)
if not started:
started = True
player.play(playlist)
if startat:
# Seek to the starting position
seektime = startat / 10000000.0
player.seekTime(seektime)
self.verifyPlaylist()
embycursor.close()
示例11: deleteCachedArtwork
def deleteCachedArtwork(self, url):
# Only necessary to remove and apply a new backdrop or poster
connection = kodiSQL('texture')
cursor = connection.cursor()
try:
cursor.execute("SELECT cachedurl FROM texture WHERE url = ?",
(url,))
cachedurl = cursor.fetchone()[0]
except TypeError:
log.info("Could not find cached url.")
else:
# Delete thumbnail as well as the entry
thumbnails = tryDecode(
translatePath("special://thumbnails/%s" % cachedurl))
log.debug("Deleting cached thumbnail: %s" % thumbnails)
try:
delete(thumbnails)
except Exception as e:
log.error('Could not delete cached artwork %s. Error: %s'
% (thumbnails, e))
cursor.execute("DELETE FROM texture WHERE url = ?", (url,))
connection.commit()
finally:
connection.close()
示例12: getThemeMedia
def getThemeMedia():
doUtils = downloadutils.DownloadUtils()
dialog = xbmcgui.Dialog()
playback = None
# Choose playback method
resp = dialog.select("Playback method for your themes", ["Direct Play", "Direct Stream"])
if resp == 0:
playback = "DirectPlay"
elif resp == 1:
playback = "DirectStream"
else:
return
library = xbmc.translatePath(
"special://profile/addon_data/plugin.video.emby/library/").decode('utf-8')
# Create library directory
if not xbmcvfs.exists(library):
xbmcvfs.mkdir(library)
# Set custom path for user
tvtunes_path = xbmc.translatePath(
"special://profile/addon_data/script.tvtunes/").decode('utf-8')
if xbmcvfs.exists(tvtunes_path):
tvtunes = xbmcaddon.Addon(id="script.tvtunes")
tvtunes.setSetting('custom_path_enable', "true")
tvtunes.setSetting('custom_path', library)
utils.logMsg("EMBY", "TV Tunes custom path is enabled and set.", 1)
else:
# if it does not exist this will not work so warn user
# often they need to edit the settings first for it to be created.
dialog.ok(
heading="Warning",
line1=(
"The settings file does not exist in tvtunes. ",
"Go to the tvtunes addon and change a setting, then come back and re-run."))
xbmc.executebuiltin('Addon.OpenSettings(script.tvtunes)')
return
# Get every user view Id
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor()
emby_db = embydb.Embydb_Functions(embycursor)
viewids = emby_db.getViews()
embycursor.close()
# Get Ids with Theme Videos
itemIds = {}
for view in viewids:
url = "{server}/emby/Users/{UserId}/Items?HasThemeVideo=True&ParentId=%s&format=json" % view
result = doUtils.downloadUrl(url)
if result['TotalRecordCount'] != 0:
for item in result['Items']:
itemId = item['Id']
folderName = item['Name']
folderName = utils.normalize_string(folderName.encode('utf-8'))
itemIds[itemId] = folderName
# Get paths for theme videos
for itemId in itemIds:
nfo_path = xbmc.translatePath(
"special://profile/addon_data/plugin.video.emby/library/%s/" % itemIds[itemId])
# Create folders for each content
if not xbmcvfs.exists(nfo_path):
xbmcvfs.mkdir(nfo_path)
# Where to put the nfos
nfo_path = "%s%s" % (nfo_path, "tvtunes.nfo")
url = "{server}/emby/Items/%s/ThemeVideos?format=json" % itemId
result = doUtils.downloadUrl(url)
# Create nfo and write themes to it
nfo_file = xbmcvfs.File(nfo_path, 'w')
pathstowrite = ""
# May be more than one theme
for theme in result['Items']:
putils = playutils.PlayUtils(theme)
if playback == "DirectPlay":
playurl = putils.directPlay()
else:
playurl = putils.directStream()
pathstowrite += ('<file>%s</file>' % playurl.encode('utf-8'))
# Check if the item has theme songs and add them
url = "{server}/emby/Items/%s/ThemeSongs?format=json" % itemId
result = doUtils.downloadUrl(url)
# May be more than one theme
for theme in result['Items']:
putils = playutils.PlayUtils(theme)
if playback == "DirectPlay":
playurl = putils.directPlay()
else:
playurl = putils.directStream()
pathstowrite += ('<file>%s</file>' % playurl.encode('utf-8'))
nfo_file.write(
'<tvtunes>%s</tvtunes>' % pathstowrite
)
#.........这里部分代码省略.........
示例13: FullTextureCacheSync
def FullTextureCacheSync(self):
# This method will sync all Kodi artwork to textures13.db
# and cache them locally. This takes diskspace!
if not xbmcgui.Dialog().yesno("Image Texture Cache", "Running the image cache process can take some time.", "Are you sure you want continue?"):
return
self.logMsg("Doing Image Cache Sync", 1)
dialog = xbmcgui.DialogProgress()
dialog.create("Emby for Kodi", "Image Cache Sync")
# ask to rest all existing or not
if xbmcgui.Dialog().yesno("Image Texture Cache", "Reset all existing cache data first?", ""):
self.logMsg("Resetting all cache data first", 1)
# Remove all existing textures first
path = xbmc.translatePath("special://thumbnails/").decode('utf-8')
if xbmcvfs.exists(path):
allDirs, allFiles = xbmcvfs.listdir(path)
for dir in allDirs:
allDirs, allFiles = xbmcvfs.listdir(path+dir)
for file in allFiles:
if os.path.supports_unicode_filenames:
xbmcvfs.delete(os.path.join(path+dir.decode('utf-8'),file.decode('utf-8')))
else:
xbmcvfs.delete(os.path.join(path.encode('utf-8')+dir,file))
# remove all existing data from texture DB
textureconnection = utils.kodiSQL('texture')
texturecursor = textureconnection.cursor()
texturecursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
rows = texturecursor.fetchall()
for row in rows:
tableName = row[0]
if(tableName != "version"):
texturecursor.execute("DELETE FROM " + tableName)
textureconnection.commit()
texturecursor.close()
# Cache all entries in video DB
connection = utils.kodiSQL('video')
cursor = connection.cursor()
cursor.execute("SELECT url FROM art WHERE media_type != 'actor'") # dont include actors
result = cursor.fetchall()
total = len(result)
count = 1
percentage = 0
self.logMsg("Image cache sync about to process " + str(total) + " images", 1)
for url in result:
if dialog.iscanceled():
break
percentage = int((float(count) / float(total))*100)
textMessage = str(count) + " of " + str(total) + " (" + str(len(self.imageCacheThreads)) + ")"
dialog.update(percentage, "Updating Image Cache: " + textMessage)
self.CacheTexture(url[0])
count += 1
cursor.close()
# Cache all entries in music DB
connection = utils.kodiSQL('music')
cursor = connection.cursor()
cursor.execute("SELECT url FROM art")
result = cursor.fetchall()
total = len(result)
count = 1
percentage = 0
self.logMsg("Image cache sync about to process " + str(total) + " images", 1)
for url in result:
if dialog.iscanceled():
break
percentage = int((float(count) / float(total))*100)
textMessage = str(count) + " of " + str(total)
dialog.update(percentage, "Updating Image Cache: " + textMessage)
self.CacheTexture(url[0])
count += 1
cursor.close()
dialog.update(100, "Waiting for all threads to exit: " + str(len(self.imageCacheThreads)))
self.logMsg("Waiting for all threads to exit", 1)
while len(self.imageCacheThreads) > 0:
for thread in self.imageCacheThreads:
if thread.isFinished:
self.imageCacheThreads.remove(thread)
dialog.update(100, "Waiting for all threads to exit: " + str(len(self.imageCacheThreads)))
self.logMsg("Waiting for all threads to exit: " + str(len(self.imageCacheThreads)), 1)
xbmc.sleep(500)
dialog.close()
示例14: logMsg
if __name__ == '__main__':
itemid = xbmc.getInfoLabel("ListItem.DBID").decode("utf-8")
itemtype = xbmc.getInfoLabel("ListItem.DBTYPE").decode("utf-8")
emby = embyserver.Read_EmbyServer()
embyid = ""
if not itemtype and xbmc.getCondVisibility("Container.Content(albums)"): itemtype = "album"
if not itemtype and xbmc.getCondVisibility("Container.Content(artists)"): itemtype = "artist"
if not itemtype and xbmc.getCondVisibility("Container.Content(songs)"): itemtype = "song"
if not itemtype and xbmc.getCondVisibility("Container.Content(pictures)"): itemtype = "picture"
if (not itemid or itemid == "-1") and xbmc.getInfoLabel("ListItem.Property(embyid)"):
embyid = xbmc.getInfoLabel("ListItem.Property(embyid)")
else:
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor()
emby_db = embydb.Embydb_Functions(embycursor)
item = emby_db.getItem_byKodiId(itemid, itemtype)
embycursor.close()
if item: embyid = item[0]
logMsg("Contextmenu opened for embyid: %s - itemtype: %s" %(embyid,itemtype))
if embyid:
item = emby.getItem(embyid)
API = api.API(item)
userdata = API.getUserData()
likes = userdata['Likes']
favourite = userdata['Favorite']
示例15: fullSync
def fullSync(self, manualrun=False, repair=False):
# Only run once when first setting up. Can be run manually.
emby = self.emby
music_enabled = utils.settings('enableMusic') == "true"
utils.window('emby_dbScan', value="true")
# Add sources
utils.sourcesXML()
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor()
# Create the tables for the emby database
# emby, view, version
embycursor.execute(
"""CREATE TABLE IF NOT EXISTS emby(
emby_id TEXT UNIQUE, media_folder TEXT, emby_type TEXT, media_type TEXT, kodi_id INTEGER,
kodi_fileid INTEGER, kodi_pathid INTEGER, parent_id INTEGER, checksum INTEGER)""")
embycursor.execute(
"""CREATE TABLE IF NOT EXISTS view(
view_id TEXT UNIQUE, view_name TEXT, media_type TEXT, kodi_tagid INTEGER)""")
embycursor.execute("CREATE TABLE IF NOT EXISTS version(idVersion TEXT)")
embyconn.commit()
# content sync: movies, tvshows, musicvideos, music
kodiconn = utils.kodiSQL('video')
kodicursor = kodiconn.cursor()
if manualrun:
message = "Manual sync"
elif repair:
message = "Repair sync"
else:
message = "Initial sync"
pDialog = self.progressDialog("%s" % message, forced=True)
starttotal = datetime.now()
# Set views
self.maintainViews(embycursor, kodicursor)
embyconn.commit()
# Sync video library
process = {
'movies': self.movies,
'musicvideos': self.musicvideos,
'tvshows': self.tvshows,
'homevideos': self.homevideos
}
for itemtype in process:
startTime = datetime.now()
completed = process[itemtype](embycursor, kodicursor, pDialog, compare=manualrun)
if not completed:
utils.window('emby_dbScan', clear=True)
if pDialog:
pDialog.close()
embycursor.close()
kodicursor.close()
return False
else:
self.dbCommit(kodiconn)
embyconn.commit()
elapsedTime = datetime.now() - startTime
self.logMsg(
"SyncDatabase (finished %s in: %s)"
% (itemtype, str(elapsedTime).split('.')[0]), 1)
# sync music
if music_enabled:
musicconn = utils.kodiSQL('music')
musiccursor = musicconn.cursor()
startTime = datetime.now()
completed = self.music(embycursor, musiccursor, pDialog, compare=manualrun)
if not completed:
utils.window('emby_dbScan', clear=True)
if pDialog:
pDialog.close()
embycursor.close()
musiccursor.close()
return False
else:
musicconn.commit()
embyconn.commit()
elapsedTime = datetime.now() - startTime
self.logMsg(
"SyncDatabase (finished music in: %s)"
% (str(elapsedTime).split('.')[0]), 1)
musiccursor.close()
if pDialog:
pDialog.close()
embycursor.close()
kodicursor.close()
#.........这里部分代码省略.........