Skip to content

Commit

Permalink
Merge pull request #376 from quickmic/next-gen-dev
Browse files Browse the repository at this point in the history
plugin.video.emby-next-gen-5.3.3-build 19 (ex1)
  • Loading branch information
quickmic authored Jun 12, 2021
2 parents aacaeea + bbbd6c2 commit f983d8b
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 168 deletions.
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.emby-next-gen" name="Emby-next-gen" version="5.3.2" provider-name="quickmic, angelblue05, sualfred">
<addon id="plugin.video.emby-next-gen" name="Emby-next-gen" version="5.3.3" provider-name="quickmic, angelblue05, sualfred">
<requires>
<import addon="script.module.requests" version="2.22.0"/>
<import addon="script.module.dateutil" version="2.8.1"/>
Expand Down
2 changes: 0 additions & 2 deletions core/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def __init__(self, EmbyServer, embydb, videodb):
self.video = videodb
self.emby_db = database.emby_db.EmbyDatabase(embydb.cursor)
self.objects = obj_ops.Objects()
self.item_ids = []
self.Common = common.Common(self.emby_db, self.objects, self.EmbyServer)
self.KodiDBIO = kodi.Kodi(videodb.cursor, self.EmbyServer.Utils)
self.MoviesDBIO = MoviesDBIO(videodb.cursor)
Expand Down Expand Up @@ -128,7 +127,6 @@ def movie(self, item, library):
self.KodiDBIO.add_people(*self.EmbyServer.Utils.values(obj, queries_videos.add_people_movie_obj))
self.KodiDBIO.add_streams(*self.EmbyServer.Utils.values(obj, queries_videos.add_streams_obj))
self.ArtworkDBIO.add(obj['Artwork'], obj['MovieId'], "movie")
self.item_ids.append(obj['Id'])

if "StackTimes" in obj:
self.KodiDBIO.add_stacktimes(*self.EmbyServer.Utils.values(obj, queries_videos.add_stacktimes_obj))
Expand Down
127 changes: 64 additions & 63 deletions core/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ def __init__(self, EmbyServer, embydb, musicdb):
self.music = musicdb
self.emby_db = database.emby_db.EmbyDatabase(self.emby.cursor)
self.objects = obj_ops.Objects()
self.item_ids = []
self.Common = common.Common(self.emby_db, self.objects, self.EmbyServer)
self.MusicDBIO = MusicDBIO(self.music.cursor, self.EmbyServer.Utils.DatabaseFiles['music-version'])
self.ArtworkDBIO = artwork.Artwork(musicdb.cursor, self.EmbyServer.Utils)
self.APIHelper = helper.api.API(self.EmbyServer.Utils)
self.MusicDBIO.disable_rescan()
self.library = None

#If item does not exist, entry will be added.
#If item exists, entry will be updated
def artist(self, item, library):
e_item = self.emby_db.get_item_by_id(item['Id'])
library = self.Common.library_check(e_item, item, library)
self.library = self.Common.library_check(e_item, item, library)

if not library:
if not self.library:
return False

obj = self.objects.map(item, 'Artist')
Expand All @@ -49,8 +49,8 @@ def artist(self, item, library):
obj['ArtistId'] = None
self.LOG.debug("ArtistId %s not found" % obj['Id'])

obj['LibraryId'] = library['Id']
obj['LibraryName'] = library['Name']
obj['LibraryId'] = self.library['Id']
obj['LibraryName'] = self.library['Name']
obj['LastScraped'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
obj['ArtistType'] = "MusicArtist"
obj['Genre'] = " / ".join(obj['Genres'] or [])
Expand Down Expand Up @@ -80,7 +80,6 @@ def artist(self, item, library):
self.MusicDBIO.update(obj['Genre'], obj['Bio'], obj['Thumb'], obj['Backdrops'], obj['LastScraped'], obj['SortName'], obj['ArtistId'])

self.ArtworkDBIO.add(obj['Artwork'], obj['ArtistId'], "artist")
self.item_ids.append(obj['Id'])
return not update

#Add object to kodi
Expand All @@ -99,9 +98,9 @@ def artist_update(self, obj):
#Update object to kodi
def album(self, item, library):
e_item = self.emby_db.get_item_by_id(item['Id'])
library = self.Common.library_check(e_item, item, library)
self.library = self.Common.library_check(e_item, item, library)

if not library:
if not self.library:
return False

obj = self.objects.map(item, 'Album')
Expand All @@ -117,8 +116,8 @@ def album(self, item, library):
obj['AlbumId'] = None
self.LOG.debug("AlbumId %s not found" % obj['Id'])

obj['LibraryId'] = library['Id']
obj['LibraryName'] = library['Name']
obj['LibraryId'] = self.library['Id']
obj['LibraryName'] = self.library['Name']
obj['Rating'] = 0
obj['LastScraped'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
obj['Genres'] = obj['Genres'] or []
Expand All @@ -144,7 +143,6 @@ def album(self, item, library):
self.artist_link(obj)
self.artist_discography(obj)
self.ArtworkDBIO.add(obj['Artwork'], obj['AlbumId'], "album")
self.item_ids.append(obj['Id'])
return not update

#Add object to kodi
Expand All @@ -156,6 +154,7 @@ def album_add(self, obj):

self.emby_db.add_reference(*self.EmbyServer.Utils.values(obj, database.queries.add_reference_album_obj))
self.LOG.info("ADD album [%s] %s: %s" % (obj['AlbumId'], obj['Title'], obj['Id']))
return obj['AlbumId']

#Update object to kodi
def album_update(self, obj):
Expand Down Expand Up @@ -206,14 +205,13 @@ def artist_link(self, obj):

self.MusicDBIO.update_artist_name(*self.EmbyServer.Utils.values(temp_obj, queries_music.update_artist_name_obj))
self.MusicDBIO.link(*self.EmbyServer.Utils.values(temp_obj, queries_music.update_link_obj))
self.item_ids.append(temp_obj['Id'])

#Update object to kodi
def song(self, item, library):
e_item = self.emby_db.get_item_by_id(item['Id'])
library = self.Common.library_check(e_item, item, library)
self.library = self.Common.library_check(e_item, item, library)

if not library:
if not self.library:
return False

obj = self.objects.map(item, 'Song')
Expand All @@ -231,8 +229,8 @@ def song(self, item, library):
obj['SongId'] = self.MusicDBIO.create_entry_song()
self.LOG.debug("SongId %s not found" % obj['Id'])

obj['LibraryId'] = library['Id']
obj['LibraryName'] = library['Name']
obj['LibraryId'] = self.library['Id']
obj['LibraryName'] = self.library['Name']
obj['Path'] = self.APIHelper.get_file_path(obj['Path'], item)
PathValid, obj = self.Common.get_path_filename(obj, "audio")

Expand Down Expand Up @@ -267,6 +265,8 @@ def song(self, item, library):
if obj['Thumb']:
obj['Thumb'] = "<thumb>%s</thumb>" % obj['Thumb']

obj['AlbumId'] = self.song_album_link(obj)

if update:
self.song_update(obj)
else:
Expand All @@ -279,7 +279,6 @@ def song(self, item, library):
self.MusicDBIO.get_album_artist(*self.EmbyServer.Utils.values(obj, queries_music.get_album_artist_obj))
self.MusicDBIO.add_genres(*self.EmbyServer.Utils.values(obj, queries_music.update_genre_song_obj))
self.ArtworkDBIO.add(obj['Artwork'], obj['SongId'], "song")
self.item_ids.append(obj['Id'])

if obj['SongAlbumId'] is None:
self.ArtworkDBIO.add(obj['Artwork'], obj['AlbumId'], "album")
Expand All @@ -290,30 +289,8 @@ def song(self, item, library):
#Verify if there's an album associated.
#If no album found, create a single's album
def song_add(self, obj):
AlbumFound = False
obj['PathId'] = self.MusicDBIO.add_path(obj['Path'])

if obj['SongAlbumId']:
result = self.emby_db.get_item_by_id(*self.EmbyServer.Utils.values(obj, database.queries.get_item_song_obj))

if result:
obj['AlbumId'] = result[0]
AlbumFound = True

if not AlbumFound:
obj['LastScraped'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
obj['AlbumId'] = None
BackupTitle = obj['Title']
obj['Title'] = "--NO INFO--"
obj['Type'] = obj['LibraryName']

if self.EmbyServer.Utils.DatabaseFiles['music-version'] >= 82:
obj['AlbumId'] = self.MusicDBIO.get_album(*self.EmbyServer.Utils.values(obj, queries_music.get_single_obj82))
else:
obj['AlbumId'] = self.MusicDBIO.get_album(*self.EmbyServer.Utils.values(obj, queries_music.get_single_obj))

obj['Title'] = BackupTitle

if not self.MusicDBIO.add_song(*self.EmbyServer.Utils.values(obj, queries_music.add_song_obj)):
obj['Index'] = None #Duplicate track number for same album
self.MusicDBIO.add_song(*self.EmbyServer.Utils.values(obj, queries_music.add_song_obj))
Expand Down Expand Up @@ -356,7 +333,6 @@ def song_artist_discography(self, obj):
continue

self.MusicDBIO.link(*self.EmbyServer.Utils.values(temp_obj, queries_music.update_link_obj))
self.item_ids.append(temp_obj['Id'])

if obj['Album']:
temp_obj['Title'] = obj['Album']
Expand All @@ -373,21 +349,41 @@ def song_artist_link(self, obj):
temp_obj['Name'] = artist['Name']
temp_obj['Id'] = artist['Id']
temp_obj['Index'] = index
Data = self.emby_db.get_item_by_id(*self.EmbyServer.Utils.values(temp_obj, database.queries.get_item_obj))
Data = self.emby_db.get_item_by_id(artist['Id'])

if Data:
temp_obj['ArtistId'] = Data[0]
else:
self.artist(self.EmbyServer.API.get_item(temp_obj['Id']), library=None)
Result = self.emby_db.get_item_by_id(*self.EmbyServer.Utils.values(temp_obj, database.queries.get_item_obj))

if Result:
temp_obj['ArtistId'] = Result[0]
else:
continue
self.artist(self.EmbyServer.API.get_item(artist['Id']), self.library)
temp_obj['ArtistId'] = self.emby_db.get_item_by_id(artist['Id'])[0]

self.MusicDBIO.link_song_artist(*self.EmbyServer.Utils.values(temp_obj, queries_music.update_song_artist_obj))
self.item_ids.append(temp_obj['Id'])

def song_album_link(self, obj):
if obj['SongAlbumId']:
temp_obj = dict(obj)
temp_obj['Name'] = obj['Album']
temp_obj['AlbumId'] = obj['SongAlbumId']
Data = self.emby_db.get_item_by_id(obj['SongAlbumId'])

if Data:
temp_obj['AlbumId'] = Data[0]
else:
self.album(self.EmbyServer.API.get_item(obj['SongAlbumId']), self.library)
else: # Single
temp_obj = dict(obj)
temp_obj['Title'] = "--NO INFO--"
temp_obj['AlbumId'] = None
temp_obj['Year'] = None
temp_obj['LastScraped'] = None
temp_obj['Type'] = obj['LibraryName']

if self.EmbyServer.Utils.DatabaseFiles['music-version'] >= 82:
temp_obj['AlbumId'] = self.MusicDBIO.get_album(*self.EmbyServer.Utils.values(temp_obj, queries_music.get_single_obj82))
else:
temp_obj['AlbumId'] = self.MusicDBIO.get_album(*self.EmbyServer.Utils.values(temp_obj, queries_music.get_single_obj))

return temp_obj['AlbumId']

#This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
#Poster with progress bar
Expand Down Expand Up @@ -611,35 +607,37 @@ def validate_song(self, *args):

return None

def get_album(self, album_id, name, musicbrainz, Type, artists, *args):
def get_album(self, album_id, name, musicbrainz, AlbumOrSingle, artists, *args):
if musicbrainz:
self.cursor.execute(queries_music.get_album, (musicbrainz,))
album = None
else:
self.cursor.execute(queries_music.get_album_by_name, (name, artists,))
self.cursor.execute(queries_music.get_album_by_name_type, (name, artists, args[len(args) - 1],))
album = self.cursor.fetchone()

album = self.cursor.fetchone()
album_id = (album or self.cursor.fetchone())
try:
album_id = (album or self.cursor.fetchone())[0]
except:
album_id = None

if album_id:
album_id = album_id[0]
else:
album_id = self.add_album(*(album_id, name, musicbrainz, Type, artists,) + args)
if not album_id:
album_id = self.add_album(*(album_id, name, musicbrainz, AlbumOrSingle, artists,) + args)

return album_id

def add_album(self, album_id, name, musicbrainz, Type, artists, *args):
def add_album(self, album_id, name, musicbrainz, AlbumOrSingle, artists, *args):
album_id = album_id or self.create_entry_album()

if Type == "album":
if AlbumOrSingle == "album":
if self.DBVersion >= 82:
self.cursor.execute(queries_music.add_album82, (album_id, name, musicbrainz, Type, artists,) + args)
self.cursor.execute(queries_music.add_album82, (album_id, name, musicbrainz, AlbumOrSingle, artists,) + args)
else:
self.cursor.execute(queries_music.add_album, (album_id, name, musicbrainz, Type, artists,) + args)
self.cursor.execute(queries_music.add_album, (album_id, name, musicbrainz, AlbumOrSingle, artists,) + args)
else: #single
if self.DBVersion >= 82:
self.cursor.execute(queries_music.add_single82, (album_id, name, musicbrainz, Type, artists,) + args)
self.cursor.execute(queries_music.add_single82, (album_id, name, musicbrainz, AlbumOrSingle, artists,) + args)
else:
self.cursor.execute(queries_music.add_single, (album_id, name, musicbrainz, Type, artists,) + args)
self.cursor.execute(queries_music.add_single, (album_id, name, musicbrainz, AlbumOrSingle, artists,) + args)

return album_id

Expand Down Expand Up @@ -689,6 +687,9 @@ def update_song(self, *args):
def link_song_artist(self, *args):
self.cursor.execute(queries_music.update_song_artist, args)

def link_song_album(self, *args):
self.cursor.execute(queries_music.update_song_album, args)

def rate_song(self, *args):
self.cursor.execute(queries_music.update_song_rating, args)

Expand Down
2 changes: 0 additions & 2 deletions core/musicvideos.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def __init__(self, EmbyServer, embydb, videodb):
self.video = videodb
self.emby_db = database.emby_db.EmbyDatabase(embydb.cursor)
self.objects = obj_ops.Objects()
self.item_ids = []
self.Common = common.Common(self.emby_db, self.objects, self.EmbyServer)
self.MusicVideosDBIO = MusicVideosDBIO(videodb.cursor)
self.KodiDBIO = kodi.Kodi(videodb.cursor, self.EmbyServer.Utils)
Expand Down Expand Up @@ -136,7 +135,6 @@ def musicvideo(self, item, library):
self.KodiDBIO.add_people(*self.EmbyServer.Utils.values(obj, queries_videos.add_people_mvideo_obj))
self.KodiDBIO.add_streams(*self.EmbyServer.Utils.values(obj, queries_videos.add_streams_obj))
self.ArtworkDBIO.add(obj['Artwork'], obj['MvideoId'], "musicvideo")
self.item_ids.append(obj['Id'])

if "StackTimes" in obj:
self.KodiDBIO.add_stacktimes(*self.EmbyServer.Utils.values(obj, queries_videos.add_stacktimes_obj))
Expand Down
1 change: 1 addition & 0 deletions core/queries_music.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
get_song_by_id_obj = ["{SongId}"]
get_album = """ SELECT idAlbum FROM album WHERE strMusicBrainzAlbumID = ? """
get_album_by_name = """ SELECT idAlbum FROM album WHERE strAlbum = ? AND strArtistDisp = ? """
get_album_by_name_type = """ SELECT idAlbum FROM album WHERE strAlbum = ? AND strArtistDisp = ? AND strType = ? """
get_album_artist = """ SELECT strArtistDisp FROM album WHERE idAlbum = ? """
get_album_artist_obj = ["{AlbumId}", "{strAlbumArtists}"]
get_genre = """ SELECT idGenre FROM genre WHERE strGenre = ? COLLATE NOCASE """
Expand Down
6 changes: 0 additions & 6 deletions core/tvshows.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def __init__(self, EmbyServer, embydb, videodb, update_library=False):
self.video = videodb
self.emby_db = database.emby_db.EmbyDatabase(embydb.cursor)
self.objects = obj_ops.Objects()
self.item_ids = []
self.Common = common.Common(self.emby_db, self.objects, self.EmbyServer)
self.KodiDBIO = kodi.Kodi(videodb.cursor, self.EmbyServer.Utils)
self.TVShowsDBIO = TVShowsDBIO(videodb.cursor)
Expand Down Expand Up @@ -112,7 +111,6 @@ def tvshow(self, item, library, pooling=None, redirect=None):
self.KodiDBIO.add_genres(*self.EmbyServer.Utils.values(obj, queries_videos.add_genres_tvshow_obj))
self.KodiDBIO.add_studios(*self.EmbyServer.Utils.values(obj, queries_videos.add_studios_tvshow_obj))
self.ArtworkDBIO.add(obj['Artwork'], obj['ShowId'], "tvshow")
self.item_ids.append(obj['Id'])

if "StackTimes" in obj:
self.KodiDBIO.add_stacktimes(*self.EmbyServer.Utils.values(obj, queries_videos.add_stacktimes_obj))
Expand All @@ -136,7 +134,6 @@ def tvshow(self, item, library, pooling=None, redirect=None):

try:
self.emby_db.get_item_by_id(season['Id'])[0]
self.item_ids.append(season['Id'])
except TypeError:
self.season(season, library, obj['ShowId'])

Expand Down Expand Up @@ -243,7 +240,6 @@ def season(self, item, library, show_id=None):

if obj['Location'] != 'Virtual':
self.emby_db.add_reference(*self.EmbyServer.Utils.values(obj, database.queries.add_reference_season_obj))
self.item_ids.append(obj['Id'])

self.ArtworkDBIO.add(obj['Artwork'], obj['SeasonId'], "season")
self.LOG.info("UPDATE season [%s/%s] %s: %s" % (obj['ShowId'], obj['SeasonId'], obj['Title'] or obj['Index'], obj['Id']))
Expand Down Expand Up @@ -362,7 +358,6 @@ def episode(self, item, library):
self.KodiDBIO.add_streams(*self.EmbyServer.Utils.values(obj, queries_videos.add_streams_obj))
self.KodiDBIO.add_playstate(*self.EmbyServer.Utils.values(obj, queries_videos.add_bookmark_obj))
self.ArtworkDBIO.update(obj['Artwork']['Primary'], obj['EpisodeId'], "episode", "thumb")
self.item_ids.append(obj['Id'])
return not update

#Add object to kodi
Expand Down Expand Up @@ -433,7 +428,6 @@ def get_show_id(self, obj):
else:
obj['ShowId'] = obj['ShowId'][0]

self.item_ids.append(obj['SeriesId'])
return True

#This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
Expand Down
3 changes: 3 additions & 0 deletions database/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(self, Player, EmbyServer):
self.Views = emby.views.Views(self.EmbyServer)
self.progress_percent = 0
self.Xmls = helper.xmls.Xmls(self.EmbyServer.Utils)

threading.Thread.__init__(self)
self.start()

Expand Down Expand Up @@ -114,6 +115,8 @@ def update_progress_dialog(self, item):

def run(self):
self.LOG.warning("--->[ library ]")
self.Xmls.advanced_settings()
self.Xmls.advanced_settings_add_timeouts()
self.Views.update_views()
self.sync.update_library = False

Expand Down
Loading

0 comments on commit f983d8b

Please sign in to comment.