From 89afd46b56ef547f55ba885e6b4bb3f246e5a0ce Mon Sep 17 00:00:00 2001 From: croneter Date: Mon, 25 Jan 2021 13:01:03 +0100 Subject: [PATCH 1/7] Fix OSError: Invalid argument when Plex returns an invalid timestamp --- resources/lib/timing.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/resources/lib/timing.py b/resources/lib/timing.py index 5ace8a90..5f0f1909 100644 --- a/resources/lib/timing.py +++ b/resources/lib/timing.py @@ -1,9 +1,12 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import absolute_import, division, unicode_literals +from logging import getLogger from datetime import datetime, timedelta from time import localtime, strftime +LOG = getLogger('PLEX.timing') + EPOCH = datetime.utcfromtimestamp(0) @@ -29,7 +32,13 @@ def unix_date_to_kodi(unix_kodi_time): Output: Y-m-d h:m:s = 2009-04-05 23:16:04 """ - return strftime('%Y-%m-%d %H:%M:%S', localtime(float(unix_kodi_time))) + try: + return strftime('%Y-%m-%d %H:%M:%S', localtime(float(unix_kodi_time))) + except Exception: + LOG.exception('Received an illegal timestamp from Plex: %s. ' + 'Using 1970-01-01 12:00:00', + unix_kodi_time) + return '1970-01-01 12:00:00' def plex_date_to_kodi(plex_timestamp): From 281c7d1599118bd19fde6252f64d19b9af4fdc73 Mon Sep 17 00:00:00 2001 From: croneter Date: Wed, 27 Jan 2021 15:45:09 +0100 Subject: [PATCH 2/7] Fix ValueError when deleting a music album --- resources/lib/itemtypes/music.py | 6 ------ resources/lib/kodi_db/music.py | 32 -------------------------------- 2 files changed, 38 deletions(-) diff --git a/resources/lib/itemtypes/music.py b/resources/lib/itemtypes/music.py index 7e2721cc..ddd26d2f 100644 --- a/resources/lib/itemtypes/music.py +++ b/resources/lib/itemtypes/music.py @@ -135,7 +135,6 @@ class MusicMixin(object): ''' Remove an album ''' - self.kodidb.delete_album_from_discography(kodi_id) if v.KODIVERSION < 18: self.kodidb.delete_album_from_album_genre(kodi_id) self.kodidb.remove_album(kodi_id) @@ -353,11 +352,6 @@ class Album(MusicMixin, ItemBase): timing.unix_date_to_kodi(self.last_sync), 'album') self.kodidb.add_albumartist(artist_id, kodi_id, api.artist_name()) - if v.KODIVERSION < 18: - self.kodidb.add_discography(artist_id, name, api.year()) - self.kodidb.add_music_genres(kodi_id, - api.genres(), - v.KODI_TYPE_ALBUM) if app.SYNC.artwork: self.kodidb.modify_artwork(artworks, kodi_id, diff --git a/resources/lib/kodi_db/music.py b/resources/lib/kodi_db/music.py index 50993806..ad61a459 100644 --- a/resources/lib/kodi_db/music.py +++ b/resources/lib/kodi_db/music.py @@ -106,26 +106,6 @@ class KodiMusicDB(common.KodiDBBase): self.cursor.execute('DELETE FROM song_artist WHERE idSong = ?', (song_id, )) - @db.catch_operationalerrors - def delete_album_from_discography(self, album_id): - """ - Removes the album with id album_id from the table discography - """ - # Need to get the album name as a string first! - self.cursor.execute('SELECT strAlbum, iYear FROM album WHERE idAlbum = ? LIMIT 1', - (album_id, )) - try: - name, year = self.cursor.fetchone() - except TypeError: - return - self.cursor.execute('SELECT idArtist FROM album_artist WHERE idAlbum = ? LIMIT 1', - (album_id, )) - artist = self.cursor.fetchone() - if not artist: - return - self.cursor.execute('DELETE FROM discography WHERE idArtist = ? AND strAlbum = ? AND strYear = ?', - (artist[0], name, year)) - @db.catch_operationalerrors def delete_song_from_song_genre(self, song_id): """ @@ -352,16 +332,6 @@ class KodiMusicDB(common.KodiDBBase): VALUES (?, ?, ?) ''', (artist_id, kodi_id, artistname)) - @db.catch_operationalerrors - def add_discography(self, artist_id, albumname, year): - self.cursor.execute(''' - INSERT OR REPLACE INTO discography( - idArtist, - strAlbum, - strYear) - VALUES (?, ?, ?) - ''', (artist_id, albumname, year)) - @db.catch_operationalerrors def add_music_genres(self, kodiid, genres, mediatype): """ @@ -656,5 +626,3 @@ class KodiMusicDB(common.KodiDBBase): (kodi_id, )) self.cursor.execute('DELETE FROM song_artist WHERE idArtist = ?', (kodi_id, )) - self.cursor.execute('DELETE FROM discography WHERE idArtist = ?', - (kodi_id, )) From f187111411d83aa3e2760d6d809c7c0738b76074 Mon Sep 17 00:00:00 2001 From: croneter Date: Wed, 27 Jan 2021 16:28:25 +0100 Subject: [PATCH 3/7] Fix PKC not auto-picking audio/subtitle stream when transcoding --- .../resource.language.en_gb/strings.po | 2 +- resources/lib/playback_decision.py | 50 ++++++++++++------- resources/settings.xml | 2 +- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 380936d4..58da1619 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -630,7 +630,7 @@ msgstr "" # PKC Settings - Playback msgctxt "#30541" -msgid "Don't ask to pick a certain stream/quality" +msgid "Transcoding: Auto-pick audio and subtitle stream using Plex defaults" msgstr "" # PKC Settings - Playback diff --git a/resources/lib/playback_decision.py b/resources/lib/playback_decision.py index d2e498a5..33d606f0 100644 --- a/resources/lib/playback_decision.py +++ b/resources/lib/playback_decision.py @@ -349,8 +349,14 @@ def audio_subtitle_prefs(api, item): action_type='PUT', parameters=args) return True + return setup_transcoding_audio_subtitle_prefs(mediastreams, part_id) + + +def setup_transcoding_audio_subtitle_prefs(mediastreams, part_id): audio_streams_list = [] audio_streams = [] + audio_default = None + subtitle_default = None subtitle_streams_list = [] # "Don't burn-in any subtitle" subtitle_streams = ['1 %s' % utils.lang(39706)] @@ -379,6 +385,8 @@ def audio_subtitle_prefs(api, item): utils.lang(39707), # unknown codec, channellayout) + if stream.get('default'): + audio_default = audio_numb audio_streams_list.append(index) audio_streams.append(track.encode('utf-8')) audio_numb += 1 @@ -391,7 +399,6 @@ def audio_subtitle_prefs(api, item): continue # Subtitle is available within the video file # Burn in the subtitle, if user chooses to do so - default = stream.get('default') forced = stream.get('forced') try: track = '{} {}'.format(sub_num + 1, @@ -400,7 +407,8 @@ def audio_subtitle_prefs(api, item): track = '{} {} ({})'.format(sub_num + 1, utils.lang(39707), # unknown stream.get('codec')) - if default: + if stream.get('default'): + subtitle_default = sub_num track = "%s - %s" % (track, utils.lang(39708)) # Default if forced: track = "%s - %s" % (track, utils.lang(39709)) # Forced @@ -410,10 +418,14 @@ def audio_subtitle_prefs(api, item): sub_num += 1 if audio_numb > 1: - resp = utils.dialog('select', utils.lang(33013), audio_streams) - if resp == -1: - LOG.info('User aborted dialog to select audio stream') - return + # "Transcoding: Auto-pick audio and subtitle stream using Plex defaults" + if utils.settings('bestQuality') == 'true' and audio_default is not None: + resp = audio_default + else: + resp = utils.dialog('select', utils.lang(33013), audio_streams) + if resp == -1: + LOG.info('User aborted dialog to select audio stream') + return args = { 'audioStreamID': audio_streams_list[resp], 'allParts': 1 @@ -428,18 +440,22 @@ def audio_subtitle_prefs(api, item): # Otherwise, the PMS might pick-up the last one LOG.info('No subtitles to burn-in') else: - resp = utils.dialog('select', utils.lang(33014), subtitle_streams) - if resp == -1: - LOG.info('User aborted dialog to select subtitle stream') - return - elif resp == 0: - # User did not select a subtitle or backed out of the dialog - LOG.info('User chose to not burn-in any subtitles') + # "Transcoding: Auto-pick audio and subtitle stream using Plex defaults" + if utils.settings('bestQuality') == 'true' and subtitle_default is not None: + resp = subtitle_default else: - LOG.info('User chose to burn-in subtitle %s: %s', - select_subs_index, - subtitle_streams[resp].decode('utf-8')) - select_subs_index = subtitle_streams_list[resp - 1] + resp = utils.dialog('select', utils.lang(33014), subtitle_streams) + if resp == -1: + LOG.info('User aborted dialog to select subtitle stream') + return + elif resp == 0: + # User did not select a subtitle or backed out of the dialog + LOG.info('User chose to not burn-in any subtitles') + else: + LOG.info('User chose to burn-in subtitle %s: %s', + select_subs_index, + subtitle_streams[resp].decode('utf-8')) + select_subs_index = subtitle_streams_list[resp - 1] # Now prep the PMS for our choice args = { 'subtitleStreamID': select_subs_index, diff --git a/resources/settings.xml b/resources/settings.xml index 5b143128..6b943a83 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -120,7 +120,7 @@ - + From 01fb1d5da6dc161c215679391cdead9f2e918a88 Mon Sep 17 00:00:00 2001 From: croneter Date: Thu, 28 Jan 2021 13:35:22 +0100 Subject: [PATCH 4/7] Beta version bump 2.12.11 --- addon.xml | 9 +++++++-- changelog.txt | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/addon.xml b/addon.xml index 5bf25694..531210d6 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@ - + @@ -83,7 +83,12 @@ Natūralioji „Plex“ integracija į „Kodi“ Prijunkite „Kodi“ prie „Plex Medija Serverio“. Šiame papildinyje daroma prielaida, kad valdote visus savo vaizdo įrašus naudodami „Plex“ (ir nė vieno su „Kodi“). Galite prarasti jau saugomus „Kodi“ vaizdo įrašų ir muzikos duomenų bazių duomenis (kadangi šis papildinys juos tiesiogiai pakeičia). Naudokite savo pačių rizika! Naudokite savo pačių rizika - version 2.12.10: + version 2.12.11 (beta only): +- Fix PKC not auto-picking audio/subtitle stream when transcoding +- Fix ValueError when deleting a music album +- Fix OSError: Invalid argument when Plex returns an invalid timestamp + +version 2.12.10: - Fix pictures from Plex picture libraries not working/displaying version 2.12.9: diff --git a/changelog.txt b/changelog.txt index e508d772..29fccdd2 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,8 @@ +version 2.12.11 (beta only): +- Fix PKC not auto-picking audio/subtitle stream when transcoding +- Fix ValueError when deleting a music album +- Fix OSError: Invalid argument when Plex returns an invalid timestamp + version 2.12.10: - Fix pictures from Plex picture libraries not working/displaying From 269dedf398233164a7059c7b5c36896421a5a876 Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 31 Jan 2021 17:20:17 +0100 Subject: [PATCH 5/7] ValueError: invalid literal for int() for invalid dates sent by Plex --- resources/lib/library_sync/fill_metadata_queue.py | 4 ++-- resources/lib/plex_api/base.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/lib/library_sync/fill_metadata_queue.py b/resources/lib/library_sync/fill_metadata_queue.py index 492db28c..6e7f717d 100644 --- a/resources/lib/library_sync/fill_metadata_queue.py +++ b/resources/lib/library_sync/fill_metadata_queue.py @@ -41,8 +41,8 @@ class FillMetadataQueue(common.LibrarySyncMixin, plex_id = int(xml.get('ratingKey')) checksum = int('{}{}'.format( plex_id, - xml.get('updatedAt', - xml.get('addedAt', '1541572987')).replace('-', ''))) + abs(int(xml.get('updatedAt', + xml.get('addedAt', '1541572987')))))) if (not self.repair and plexdb.checksum(plex_id, section.plex_type) == checksum): continue diff --git a/resources/lib/plex_api/base.py b/resources/lib/plex_api/base.py index f20178e7..b4c4a859 100644 --- a/resources/lib/plex_api/base.py +++ b/resources/lib/plex_api/base.py @@ -231,8 +231,8 @@ class Base(object): addedAt is used. """ return int('%s%s' % (self.xml.get('ratingKey'), - self.xml.get('updatedAt') or - self.xml.get('addedAt', '1541572987'))) + abs(int(self.xml.get('updatedAt') or + self.xml.get('addedAt', '1541572987'))))) def title(self): """ From f192c0912c6ecdc04f9485f25489485d6e724d83 Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 31 Jan 2021 17:39:44 +0100 Subject: [PATCH 6/7] Hopefully fix rare case when sync would get stuck indefinitely --- resources/lib/backgroundthread.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/resources/lib/backgroundthread.py b/resources/lib/backgroundthread.py index 831b3274..5c095720 100644 --- a/resources/lib/backgroundthread.py +++ b/resources/lib/backgroundthread.py @@ -136,6 +136,11 @@ class ProcessingQueue(Queue.Queue, object): return self._current_queue._qsize() if self._current_queue else 0 def _total_qsize(self): + """ + This method is BROKEN as it can lead to a deadlock when a single item + from the current section takes longer to download then any new items + coming in + """ return sum(q._qsize() for q in self._queues) if self._queues else 0 def put(self, item, block=True, timeout=None): @@ -147,16 +152,16 @@ class ProcessingQueue(Queue.Queue, object): try: if self.maxsize > 0: if not block: - if self._total_qsize() == self.maxsize: + if self._qsize() == self.maxsize: raise Queue.Full elif timeout is None: - while self._total_qsize() == self.maxsize: + while self._qsize() == self.maxsize: self.not_full.wait() elif timeout < 0: raise ValueError("'timeout' must be a non-negative number") else: endtime = _time() + timeout - while self._total_qsize() == self.maxsize: + while self._qsize() == self.maxsize: remaining = endtime - _time() if remaining <= 0.0: raise Queue.Full From 1b56f5cef98962391825a59da83e2e3d3d00d11a Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 31 Jan 2021 17:49:59 +0100 Subject: [PATCH 7/7] Stable and beta version bump 2.12.12 --- addon.xml | 9 +++++++-- changelog.txt | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/addon.xml b/addon.xml index 531210d6..e8dd5c02 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@ - + @@ -83,7 +83,12 @@ Natūralioji „Plex“ integracija į „Kodi“ Prijunkite „Kodi“ prie „Plex Medija Serverio“. Šiame papildinyje daroma prielaida, kad valdote visus savo vaizdo įrašus naudodami „Plex“ (ir nė vieno su „Kodi“). Galite prarasti jau saugomus „Kodi“ vaizdo įrašų ir muzikos duomenų bazių duomenis (kadangi šis papildinys juos tiesiogiai pakeičia). Naudokite savo pačių rizika! Naudokite savo pačių rizika - version 2.12.11 (beta only): + version 2.12.12: +- Hopefully fix rare case when sync would get stuck indefinitely +- Fix ValueError: invalid literal for int() for invalid dates sent by Plex +- version 2.12.11 for everyone + +version 2.12.11 (beta only): - Fix PKC not auto-picking audio/subtitle stream when transcoding - Fix ValueError when deleting a music album - Fix OSError: Invalid argument when Plex returns an invalid timestamp diff --git a/changelog.txt b/changelog.txt index 29fccdd2..ebe395ef 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,8 @@ +version 2.12.12: +- Hopefully fix rare case when sync would get stuck indefinitely +- Fix ValueError: invalid literal for int() for invalid dates sent by Plex +- version 2.12.11 for everyone + version 2.12.11 (beta only): - Fix PKC not auto-picking audio/subtitle stream when transcoding - Fix ValueError when deleting a music album