New hybrid method

This commit is contained in:
angelblue05 2018-09-06 03:36:32 -05:00
parent 7f5084c62e
commit ace50b34dc
279 changed files with 39526 additions and 19994 deletions

View file

@ -0,0 +1,6 @@
from kodi import Kodi
from movies import Movies
from musicvideos import MusicVideos
from tvshows import TVShows
from music import Music
from artwork import Artwork

View file

@ -0,0 +1,386 @@
# -*- coding: utf-8 -*-
#################################################################################################
import logging
import urllib
import Queue
import threading
import xbmc
import xbmcvfs
import queries as QU
import queries_texture as QUTEX
from helper import window, settings
from libraries import requests
##################################################################################################
LOG = logging.getLogger("EMBY."+__name__)
##################################################################################################
class Artwork(object):
def __init__(self, cursor):
self.cursor = cursor
self.enable_cache = settings('enableTextureCache.bool')
self.queue = Queue.Queue()
self.threads = []
self.kodi = {
'username': settings('webServerUser'),
'password': settings('webServerPass'),
'host': "localhost",
'port': settings('webServerPort')
}
def update(self, image_url, kodi_id, media, image):
''' Update artwork in the video database.
Only cache artwork if it changed for the main backdrop, poster.
Delete current entry before updating with the new one.
Cache fanart and poster in Kodi texture cache.
'''
if not image_url or image == 'poster' and media in ('song', 'artist', 'album'):
return
cache = False
try:
self.cursor.execute(QU.get_art, (kodi_id, media, image,))
url = self.cursor.fetchone()[0]
except TypeError:
cache = True
LOG.debug("ADD to kodi_id %s art: %s", kodi_id, image_url)
self.cursor.execute(QU.add_art, (kodi_id, media, image, image_url))
else:
if url != image_url:
cache = True
if image in ('fanart', 'poster'):
self.delete_cache(url)
LOG.info("UPDATE to kodi_id %s art: %s", kodi_id, image_url)
self.cursor.execute(QU.update_art, (image_url, kodi_id, media, image))
if cache and image in ('fanart', 'poster'):
self.cache(image_url)
def add(self, artwork, *args):
''' Add all artworks.
'''
KODI = {
'Primary': ['thumb', 'poster'],
'Banner': "banner",
'Logo': "clearlogo",
'Art': "clearart",
'Thumb': "landscape",
'Disc': "discart",
'Backdrop': "fanart"
}
for art in KODI:
if art == 'Backdrop':
self.cursor.execute(QU.get_backdrops, args + ("fanart%",))
if len(self.cursor.fetchall()) > len(artwork['Backdrop']):
self.cursor.execute(QU.delete_backdrops, args + ("fanart_",))
for index, backdrop in enumerate(artwork['Backdrop']):
if index:
self.update(*(backdrop,) + args + ("%s%s" % ("fanart", index),))
else:
self.update(*(backdrop,) + args + ("fanart",))
elif art == 'Primary':
for kodi_image in KODI['Primary']:
self.update(*(artwork['Primary'],) + args + (kodi_image,))
elif artwork.get(art):
self.update(*(artwork[art],) + args + (KODI[art],))
def delete(self, *args):
''' Delete artwork from kodi database and remove cache for backdrop/posters.
'''
self.cursor.execute(QU.get_art_url, args)
for row in self.cursor.fetchall():
if row[1] in ('poster', 'fanart'):
self.delete_cache(row[0])
def cache(self, url):
''' Cache a single image to texture cache.
'''
if not url or not self.enable_cache:
return
url = self.double_urlencode(url)
self.queue.put(url)
self.add_worker()
def double_urlencode(self, text):
text = self.single_urlencode(text)
text = self.single_urlencode(text)
return text
def single_urlencode(self, text):
''' urlencode needs a utf-string.
return the result as unicode
'''
text = urllib.urlencode({'blahblahblah': text.encode('utf-8')})
text = text[13:]
return text.decode('utf-8')
def add_worker(self):
for thread in self.threads:
if thread.is_done:
self.threads.remove(thread)
if self.queue.qsize() and len(self.threads) < 3:
new_thread = GetArtworkWorker(self.kodi, self.queue)
new_thread.start()
LOG.info("-->[ q:artwork/%s ]", id(new_thread))
self.threads.append(new_thread)
def delete_cache(self, url):
''' Delete cached artwork.
'''
from database import Database
with Database('texture') as texturedb:
try:
texturedb.cursor.execute(QUTEX.get_cache, (url,))
cached = texturedb.cursor.fetchone()[0]
except TypeError:
LOG.debug("Could not find cached url: %s", url)
else:
thumbnails = xbmc.translatePath("special://thumbnails/%s" % cached).decode('utf-8')
xbmcvfs.delete(thumbnails)
texturedb.cursor.execute(QUTEX.delete_cache, (url,))
LOG.info("DELETE cached %s", cached)
class GetArtworkWorker(threading.Thread):
is_done = False
def __init__(self, kodi, queue):
self.kodi = kodi
self.queue = queue
threading.Thread.__init__(self)
def run(self):
''' Prepare the request. Request removes the urlencode which is required in this case.
Use a session allows to use a pool of connections.
'''
with requests.Session() as s:
while True:
try:
url = self.queue.get(timeout=2)
except Queue.Empty:
self.is_done = True
LOG.info("--<[ q:artwork/%s ]", id(self))
return
try:
req = requests.Request(method='HEAD',
url="http://%s:%s/image/image://%s" % (self.kodi['host'], self.kodi['port'], url),
auth=(self.kodi['username'], self.kodi['password']))
prep = req.prepare()
prep.url = "http://%s:%s/image/image://%s" % (self.kodi['host'], self.kodi['port'], url)
s.send(prep, timeout=(0.01, 0.01))
s.content # release the connection
except Exception:
pass
self.queue.task_done()
if xbmc.Monitor().abortRequested():
break
"""
# -*- coding: utf-8 -*-
#################################################################################################
import logging
import os
import urllib
from sqlite3 import OperationalError
import xbmc
import xbmcgui
import xbmcvfs
import requests
import resources.lib.image_cache_thread as image_cache_thread
from resources.lib.helper import _, window, settings, JSONRPC
from resources.lib.database import Database
from __objs__ import QU
##################################################################################################
log = logging.getLogger("EMBY."+__name__)
##################################################################################################
class Artwork(object):
xbmc_host = 'localhost'
xbmc_port = None
xbmc_username = None
xbmc_password = None
image_cache_threads = []
image_cache_limit = 0
def __init__(self, server):
self.server = server
self.enable_texture_cache = settings('enableTextureCache') == "true"
self.image_cache_limit = int(settings('imageCacheLimit')) * 5
log.debug("image cache thread count: %s", self.image_cache_limit)
if not self.xbmc_port and self.enable_texture_cache:
self._set_webserver_details()
def texture_cache_sync(self):
# This method will sync all Kodi artwork to textures13.db
# and cache them locally. This takes diskspace!
if not dialog(type_="yesno",
heading="{emby}",
line1=_(33042)):
return
log.info("Doing Image Cache Sync")
pdialog = xbmcgui.DialogProgress()
pdialog.create(_(29999), _(33043))
# ask to rest all existing or not
if dialog(type_="yesno", heading="{emby}", line1=_(33044)):
log.info("Resetting all cache data first")
self.delete_cache()
# Cache all entries in video DB
self._cache_all_video_entries(pdialog)
# Cache all entries in music DB
self._cache_all_music_entries(pdialog)
pdialog.update(100, "%s %s" % (_(33046), len(self.image_cache_threads)))
log.info("Waiting for all threads to exit")
while len(self.image_cache_threads):
for thread in self.image_cache_threads:
if thread.is_finished:
self.image_cache_threads.remove(thread)
pdialog.update(100, "%s %s" % (_(33046), len(self.image_cache_threads)))
log.info("Waiting for all threads to exit: %s", len(self.image_cache_threads))
xbmc.sleep(500)
pdialog.close()
@classmethod
def delete_cache(cls):
# Remove all existing textures first
path = xbmc.translatePath('special://thumbnails/').decode('utf-8')
if xbmcvfs.exists(path):
dirs, ignore_files = xbmcvfs.listdir(path)
for directory in dirs:
ignore_dirs, files = xbmcvfs.listdir(path + directory)
for file_ in files:
if os.path.supports_unicode_filenames:
filename = os.path.join(path + directory.decode('utf-8'),
file_.decode('utf-8'))
else:
filename = os.path.join(path.encode('utf-8') + directory, file_)
xbmcvfs.delete(filename)
log.debug("deleted: %s", filename)
# remove all existing data from texture DB
with DatabaseConn('texture') as cursor_texture:
cursor_texture.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
rows = cursor_texture.fetchall()
for row in rows:
table_name = row[0]
if table_name != "version":
cursor_texture.execute("DELETE FROM " + table_name)
def _cache_all_video_entries(self, pdialog):
with Database('video') as cursor_video:
cursor_video.execute("SELECT url FROM art WHERE media_type != 'actor'") # dont include actors
result = cursor_video.fetchall()
total = len(result)
log.info("Image cache sync about to process %s images", total)
cursor_video.close()
count = 0
for url in result:
if pdialog.iscanceled():
break
percentage = int((float(count) / float(total))*100)
message = "%s of %s (%s)" % (count, total, len(self.image_cache_threads))
pdialog.update(percentage, "%s %s" % (_(33045), message))
self.cache_texture(url[0])
count += 1
def _cache_all_music_entries(self, pdialog):
with Database('music') as cursor_music:
cursor_music.execute("SELECT url FROM art")
result = cursor_music.fetchall()
total = len(result)
log.info("Image cache sync about to process %s images", total)
count = 0
for url in result:
if pdialog.iscanceled():
break
percentage = int((float(count) / float(total))*100)
message = "%s of %s" % (count, total)
pdialog.update(percentage, "%s %s" % (_(33045), message))
self.cache_texture(url[0])
count += 1
"""

View file

@ -0,0 +1,297 @@
# -*- coding: utf-8 -*-
##################################################################################################
import logging
import xbmc
import artwork
import queries as QU
from helper import values
##################################################################################################
LOG = logging.getLogger("EMBY."+__name__)
##################################################################################################
class Kodi(object):
def __init__(self):
self.artwork = artwork.Artwork(self.cursor)
def create_entry_path(self):
self.cursor.execute(QU.create_path)
return self.cursor.fetchone()[0] + 1
def create_entry_file(self):
self.cursor.execute(QU.create_file)
return self.cursor.fetchone()[0] + 1
def create_entry_person(self):
self.cursor.execute(QU.create_person)
return self.cursor.fetchone()[0] + 1
def create_entry_genre(self):
self.cursor.execute(QU.create_genre)
return self.cursor.fetchone()[0] + 1
def create_entry_studio(self):
self.cursor.execute(QU.create_studio)
return self.cursor.fetchone()[0] + 1
def create_entry_bookmark(self):
self.cursor.execute(QU.create_bookmark)
return self.cursor.fetchone()[0] + 1
def create_entry_tag(self):
self.cursor.execute(QU.create_tag)
return self.cursor.fetchone()[0] + 1
def add_path(self, *args):
path_id = self.get_path(*args)
if path_id is None:
path_id = self.create_entry_path()
self.cursor.execute(QU.add_path, (path_id,) + args)
return path_id
def get_path(self, *args):
try:
self.cursor.execute(QU.get_path, args)
return self.cursor.fetchone()[0]
except TypeError:
return
def update_path(self, *args):
self.cursor.execute(QU.update_path, args)
def remove_path(self, *args):
self.cursor.execute(QU.delete_path, args)
def add_file(self, filename, path_id):
try:
self.cursor.execute(QU.get_file, (filename, path_id,))
file_id = self.cursor.fetchone()[0]
except TypeError:
file_id = self.create_entry_file()
self.cursor.execute(QU.add_file, (file_id, path_id, filename))
return file_id
def update_file(self, *args):
self.cursor.execute(QU.update_file, args)
def remove_file(self, path, *args):
path_id = self.get_path(path)
if path_id is not None:
self.cursor.execute(QU.delete_file_by_path, (path_id,) + args)
def get_filename(self, *args):
try:
self.cursor.execute(QU.get_filename, args)
return self.cursor.fetchone()[0]
except TypeError:
return ""
def add_people(self, people, *args):
def add_thumbnail(person_id, person, person_type):
if person['imageurl']:
art = person_type.lower()
if "writing" in art:
art = "writer"
self.artwork.update(person['imageurl'], person_id, art, "thumb")
def add_link(link, person_id):
self.cursor.execute(QU.update_link.replace("{LinkType}", link), (person_id,) + args)
cast_order = 1
for person in people:
person_id = self.get_person(person['Name'])
if person['Type'] == 'Actor':
role = person.get('Role')
self.cursor.execute(QU.update_actor, (person_id,) + args + (role, cast_order,))
cast_order += 1
elif person['Type'] == 'Director':
add_link('director_link', person_id)
elif person['Type'] == 'Writer':
add_link('writer_link', person_id)
elif person['Type'] == 'Artist':
add_link('actor_link', person_id)
add_thumbnail(person_id, person, person['Type'])
def add_person(self, *args):
person_id = self.create_entry_person()
self.cursor.execute(QU.add_person, (person_id,) + args)
return person_id
def get_person(self, *args):
try:
self.cursor.execute(QU.get_person, args)
return self.cursor.fetchone()[0]
except TypeError:
return self.add_person(*args)
def add_genres(self, genres, *args):
''' Delete current genres first for clean slate.
'''
self.cursor.execute(QU.delete_genres, args)
for genre in genres:
self.cursor.execute(QU.update_genres, (self.get_genre(genre),) + args)
def add_genre(self, *args):
genre_id = self.create_entry_genre()
self.cursor.execute(QU.add_genre, (genre_id,) + args)
return genre_id
def get_genre(self, *args):
try:
self.cursor.execute(QU.get_genre, args)
return self.cursor.fetchone()[0]
except TypeError:
return self.add_genre(*args)
def add_studios(self, studios, *args):
for studio in studios:
studio_id = self.get_studio(studio)
self.cursor.execute(QU.update_studios, (studio_id,) + args)
def add_studio(self, *args):
studio_id = self.create_entry_studio()
self.cursor.execute(QU.add_studio, (studio_id,) + args)
return studio_id
def get_studio(self, *args):
try:
self.cursor.execute(QU.get_studio, args)
return self.cursor.fetchone()[0]
except TypeError:
return self.add_studio(*args)
def add_streams(self, file_id, streams, runtime):
''' First remove any existing entries
Then re-add video, audio and subtitles.
'''
self.cursor.execute(QU.delete_streams, (file_id,))
if streams:
for track in streams['video']:
track['FileId'] = file_id
track['Runtime'] = runtime
self.add_stream_video(*values(track, QU.add_stream_video_obj))
for track in streams['audio']:
track['FileId'] = file_id
self.add_stream_audio(*values(track, QU.add_stream_audio_obj))
for track in streams['subtitle']:
self.add_stream_sub(*values({'language': track, 'FileId': file_id}, QU.add_stream_sub_obj))
def add_stream_video(self, *args):
self.cursor.execute(QU.add_stream_video, args)
def add_stream_audio(self, *args):
self.cursor.execute(QU.add_stream_audio, args)
def add_stream_sub(self, *args):
self.cursor.execute(QU.add_stream_sub, args)
def add_playstate(self, file_id, playcount, date_played, resume, *args):
''' Delete the existing resume point.
Set the watched count.
'''
self.cursor.execute(QU.delete_bookmark, (file_id,))
self.set_playcount(playcount, date_played, file_id)
if resume:
bookmark_id = self.create_entry_bookmark()
self.cursor.execute(QU.add_bookmark, (bookmark_id, file_id, resume,) + args)
def set_playcount(self, *args):
self.cursor.execute(QU.update_playcount, args)
def add_tags(self, tags, *args):
self.cursor.execute(QU.delete_tags, args)
for tag in tags:
tag_id = self.get_tag(tag, *args)
def add_tag(self, *args):
tag_id = self.create_entry_tag()
self.cursor.execute(QU.add_tag, (tag_id,) + args)
return tag_id
def get_tag(self, tag, *args):
try:
self.cursor.execute(QU.get_tag, (tag,))
tag_id = self.cursor.fetchone()[0]
except TypeError:
tag_id = self.add_tag(tag)
self.cursor.execute(QU.update_tag, (tag_id,) + args)
return tag_id
def remove_tag(self, tag, *args):
try:
self.cursor.execute(QU.get_tag, (tag,))
tag_id = self.cursor.fetchone()[0]
except TypeError:
return
self.cursor.execute(QU.delete_tag, (tag,) + args)

View file

@ -0,0 +1,149 @@
# -*- coding: utf-8 -*-
##################################################################################################
import logging
from kodi import Kodi
import queries as QU
##################################################################################################
LOG = logging.getLogger("EMBY."+__name__)
##################################################################################################
class Movies(Kodi):
def __init__(self, cursor):
self.cursor = cursor
Kodi.__init__(self)
def create_entry_unique_id(self):
self.cursor.execute(QU.create_unique_id)
return self.cursor.fetchone()[0] + 1
def create_entry_rating(self):
self.cursor.execute(QU.create_rating)
return self.cursor.fetchone()[0] + 1
def create_entry(self):
self.cursor.execute(QU.create_movie)
return self.cursor.fetchone()[0] + 1
def create_entry_set(self):
self.cursor.execute(QU.create_set)
return self.cursor.fetchone()[0] + 1
def create_entry_country(self):
self.cursor.execute(QU.create_country)
return self.cursor.fetchone()[0] + 1
def get(self, *args):
try:
self.cursor.execute(QU.get_movie, args)
return self.cursor.fetchone()[0]
except TypeError:
return
def add(self, *args):
self.cursor.execute(QU.add_movie, args)
def update(self, *args):
self.cursor.execute(QU.update_movie, args)
def delete(self, kodi_id, file_id):
self.cursor.execute(QU.delete_movie, (kodi_id,))
self.cursor.execute(QU.delete_file, (file_id,))
def get_rating_id(self, *args):
try:
self.cursor.execute(QU.get_rating, args)
return self.cursor.fetchone()[0]
except TypeError:
return None
def add_ratings(self, *args):
''' Add ratings, rating type and votes.
'''
self.cursor.execute(QU.add_rating, args)
def update_ratings(self, *args):
''' Update rating by rating_id.
'''
self.cursor.execute(QU.update_rating, args)
def get_unique_id(self, *args):
try:
self.cursor.execute(QU.get_unique_id, args)
return self.cursor.fetchone()[0]
except TypeError:
return
def add_unique_id(self, *args):
''' Add the provider id, imdb, tvdb.
'''
self.cursor.execute(QU.add_unique_id, args)
def update_unique_id(self, *args):
''' Update the provider id, imdb, tvdb.
'''
self.cursor.execute(QU.update_unique_id, args)
def add_countries(self, countries, *args):
for country in countries:
self.cursor.execute(QU.update_country, (self.get_country(country),) + args)
def add_country(self, *args):
country_id = self.create_entry_country()
self.cursor.execute(QU.add_country, (country_id,) + args)
return country_id
def get_country(self, *args):
try:
self.cursor.execute(QU.get_country, args)
return self.cursor.fetchone()[0]
except TypeError:
return self.add_country(*args)
def add_boxset(self, *args):
set_id = self.create_entry_set()
self.cursor.execute(QU.add_set, (set_id,) + args)
return set_id
def update_boxset(self, *args):
self.cursor.execute(QU.update_set, args)
def set_boxset(self, *args):
self.cursor.execute(QU.update_movie_set, args)
def remove_from_boxset(self, *args):
self.cursor.execute(QU.delete_movie_set, args)
def delete_boxset(self, *args):
self.cursor.execute(QU.delete_set, args)

View file

@ -0,0 +1,223 @@
# -*- coding: utf-8 -*-
##################################################################################################
import logging
import queries_music as QU
from kodi import Kodi
##################################################################################################
LOG = logging.getLogger("EMBY."+__name__)
##################################################################################################
class Music(Kodi):
def __init__(self, cursor):
self.cursor = cursor
Kodi.__init__(self)
def create_entry(self):
''' Krypton has a dummy first entry
idArtist: 1 strArtist: [Missing Tag] strMusicBrainzArtistID: Artist Tag Missing
'''
self.cursor.execute(QU.create_artist)
return self.cursor.fetchone()[0] + 1
def create_entry_album(self):
self.cursor.execute(QU.create_album)
return self.cursor.fetchone()[0] + 1
def create_entry_song(self):
self.cursor.execute(QU.create_song)
return self.cursor.fetchone()[0] + 1
def create_entry_genre(self):
self.cursor.execute(QU.create_genre)
return self.cursor.fetchone()[0] + 1
def update_path(self, *args):
self.cursor.execute(QU.update_path, args)
def add_role(self, *args):
self.cursor.execute(QU.update_role, args)
def get(self, artist_id, name, musicbrainz):
''' Get artist or create the entry.
'''
try:
self.cursor.execute(QU.get_artist, (musicbrainz,))
result = self.cursor.fetchone()
artist_id = result[0]
artist_name = result[1]
except TypeError:
artist_id = self.add_artist(artist_id, name, musicbrainz)
else:
if artist_name != name:
self.update_artist_name(artist_id, name)
return artist_id
def add_artist(self, artist_id, name, *args):
''' Safety check, when musicbrainz does not exist
'''
try:
self.cursor.execute(QU.get_artist_by_name, (name,))
artist_id = self.cursor.fetchone()[0]
except TypeError:
artist_id = artist_id or self.create_entry()
self.cursor.execute(QU.add_artist, (artist_id, name,) + args)
return artist_id
def update_artist_name(self, *args):
self.cursor.execute(QU.update_artist_name, args)
def update(self, *args):
self.cursor.execute(QU.update_artist, args)
def link(self, *args):
self.cursor.execute(QU.update_link, args)
def add_discography(self, *args):
self.cursor.execute(QU.update_discography, args)
def validate_artist(self, *args):
try:
self.cursor.execute(QU.get_artist_by_id, args)
return self.cursor.fetchone()[0]
except TypeError:
return
def validate_album(self, *args):
try:
self.cursor.execute(QU.get_album_by_id, args)
return self.cursor.fetchone()[0]
except TypeError:
return
def validate_song(self, *args):
try:
self.cursor.execute(QU.get_song_by_id, args)
return self.cursor.fetchone()[0]
except TypeError:
return
def get_album(self, album_id, name, musicbrainz, *args):
if musicbrainz is not None:
self.cursor.execute(QU.get_album, (musicbrainz,))
else:
self.cursor.execute(QU.get_album_by_name, (name,))
try:
album_id = self.cursor.fetchone()[0]
except TypeError:
album_id = self.add_album(*(album_id, name, musicbrainz,) + args)
return album_id
def add_album(self, album_id, *args):
album_id = album_id or self.create_entry_album()
self.cursor.execute(QU.add_album, (album_id,) + args)
return album_id
def update_album(self, *args):
self.cursor.execute(QU.update_album, args)
def get_album_artist(self, album_id, artists):
try:
self.cursor.execute(QU.get_album_artist, (album_id,))
curr_artists = self.cursor.fetchone()[0]
except TypeError:
return
if curr_artists != artists:
self.update_album_artist(artists, album_id)
def update_album_artist(self, *args):
self.cursor.execute(QU.update_album_artist, args)
def add_single(self, *args):
self.cursor.execute(QU.add_single, args)
def add_song(self, *args):
self.cursor.execute(QU.add_song, args)
def update_song(self, *args):
self.cursor.execute(QU.update_song, args)
def link_song_artist(self, *args):
self.cursor.execute(QU.update_song_artist, args)
def link_song_album(self, *args):
self.cursor.execute(QU.update_song_album, args)
def rate_song(self, *args):
self.cursor.execute(QU.update_song_rating, args)
def add_genres(self, kodi_id, genres, media):
''' Add genres, but delete current genres first.
'''
if media == 'album':
self.cursor.execute(QU.delete_genres_album, (kodi_id,))
for genre in genres:
genre_id = self.get_genre(genre)
self.cursor.execute(QU.update_genre_album, (genre_id, kodi_id))
elif media == 'song':
self.cursor.execute(QU.delete_genres_song, (kodi_id,))
for genre in genres:
genre_id = self.get_genre(genre)
self.cursor.execute(QU.update_genre_song, (genre_id, kodi_id))
def get_genre(self, *args):
try:
self.cursor.execute(QU.get_genre, args)
return self.cursor.fetchone()[0]
except TypeError:
return self.add_genre(*args)
def add_genre(self, *args):
genre_id = self.create_entry_genre()
self.cursor.execute(QU.add_genre, (genre_id,) + args)
return genre_id
def delete(self, *args):
self.cursor.execute(QU.delete_artist, args)
def delete_album(self, *args):
self.cursor.execute(QU.delete_album, args)
def delete_song(self, *args):
self.cursor.execute(QU.delete_song, args)

View file

@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
##################################################################################################
import logging
import queries as QU
from kodi import Kodi
##################################################################################################
log = logging.getLogger("EMBY."+__name__)
##################################################################################################
class MusicVideos(Kodi):
def __init__(self, cursor):
self.cursor = cursor
Kodi.__init__(self)
def create_entry(self):
self.cursor.execute(QU.create_musicvideo)
return self.cursor.fetchone()[0] + 1
def get(self, *args):
try:
self.cursor.execute(QU.get_musicvideo, args)
return self.cursor.fetchone()[0]
except TypeError:
return
def add(self, *args):
self.cursor.execute(QU.add_musicvideo, args)
def update(self, *args):
self.cursor.execute(QU.update_musicvideo, args)
def delete(self, kodi_id, file_id):
self.cursor.execute(QU.delete_musicvideo, (kodi_id,))
self.cursor.execute(QU.delete_file, (file_id,))

View file

@ -0,0 +1,550 @@
''' Queries for the Kodi database. obj reflect key/value to retrieve from emby items.
Some functions require additional information, therefore obj do not always reflect
the Kodi database query values.
'''
create_path = """ SELECT coalesce(max(idPath), 0)
FROM path
"""
create_file = """ SELECT coalesce(max(idFile), 0)
FROM files
"""
create_person = """ SELECT coalesce(max(actor_id), 0)
FROM actor
"""
create_genre = """ SELECT coalesce(max(genre_id), 0)
FROM genre
"""
create_studio = """ SELECT coalesce(max(studio_id), 0)
FROM studio
"""
create_bookmark = """ SELECT coalesce(max(idBookmark), 0)
FROM bookmark
"""
create_tag = """ SELECT coalesce(max(tag_id), 0)
FROM tag
"""
create_unique_id = """ SELECT coalesce(max(uniqueid_id), 0)
FROM uniqueid
"""
create_rating = """ SELECT coalesce(max(rating_id), 0)
FROM rating
"""
create_movie = """ SELECT coalesce(max(idMovie), 0)
FROM movie
"""
create_set = """ SELECT coalesce(max(idSet), 0)
FROM sets
"""
create_country = """ SELECT coalesce(max(country_id), 0)
FROM country
"""
create_musicvideo = """ SELECT coalesce(max(idMVideo), 0)
FROM musicvideo
"""
create_tvshow = """ SELECT coalesce(max(idShow), 0)
FROM tvshow
"""
create_season = """ SELECT coalesce(max(idSeason), 0)
FROM seasons
"""
create_episode = """ SELECT coalesce(max(idEpisode), 0)
FROM episode
"""
get_path = """ SELECT idPath
FROM path
WHERE strPath = ?
"""
get_path_obj = [ "{Path}"
]
get_file = """ SELECT idFile
FROM files
WHERE idPath = ?
AND strFilename = ?
"""
get_file_obj = [ "{FileId}"
]
get_filename = """ SELECT strFilename
FROM files
WHERE idFile = ?
"""
get_person = """ SELECT actor_id
FROM actor
WHERE name = ?
COLLATE NOCASE
"""
get_genre = """ SELECT genre_id
FROM genre
WHERE name = ?
COLLATE NOCASE
"""
get_studio = """ SELECT studio_id
FROM studio
WHERE name = ?
COLLATE NOCASE
"""
get_tag = """ SELECT tag_id
FROM tag
WHERE name = ?
COLLATE NOCASE
"""
get_tag_movie_obj = [ "{MovieId}", "Favorite movies", "movie"
]
get_tag_mvideo_obj = [ "{MvideoId}", "Favorite musicvideos", "musicvideo"
]
get_tag_episode_obj = [ "{KodiId}", "Favorite tvshows", "tvshow"
]
get_art = """ SELECT url
FROM art
WHERE media_id = ?
AND media_type = ?
AND type = ?
"""
get_movie = """ SELECT *
FROM movie
WHERE idMovie = ?
"""
get_movie_obj = [ "{MovieId}"
]
get_rating = """ SELECT rating_id
FROM rating
WHERE media_type = ?
AND media_id = ?
"""
get_rating_movie_obj = [ "movie","{MovieId}"
]
get_rating_episode_obj = [ "episode","{EpisodeId}"
]
get_unique_id = """ SELECT uniqueid_id
FROM uniqueid
WHERE media_type = ?
AND media_id = ?
"""
get_unique_id_movie_obj = [ "movie","{MovieId}"
]
get_unique_id_tvshow_obj = [ "tvshow","{ShowId}"
]
get_unique_id_episode_obj = [ "episode","{EpisodeId}"
]
get_country = """ SELECT country_id
FROM country
WHERE name = ?
COLLATE NOCASE
"""
get_set = """ SELECT idSet
FROM sets
WHERE strSet = ?
COLLATE NOCASE
"""
get_musicvideo = """ SELECT *
FROM musicvideo
WHERE idMVideo = ?
"""
get_musicvideo_obj = [ "{MvideoId}"
]
get_tvshow = """ SELECT *
FROM tvshow
WHERE idShow = ?
"""
get_tvshow_obj = [ "{ShowId}"
]
get_episode = """ SELECT *
FROM episode
WHERE idEpisode = ?
"""
get_episode_obj = [ "{EpisodeId}"
]
get_season = """ SELECT idSeason
FROM seasons
WHERE idShow = ?
AND season = ?
"""
get_season_obj = [ "{Title}","{ShowId}","{Index}"
]
get_season_special_obj = [ None,"{ShowId}",-1
]
get_season_episode_obj = [ None,"{ShowId}","{Season}"
]
get_backdrops = """ SELECT url
FROM art
WHERE media_id = ?
AND media_type = ?
AND type LIKE ?
"""
get_art = """ SELECT url
FROM art
WHERE media_id = ?
AND media_type = ?
AND type = ?
"""
get_art_url = """ SELECT url, type
FROM art
WHERE media_id = ?
AND media_type = ?
"""
get_show_by_unique_id = """ SELECT idShow
FROM tvshow_view
WHERE uniqueid_value = ?
"""
get_total_episodes = """ SELECT totalCount
FROM tvshowcounts
WHERE idShow = ?
"""
get_total_episodes_obj = [ "{ParentId}"
]
add_path = """ INSERT INTO path(idPath, strPath)
VALUES (?, ?)
"""
add_path_obj = [ "{Path}"
]
add_file = """ INSERT INTO files(idFile, idPath, strFilename)
VALUES (?, ?, ?)
"""
add_file_obj = [ "{PathId}","{Filename}"
]
add_person = """ INSERT INTO actor(actor_id, name)
VALUES (?, ?)
"""
add_people_movie_obj = [ "{People}","{MovieId}","movie"
]
add_people_mvideo_obj = [ "{People}","{MvideoId}","musicvideo"
]
add_people_tvshow_obj = [ "{People}","{ShowId}","tvshow"
]
add_people_episode_obj = [ "{People}","{EpisodeId}","episode"
]
add_actor_link = """ INSERT INTO actor_link(actor_id, media_id, media_type, role, cast_order)
VALUES (?, ?, ?, ?, ?)
"""
add_link = """ INSERT INTO {LinkType}(actor_id, media_id, media_type)
VALUES (?, ?, ?)
"""
add_genre = """ INSERT INTO genre(genre_id, name)
VALUES (?, ?)
"""
add_genres_movie_obj = [ "{Genres}","{MovieId}","movie"
]
add_genres_mvideo_obj = [ "{Genres}","{MvideoId}","musicvideo"
]
add_genres_tvshow_obj = [ "{Genres}","{ShowId}","tvshow"
]
add_studio = """ INSERT INTO studio(studio_id, name)
VALUES (?, ?)
"""
add_studios_movie_obj = [ "{Studios}","{MovieId}","movie"
]
add_studios_mvideo_obj = [ "{Studios}","{MvideoId}","musicvideo"
]
add_studios_tvshow_obj = [ "{Studios}","{ShowId}","tvshow"
]
add_bookmark = """ INSERT INTO bookmark(idBookmark, idFile, timeInSeconds, totalTimeInSeconds, player, type)
VALUES (?, ?, ?, ?, ?, ?)
"""
add_bookmark_obj = [ "{FileId}","{PlayCount}","{DatePlayed}","{Resume}","{Runtime}","DVDPlayer",1
]
add_streams_obj = [ "{FileId}","{Streams}","{Runtime}"
]
add_stream_video = """ INSERT INTO streamdetails(idFile, iStreamType, strVideoCodec, fVideoAspect, iVideoWidth,
iVideoHeight, iVideoDuration, strStereoMode)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
"""
add_stream_video_obj = [ "{FileId}",0,"{codec}","{aspect}","{width}","{height}","{Runtime}","{3d}"
]
add_stream_audio = """ INSERT INTO streamdetails(idFile, iStreamType, strAudioCodec, iAudioChannels, strAudioLanguage)
VALUES (?, ?, ?, ?, ?)
"""
add_stream_audio_obj = [ "{FileId}",1,"{codec}","{channels}","{language}"
]
add_stream_sub = """ INSERT INTO streamdetails(idFile, iStreamType, strSubtitleLanguage)
VALUES (?, ?, ?)
"""
add_stream_sub_obj = [ "{FileId}",2,"{language}"
]
add_tag = """ INSERT INTO tag(tag_id, name)
VALUES (?, ?)
"""
add_tags_movie_obj = [ "{Tags}","{MovieId}","movie"
]
add_tags_mvideo_obj = [ "{Tags}","{MvideoId}","musicvideo"
]
add_tags_tvshow_obj = [ "{Tags}","{ShowId}","tvshow"
]
add_art = """ INSERT INTO art(media_id, media_type, type, url)
VALUES (?, ?, ?, ?)
"""
add_movie = """ INSERT INTO movie(idMovie, idFile, c00, c01, c02, c03, c04, c05, c06, c07,
c09, c10, c11, c12, c14, c15, c16, c18, c19, c21, premiered)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
"""
add_movie_obj = [ "{MovieId}","{FileId}","{Title}","{Plot}","{ShortPlot}","{Tagline}",
"{Votes}","{RatingId}","{Writers}","{Year}","{Unique}","{SortTitle}",
"{Runtime}","{Mpaa}","{Genre}","{Directors}","{Title}","{Studio}",
"{Trailer}","{Country}","{Year}"
]
add_rating = """ INSERT INTO rating(rating_id, media_id, media_type, rating_type, rating, votes)
VALUES (?, ?, ?, ?, ?, ?)
"""
add_rating_movie_obj = [ "{RatingId}","{MovieId}","movie","default","{Rating}","{Votes}"
]
add_rating_tvshow_obj = [ "{RatingId}","{ShowId}","tvshow","default","{Rating}","{Votes}"
]
add_rating_episode_obj = [ "{RatingId}","{EpisodeId}","episode","default","{Rating}","{Votes}"
]
add_unique_id = """ INSERT INTO uniqueid(uniqueid_id, media_id, media_type, value, type)
VALUES (?, ?, ?, ?, ?)
"""
add_unique_id_movie_obj = [ "{Unique}","{MovieId}","movie","{UniqueId}","{ProviderName}"
]
add_unique_id_tvshow_obj = [ "{Unique}","{ShowId}","tvshow","{UniqueId}","{ProviderName}"
]
add_unique_id_episode_obj = [ "{Unique}","{EpisodeId}","episode","{UniqueId}","{ProviderName}"
]
add_country = """ INSERT INTO country(country_id, name)
VALUES (?, ?)
"""
add_set = """ INSERT INTO sets(idSet, strSet, strOverview)
VALUES (?, ?, ?)
"""
add_set_obj = [ "{Title}","{Overview}"
]
add_musicvideo = """ INSERT INTO musicvideo(idMVideo,idFile, c00, c04, c05, c06, c07, c08, c09, c10,
c11, c12, premiered)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
"""
add_musicvideo_obj = [ "{MvideoId}","{FileId}","{Title}","{Runtime}","{Directors}","{Studio}","{Year}",
"{Plot}","{Album}","{Artists}","{Genre}","{Index}","{Premiere}"
]
add_tvshow = """ INSERT INTO tvshow(idShow, c00, c01, c04, c05, c08, c09, c12, c13, c14, c15)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
"""
add_tvshow_obj = [ "{ShowId}","{Title}","{Plot}","{RatingId}","{Premiere}","{Genre}","{Title}",
"{Unique}","{Mpaa}","{Studio}","{SortTitle}"
]
add_season = """ INSERT INTO seasons(idSeason, idShow, season)
VALUES (?, ?, ?)
"""
add_episode = """ INSERT INTO episode(idEpisode, idFile, c00, c01, c03, c04, c05, c09, c10, c12, c13, c14,
idShow, c15, c16, idSeason)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
"""
add_episode_obj = [ "{EpisodeId}","{FileId}","{Title}","{Plot}","{RatingId}","{Writers}","{Premiere}","{Runtime}",
"{Directors}","{Season}","{Index}","{Title}","{ShowId}","{AirsBeforeSeason}",
"{AirsBeforeEpisode}","{SeasonId}"
]
add_art = """ INSERT INTO art(media_id, media_type, type, url)
VALUES (?, ?, ?, ?)
"""
update_path = """ UPDATE path
SET strPath = ?, strContent = ?, strScraper = ?, noUpdate = ?
WHERE idPath = ?
"""
update_path_movie_obj = [ "{Path}","movies","metadata.local",1,"{PathId}"
]
update_path_toptvshow_obj = [ "{TopLevel}","tvshows","metadata.local",1,"{TopPathId}"
]
update_path_tvshow_obj = [ "{Path}",None,None,1,"{PathId}"
]
update_path_episode_obj = [ "{Path}",None,None,1,"{PathId}"
]
update_path_mvideo_obj = [ "{Path}","musicvideos","metadata.local",1,"{PathId}"
]
update_file = """ UPDATE files
SET idPath = ?, strFilename = ?, dateAdded = ?
WHERE idFile = ?
"""
update_file_obj = [ "{PathId}","{Filename}","{DateAdded}","{FileId}"
]
update_genres = """ INSERT OR REPLACE INTO genre_link(genre_id, media_id, media_type)
VALUES (?, ?, ?)
"""
update_studios = """ INSERT OR REPLACE INTO studio_link(studio_id, media_id, media_type)
VALUES (?, ?, ?)
"""
update_playcount = """ UPDATE files
SET playCount = ?, lastPlayed = ?
WHERE idFile = ?
"""
update_tag = """ INSERT OR REPLACE INTO tag_link(tag_id, media_id, media_type)
VALUES (?, ?, ?)
"""
update_art = """ UPDATE art
SET url = ?
WHERE media_id = ?
AND media_type = ?
AND type = ?
"""
update_actor = """ INSERT OR REPLACE INTO actor_link(actor_id, media_id, media_type, role, cast_order)
VALUES (?, ?, ?, ?, ?)
"""
update_link = """ INSERT OR REPLACE INTO {LinkType}(actor_id, media_id, media_type)
VALUES (?, ?, ?)
"""
update_movie = """ UPDATE movie
SET c00 = ?, c01 = ?, c02 = ?, c03 = ?, c04 = ?, c05 = ?, c06 = ?,
c07 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ?, c14 = ?, c15 = ?,
c16 = ?, c18 = ?, c19 = ?, c21 = ?, premiered = ?
WHERE idMovie = ?
"""
update_movie_obj = [ "{Title}","{Plot}","{ShortPlot}","{Tagline}","{Votes}","{RatingId}",
"{Writers}","{Year}","{Unique}","{SortTitle}","{Runtime}",
"{Mpaa}","{Genre}","{Directors}","{Title}","{Studio}","{Trailer}",
"{Country}","{Year}","{MovieId}"
]
update_rating = """ UPDATE rating
SET media_id = ?, media_type = ?, rating_type = ?, rating = ?, votes = ?
WHERE rating_id = ?
"""
update_rating_movie_obj = [ "{MovieId}","movie","default","{Rating}","{Votes}","{RatingId}"
]
update_rating_tvshow_obj = [ "{ShowId}","tvshow","default","{Rating}","{Votes}","{RatingId}"
]
update_rating_episode_obj = [ "{EpisodeId}","episode","default","{Rating}","{Votes}","{RatingId}"
]
update_unique_id = """ UPDATE uniqueid
SET media_id = ?, media_type = ?, value = ?, type = ?
WHERE uniqueid_id = ?
"""
update_unique_id_movie_obj = [ "{MovieId}","movie","{UniqueId}","{ProviderName}","{Unique}"
]
update_unique_id_tvshow_obj = [ "{ShowId}","tvshow","{UniqueId}","{ProviderName}","{Unique}"
]
update_unique_id_episode_obj = [ "{EpisodeId}","episode","{UniqueId}","{ProviderName}","{Unique}"
]
update_country = """ INSERT OR REPLACE INTO country_link(country_id, media_id, media_type)
VALUES (?, ?, ?)
"""
update_country_obj = [ "{Countries}","{MovieId}","movie"
]
update_set = """ UPDATE sets
SET strSet = ?, strOverview = ?
WHERE idSet = ?
"""
update_set_obj = [ "{Title}", "{Overview}", "{SetId}"
]
update_movie_set = """ UPDATE movie
SET idSet = ?
WHERE idMovie = ?
"""
update_movie_set_obj = [ "{SetId}","{MovieId}"
]
update_musicvideo = """ UPDATE musicvideo
SET c00 = ?, c04 = ?, c05 = ?, c06 = ?, c07 = ?, c08 = ?, c09 = ?, c10 = ?,
c11 = ?, c12 = ?, premiered = ?
WHERE idMVideo = ?
"""
update_musicvideo_obj = [ "{Title}","{Runtime}","{Directors}","{Studio}","{Year}","{Plot}","{Album}",
"{Artists}","{Genre}","{Index}","{Premiere}","{MvideoId}"
]
update_tvshow = """ UPDATE tvshow
SET c00 = ?, c01 = ?, c04 = ?, c05 = ?, c08 = ?, c09 = ?,
c12 = ?, c13 = ?, c14 = ?, c15 = ?
WHERE idShow = ?
"""
update_tvshow_obj = [ "{ShowId}","{Title}","{Plot}","{RatingId}","{Premiere}","{Genre}","{Title}",
"{Unique}","{Mpaa}","{Studio}","{SortTitle}"
]
update_tvshow_link = """ INSERT OR REPLACE INTO tvshowlinkpath(idShow, idPath)
VALUES (?, ?)
"""
update_tvshow_link_obj = [ "{ShowId}","{PathId}"
]
update_season = """ UPDATE seasons
SET name = ?
WHERE idSeason = ?
"""
update_episode = """ UPDATE episode
SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?, c10 = ?,
c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ?, idSeason = ?, idShow = ?
WHERE idEpisode = ?
"""
update_episode_obj = [ "{Title}","{Plot}","{RatingId}","{Writers}","{Premiere}","{Runtime}","{Directors}",
"{Season}","{Index}","{Title}","{AirsBeforeSeason}","{AirsBeforeEpisode}","{SeasonId}",
"{ShowId}","{EpisodeId}"
]
delete_path = """ DELETE FROM path
WHERE idPath = ?
"""
delete_path_obj = [ "{PathId}"
]
delete_file = """ DELETE FROM files
WHERE idFile = ?
"""
delete_file_obj = [ "{Path}","{Filename}"
]
delete_file_by_path = """ DELETE FROM files
WHERE idPath = ?
AND strFileName = ?
"""
delete_genres = """ DELETE FROM genre_link
WHERE media_id = ?
AND media_type = ?
"""
delete_bookmark = """ DELETE FROM bookmark
WHERE idFile = ?
"""
delete_streams = """ DELETE FROM streamdetails
WHERE idFile = ?
"""
delete_tags = """ DELETE FROM tag_link
WHERE media_id = ?
AND media_type = ?
"""
delete_tag = """ DELETE FROM tag_link
WHERE tag_id = ?
AND media_type = ?
AND media_id = ?
"""
delete_tag_movie_obj = [ "{MovieId}","Favorite movies","movie"
]
delete_tag_mvideo_obj = [ "{MvideoId}","Favorite musicvideos","musicvideo"
]
delete_tag_episode_obj = [ "{KodiId}","Favorite tvshows","tvshow"
]
delete_movie = """ DELETE FROM movie
WHERE idMovie = ?
"""
delete_movie_obj = [ "{KodiId}","{FileId}"
]
delete_set = """ DELETE FROM sets
WHERE idSet = ?
"""
delete_set_obj = [ "{KodiId}"
]
delete_movie_set = """ UPDATE movie
SET idSet = null
WHERE idMovie = ?
"""
delete_movie_set_obj = [ "{MovieId}"
]
delete_musicvideo = """ DELETE FROM musicvideo
WHERE idMVideo = ?
"""
delete_musicvideo_obj = [ "{MvideoId}", "{FileId}"
]
delete_tvshow = """ DELETE FROM tvshow
WHERE idShow = ?
"""
delete_season = """ DELETE FROM seasons
WHERE idSeason = ?
"""
delete_episode = """ DELETE FROM episode
WHERE idEpisode = ?
"""
delete_backdrops = """ DELETE FROM art
WHERE media_id = ?
AND media_type = ?
AND type LIKE ?
"""

View file

@ -0,0 +1,197 @@
create_artist = """ SELECT coalesce(max(idArtist), 1)
FROM artist
"""
create_album = """ SELECT coalesce(max(idAlbum), 0)
FROM album
"""
create_song = """ SELECT coalesce(max(idSong), 0)
FROM song
"""
create_genre = """ SELECT coalesce(max(idGenre), 0)
FROM genre
"""
get_artist = """ SELECT idArtist, strArtist
FROM artist
WHERE strMusicBrainzArtistID = ?
"""
get_artist_obj = [ "{ArtistId}","{Name}","{UniqueId}"
]
get_artist_by_name = """ SELECT idArtist
FROM artist
WHERE strArtist = ?
COLLATE NOCASE
"""
get_artist_by_id = """ SELECT *
FROM artist
WHERE idArtist = ?
"""
get_artist_by_id_obj = [ "{ArtistId}"
]
get_album_by_id = """ SELECT *
FROM album
WHERE idAlbum = ?
"""
get_album_by_id_obj = [ "{AlbumId}"
]
get_song_by_id = """ SELECT *
FROM song
WHERE idSong = ?
"""
get_song_by_id_obj = [ "{SongId}"
]
get_album = """ SELECT idAlbum
FROM album
WHERE strMusicBrainzAlbumID = ?
"""
get_album_obj = [ "{AlbumId}","{Title}","{UniqueId}","album"
]
get_album_by_name = """ SELECT idAlbum
FROM album
WHERE strAlbum = ?
"""
get_album_artist = """ SELECT strArtists
FROM album
WHERE idAlbum = ?
"""
get_album_artist_obj = [ "{AlbumId}","{strAlbumArtists}"
]
get_genre = """ SELECT idGenre
FROM genre
WHERE strGenre = ?
COLLATE NOCASE
"""
get_total_episodes = """ SELECT totalCount
FROM tvshowcounts
WHERE idShow = ?
"""
add_artist = """ INSERT INTO artist(idArtist, strArtist, strMusicBrainzArtistID)
VALUES (?, ?, ?)
"""
add_album = """ INSERT INTO album(idAlbum, strAlbum, strMusicBrainzAlbumID, strReleaseType)
VALUES (?, ?, ?, ?)
"""
add_single = """ INSERT INTO album(idAlbum, strGenres, iYear, strReleaseType)
VALUES (?, ?, ?, ?)
"""
add_single_obj = [ "{AlbumId}","{Genre}","{Year}","single"
]
add_song = """ INSERT INTO song(idSong, idAlbum, idPath, strArtists, strGenres, strTitle, iTrack,
iDuration, iYear, strFileName, strMusicBrainzTrackID, iTimesPlayed, lastplayed,
rating, comment, dateAdded)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
"""
add_song_obj = [ "{SongId}","{AlbumId}","{PathId}","{Artists}","{Genre}","{Title}","{Index}",
"{Runtime}","{Year}","{Filename}","{UniqueId}","{PlayCount}","{DatePlayed}","{Rating}",
"{Comment}","{DateAdded}"
]
add_genre = """ INSERT INTO genre(idGenre, strGenre)
VALUES (?, ?)
"""
add_genres_obj = [ "{AlbumId}","{Genres}","album"
]
update_path = """ UPDATE path
SET strPath = ?
WHERE idPath = ?
"""
update_path_obj = [ "{Path}","{PathId}"
]
update_role = """ INSERT OR REPLACE INTO role(idRole, strRole)
VALUES (?, ?)
"""
update_role_obj = [ 1,"Composer"
]
update_artist_name = """ UPDATE artist
SET strArtist = ?
WHERE idArtist = ?
"""
update_artist_name_obj = [ "{Name}","{ArtistId}"
]
update_artist = """ UPDATE artist
SET strGenres = ?, strBiography = ?, strImage = ?, strFanart = ?, lastScraped = ?
WHERE idArtist = ?
"""
update_link = """ INSERT OR REPLACE INTO album_artist(idArtist, idAlbum, strArtist)
VALUES (?, ?, ?)
"""
update_link_obj = [ "{ArtistId}","{AlbumId}","{Name}"
]
update_discography = """ INSERT OR REPLACE INTO discography(idArtist, strAlbum, strYear)
VALUES (?, ?, ?)
"""
update_discography_obj = [ "{ArtistId}","{Title}","{Year}"
]
update_album = """ UPDATE album
SET strArtists = ?, iYear = ?, strGenres = ?, strReview = ?, strImage = ?,
iUserrating = ?, lastScraped = ?, strReleaseType = ?
WHERE idAlbum = ?
"""
update_album_obj = [ "{Artists}","{Year}","{Genre}","{Bio}","{Thumb}","{Rating}","{LastScraped}",
"album","{AlbumId}"
]
update_album_artist = """ UPDATE album
SET strArtists = ?
WHERE idAlbum = ?
"""
update_song = """ UPDATE song
SET idAlbum = ?, strArtists = ?, strGenres = ?, strTitle = ?, iTrack = ?,
iDuration = ?, iYear = ?, strFilename = ?, iTimesPlayed = ?, lastplayed = ?,
rating = ?, comment = ?, dateAdded = ?
WHERE idSong = ?
"""
update_song_obj = [ "{AlbumId}","{Artists}","{Genre}","{Title}","{Index}","{Runtime}","{Year}",
"{Filename}","{PlayCount}","{DatePlayed}","{Rating}","{Comment}",
"{DateAdded}","{SongId}"
]
update_song_artist = """ INSERT OR REPLACE INTO song_artist(idArtist, idSong, idRole, iOrder, strArtist)
VALUES (?, ?, ?, ?, ?)
"""
update_song_artist_obj = [ "{ArtistId}","{SongId}",1,"{Index}","{Name}"
]
update_song_album = """ INSERT OR REPLACE INTO albuminfosong(idAlbumInfoSong, idAlbumInfo, iTrack,
strTitle, iDuration)
VALUES (?, ?, ?, ?, ?)
"""
update_song_album_obj = [ "{SongId}","{AlbumId}","{Index}","{Title}","{Runtime}"
]
update_song_rating = """ UPDATE song
SET iTimesPlayed = ?, lastplayed = ?, rating = ?
WHERE idSong = ?
"""
update_song_rating_obj = [ "{PlayCount}","{DatePlayed}","{Rating}","{KodiId}"
]
update_genre_album = """ INSERT OR REPLACE INTO album_genre(idGenre, idAlbum)
VALUES (?, ?)
"""
update_genre_song = """ INSERT OR REPLACE INTO song_genre(idGenre, idSong)
VALUES (?, ?)
"""
update_genre_song_obj = [ "{SongId}","{Genres}","song"
]
delete_genres_album = """ DELETE FROM album_genre
WHERE idAlbum = ?
"""
delete_genres_song = """ DELETE FROM song_genre
WHERE idSong = ?
"""
delete_artist = """ DELETE FROM artist
WHERE idArtist = ?
"""
delete_album = """ DELETE FROM album
WHERE idAlbum = ?
"""
delete_song = """ DELETE FROM song
WHERE idSong = ?
"""

View file

@ -0,0 +1,11 @@
get_cache = """ SELECT cachedurl
FROM texture
WHERE url = ?
"""
delete_cache = """ DELETE FROM texture
WHERE url = ?
"""

View file

@ -0,0 +1,156 @@
# -*- coding: utf-8 -*-
##################################################################################################
import logging
import queries as QU
from kodi import Kodi
##################################################################################################
LOG = logging.getLogger("EMBY."+__name__)
##################################################################################################
class TVShows(Kodi):
def __init__(self, cursor):
self.cursor = cursor
Kodi.__init__(self)
def create_entry_unique_id(self):
self.cursor.execute(QU.create_unique_id)
return self.cursor.fetchone()[0] + 1
def create_entry_rating(self):
self.cursor.execute(QU.create_rating)
return self.cursor.fetchone()[0] + 1
def create_entry(self):
self.cursor.execute(QU.create_tvshow)
return self.cursor.fetchone()[0] + 1
def create_entry_season(self):
self.cursor.execute(QU.create_season)
return self.cursor.fetchone()[0] + 1
def create_entry_episode(self):
self.cursor.execute(QU.create_episode)
return self.cursor.fetchone()[0] + 1
def get(self, *args):
try:
self.cursor.execute(QU.get_tvshow, args)
return self.cursor.fetchone()[0]
except TypeError:
return
def get_episode(self, *args):
try:
self.cursor.execute(QU.get_episode, args)
return self.cursor.fetchone()[0]
except TypeError:
return
def get_rating_id(self, *args):
try:
self.cursor.execute(QU.get_rating, args)
return self.cursor.fetchone()[0]
except TypeError:
return
def add_ratings(self, *args):
self.cursor.execute(QU.add_rating, args)
def update_ratings(self, *args):
self.cursor.execute(QU.update_rating, args)
def get_total_episodes(self, *args):
try:
self.cursor.execute(QU.get_total_episodes, args)
return self.cursor.fetchone()[0]
except TypeError:
return
def get_unique_id(self, *args):
try:
self.cursor.execute(QU.get_unique_id, args)
return self.cursor.fetchone()[0]
except TypeError:
return
def add_unique_id(self, *args):
self.cursor.execute(QU.add_unique_id, args)
def update_unique_id(self, *args):
self.cursor.execute(QU.update_unique_id, args)
def add(self, *args):
self.cursor.execute(QU.add_tvshow, args)
def update(self, *args):
self.cursor.execute(QU.update_tvshow, args)
def link(self, *args):
self.cursor.execute(QU.update_tvshow_link, args)
def get_season(self, name, *args):
self.cursor.execute(QU.get_season, args)
try:
season_id = self.cursor.fetchone()[0]
except TypeError:
season_id = self.add_season(*args)
if name:
self.cursor.execute(QU.update_season, (name, season_id))
return season_id
def add_season(self, *args):
season_id = self.create_entry_season()
self.cursor.execute(QU.add_season, (season_id,) + args)
return season_id
def get_by_unique_id(self, *args):
self.cursor.execute(QU.get_show_by_unique_id, args)
return self.cursor.fetchall()
def add_episode(self, *args):
self.cursor.execute(QU.add_episode, args)
def update_episode(self, *args):
self.cursor.execute(QU.update_episode, args)
def delete_tvshow(self, *args):
self.cursor.execute(QU.delete_tvshow, args)
def delete_season(self, *args):
self.cursor.execute(QU.delete_season, args)
def delete_episode(self, kodi_id, file_id):
self.cursor.execute(QU.delete_episode, (kodi_id,))
self.cursor.execute(QU.delete_file, (file_id,))