Skip to content

Commit

Permalink
Merge pull request #284 from angelblue05/master
Browse files Browse the repository at this point in the history
4.1.3
  • Loading branch information
angelblue05 authored Jul 8, 2019
2 parents 9838454 + c890cc6 commit fda167f
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 55 deletions.
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.emby"
name="Emby"
version="4.1.2"
version="4.1.3"
provider-name="angelblue05, sualfred">
<requires>
<import addon="xbmc.python" version="2.25.0"/>
Expand Down
16 changes: 13 additions & 3 deletions libraries/emby/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def emby_url(client, handler):
return "%s/emby/%s" % (client.config['auth.server'], handler)

def basic_info():
return "Etag"
return "Etag,PresentationUniqueKey"

def info():
return (
Expand All @@ -23,14 +23,16 @@ def info():
"Metascore,AirTime,DateCreated,People,Overview,CommunityRating,StartDate,"
"CriticRating,CriticRatingSummary,Etag,ShortOverview,ProductionLocations,"
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers,Status,EndDate,"
"MediaSources,VoteCount,RecursiveItemCount,PrimaryImageAspectRatio,DisplayOrder"
"MediaSources,VoteCount,RecursiveItemCount,PrimaryImageAspectRatio,DisplayOrder,"
"PresentationUniqueKey"
)

def music_info():
return (
"Etag,Genres,SortName,Studios,Writer,PremiereDate,ProductionYear,"
"OfficialRating,CumulativeRunTimeTicks,Metascore,CommunityRating,"
"AirTime,DateCreated,MediaStreams,People,ProviderIds,Overview,ItemCounts"
"AirTime,DateCreated,MediaStreams,People,ProviderIds,Overview,ItemCounts,"
"PresentationUniqueKey"
)

#################################################################################################
Expand Down Expand Up @@ -398,6 +400,10 @@ def is_valid_series(self, parent_id, name, item_id):
'''
try:
result = self.search(name, "Series")['SearchHints']

if len(result) == 1:
return str(result[0]['Id'])

for item in result:

if str(item['Id']) == item_id:
Expand Down Expand Up @@ -425,6 +431,10 @@ def is_valid_movie(self, parent_id, name, item_id):
'''
try:
result = self.search(name, "Movie")['SearchHints']

if len(result) == 1:
return str(result[0]['Id'])

for item in result:

if str(item['Id']) == item_id:
Expand Down
4 changes: 2 additions & 2 deletions resources/language/resource.language.de_de/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -1158,8 +1158,8 @@ msgstr "Patch Update zurücksetzen"

msgctxt "#33212"
msgid "Latest release"
msgstr ""
msgstr "Letzte Version"

msgctxt "#33213"
msgid "Enable label for multi-episodes. i.e. | # | title"
msgstr ""
msgstr "Aktiviere Markierung für Multi Episoden zB. | # | titel"
9 changes: 8 additions & 1 deletion resources/lib/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,18 @@ def emby_tables(cursor):
cursor.execute("CREATE TABLE IF NOT EXISTS version(idVersion TEXT)")

columns = cursor.execute("SELECT * FROM emby")
if 'emby_parent_id' not in [description[0] for description in columns.description]:
descriptions = [description[0] for description in columns.description]

if 'emby_parent_id' not in descriptions:

LOG.info("Add missing column emby_parent_id")
cursor.execute("ALTER TABLE emby ADD COLUMN emby_parent_id 'TEXT'")

if 'presentation_key' not in descriptions:

LOG.info("Add missing column presentation_key")
cursor.execute("ALTER TABLE emby ADD COLUMN presentation_key 'TEXT'")

def reset():

''' Reset both the emby database and the kodi database.
Expand Down
9 changes: 9 additions & 0 deletions resources/lib/database/emby_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ def get_items_by_media(self, *args):
def remove_media_by_parent_id(self, *args):
self.cursor.execute(QU.delete_media_by_parent_id, args)

def get_stack(self, *args):

try:
self.cursor.execute(QU.get_presentation_key, args)

return self.cursor.fetchone()[0]
except Exception as error:
return

def get_version(self, version=None):

if version is not None:
Expand Down
30 changes: 18 additions & 12 deletions resources/lib/database/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,38 +83,44 @@
get_version = """ SELECT idVersion
FROM version
"""
get_presentation_key = """ SELECT emby_id
FROM emby
WHERE presentation_key = ?
"""



add_reference = """ INSERT OR REPLACE INTO emby(emby_id, kodi_id, kodi_fileid, kodi_pathid, emby_type,
media_type, parent_id, checksum, media_folder, emby_parent_id)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
media_type, parent_id, checksum, media_folder, emby_parent_id,
presentation_key)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
"""
add_reference_movie_obj = [ "{Id}","{MovieId}","{FileId}","{PathId}","Movie","movie", None,"{Checksum}","{LibraryId}",
"{EmbyParentId}"
"{EmbyParentId}","{PresentationKey}"
]
add_reference_boxset_obj = [ "{Id}","{SetId}",None,None,"BoxSet","set",None,"{Checksum}",None,None
add_reference_boxset_obj = [ "{Id}","{SetId}",None,None,"BoxSet","set",None,"{Checksum}",None,None,"{PresentationKey}"
]
add_reference_tvshow_obj = [ "{Id}","{ShowId}",None,"{PathId}","Series","tvshow",None,"{Checksum}","{LibraryId}",
"{EmbyParentId}"
"{EmbyParentId}","{PresentationKey}"
]
add_reference_season_obj = [ "{Id}","{SeasonId}",None,None,"Season","season","{ShowId}",None,None,None
add_reference_season_obj = [ "{Id}","{SeasonId}",None,None,"Season","season","{ShowId}",None,None,None,"{PresentationKey}"
]
add_reference_pool_obj = [ "{SeriesId}","{ShowId}",None,"{PathId}","Series","tvshow",None,"{Checksum}","{LibraryId}",None
add_reference_pool_obj = [ "{SeriesId}","{ShowId}",None,"{PathId}","Series","tvshow",None,"{Checksum}","{LibraryId}",None,"{PresentationKey}"
]
add_reference_episode_obj = [ "{Id}","{EpisodeId}","{FileId}","{PathId}","Episode","episode","{SeasonId}","{Checksum}",
None,"{EmbyParentId}"
None,"{EmbyParentId}","{PresentationKey}"
]
add_reference_mvideo_obj = [ "{Id}","{MvideoId}","{FileId}","{PathId}","MusicVideo","musicvideo",None,"{Checksum}",
"{LibraryId}","{EmbyParentId}"
"{LibraryId}","{EmbyParentId}","{PresentationKey}"
]
add_reference_artist_obj = [ "{Id}","{ArtistId}",None,None,"{ArtistType}","artist",None,"{Checksum}","{LibraryId}",
"{EmbyParentId}"
"{EmbyParentId}","{PresentationKey}"
]
add_reference_album_obj = [ "{Id}","{AlbumId}",None,None,"MusicAlbum","album",None,"{Checksum}",None,"{EmbyParentId}"
add_reference_album_obj = [ "{Id}","{AlbumId}",None,None,"MusicAlbum","album",None,"{Checksum}",None,"{EmbyParentId}",
"{PresentationKey}"
]
add_reference_song_obj = [ "{Id}","{SongId}",None,"{PathId}","Audio","song","{AlbumId}","{Checksum}",
None,"{EmbyParentId}"
None,"{EmbyParentId}","{PresentationKey}"
]
add_view = """ INSERT OR REPLACE INTO view(view_id, view_name, media_type)
VALUES (?, ?, ?)
Expand Down
8 changes: 5 additions & 3 deletions resources/lib/hooks/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def set_audio_subs(self, audio=None, subtitle=None):
if audio and len(self.get_available_audio_streams()) > 1:
self.set_audio_stream(audio - 1)

if subtitle == -1 or subtitle is None:
if subtitle is None or subtitle == -1:
self.set_subtitle(False)

return
Expand Down Expand Up @@ -246,7 +246,7 @@ def _get_items(self):
def _set_items(self, items):
window('emby.play.json', items)

def set_item(self, file):
def set_item(self, file, track=True):

''' Call when playback start to setup play entry in player tracker.
'''
Expand Down Expand Up @@ -323,7 +323,9 @@ def set_item(self, file):
'SubtitleStreamIndex': item['SubtitleStreamIndex']
}
item['Server']['api'].session_playing(data)
item['Track'] = True

if track:
item['Track'] = True

if self.monitor.waitForAbort(2):
return
Expand Down
16 changes: 10 additions & 6 deletions resources/lib/hooks/webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import xbmcgui
import xbmcvfs

from helper import settings, window, JSONRPC
from helper import settings, window, dialog, JSONRPC

#################################################################################################

Expand Down Expand Up @@ -307,9 +307,6 @@ def run(self):

while True:
try:
if not window('emby_online.bool'):
raise Exception("NotConnected")

try:
params = self.server.queue.get(timeout=0.01)
except Queue.Empty:
Expand All @@ -333,8 +330,10 @@ def run(self):
if play_folder:

LOG.info("[ start play/folder ]")
window('emby.playlist.play.bool', True)
objects.utils.disable_busy_dialog()
play.start_playback()

elif window('emby.playlist.audio.bool'):

LOG.info("[ start play/relaunch ]")
Expand All @@ -350,7 +349,12 @@ def run(self):

break

play = objects.PlayStrm(params, params.get('server'))
server = params.get('server')

if not server and not window('emby_online.bool'):
raise Exception("NotConnected")

play = objects.PlayStrm(params, server)

if start_position is None:

Expand All @@ -376,7 +380,7 @@ def run(self):
play_folder = True

window('emby.playlist.start', str(start_position))
position = play.play(start_position=position)
position = play.play(play_folder, position)
playlist = play.info['KodiPlaylist']

if play_folder:
Expand Down
56 changes: 30 additions & 26 deletions resources/lib/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def __init__(self, monitor):
self.writer_threads = {'updated': [], 'userdata': [], 'removed': []}
self.database_lock = threading.Lock()
self.music_database_lock = threading.Lock()
self.sync = Sync

threading.Thread.__init__(self)
self.start()
Expand Down Expand Up @@ -113,6 +114,9 @@ def run(self):
if not self.started and not self.startup():
self.stop_client()

if self.sync.running:
continue

self.service()
except LibraryException as error:

Expand Down Expand Up @@ -389,15 +393,15 @@ def worker_add_lib(self):

def sync_libraries(self, forced=False):

with Sync(self, self.server) as sync:
with self.sync(self, self.server) as sync:
sync.libraries(forced=forced)

Views().get_nodes()

def _add_libraries(self, library_id, update=False):

try:
with Sync(self, server=self.server) as sync:
with self.sync(self, server=self.server) as sync:
sync.libraries(library_id, update)

except LibraryException as error:
Expand All @@ -412,7 +416,7 @@ def _add_libraries(self, library_id, update=False):
def _remove_libraries(self, library_id):

try:
with Sync(self, self.server) as sync:
with self.sync(self, self.server) as sync:
sync.remove_library(library_id)

except LibraryException as error:
Expand Down Expand Up @@ -442,7 +446,7 @@ def startup(self):

elif not settings('SyncInstallRunDone.bool'):

with Sync(self, self.server) as sync:
with self.sync(self, self.server) as sync:
sync.libraries()

Views().get_nodes()
Expand Down Expand Up @@ -484,32 +488,35 @@ def startup(self):
return False

def get_fast_sync(self):

new_fast_sync = compare_version(self.server['auth/server-version'],"4.2.0.23")
enable_fast_sync = False

if settings('SyncInstallRunDone.bool'):
if settings('kodiCompanion.bool'):

if settings('kodiCompanion.bool'):
for plugin in self.server['api'].get_plugins():

if plugin['Name'] in ("Emby.Kodi Sync Queue", "Kodi companion"):

if new_fast_sync > 0:
if not self.fast_sync():
dialog("ok", heading="{emby}", line1=_(33128))
enable_fast_sync = True

raise Exception("Failed to retrieve latest updates")
break

elif not self.fast_sync_plugin():
dialog("ok", heading="{emby}", line1=_(33128))
if new_fast_sync > 0:
self.fast_sync(enable_fast_sync)

raise Exception("Failed to retrieve latest updates")
elif enable_fast_sync:

LOG.info("--<[ retrieve changes ]")
if not self.fast_sync_plugin():
dialog("ok", heading="{emby}", line1=_(33128))

break
raise Exception("Failed to retrieve latest updates")
else:
raise LibraryException('CompanionMissing')

def fast_sync(self):
LOG.info("--<[ retrieve changes ]")

def fast_sync(self, plugin):

''' Movie and userdata not provided by server yet.
'''
Expand All @@ -532,16 +539,13 @@ def fast_sync(self):
if query['Type'] in self.userdata_output:
self.userdata_output[query['Type']].put(query)

try:
removed = []
result = self.server['api'].get_sync_queue(last_sync)
removed.extend(result['ItemsRemoved'])
self.removed(removed)

except Exception as error:
LOG.exception(error)
if plugin:
try:
result = self.server['api'].get_sync_queue(last_sync)
self.removed(result['ItemsRemoved'])

return False
except Exception as error:
LOG.exception(error)

return True

Expand Down Expand Up @@ -649,7 +653,7 @@ def select_libraries(self, mode=None):
def run_library_task(self, task, notification=False):

try:
with Sync(self, server=self.server) as sync:
with self.sync(self, server=self.server) as sync:
sync[task](notification)
except Exception as error:
LOG.exception(error)
Expand Down
Loading

0 comments on commit fda167f

Please sign in to comment.