PlexKodiConnect icon indicating copy to clipboard operation
PlexKodiConnect copied to clipboard

Renamed files not being synced to Kodi database

Open jaimbo opened this issue 2 years ago • 11 comments

Help yourself

  • I did try to restart Kodi :-)
  • I checked the PKC Frequently Asked Questions on the PKC wiki
  • I did try to reset the Kodi database by going to PKC Settings -> Advanced -> "Reset the database and optionally reset PlexKodiConnect" and then hitting YES, NO. This does fix the issue but needs to be done every time a file name is changed, which doesn't seem reasonable
  • I did check the existing issues on Github #1871 seems to be the same issue

Describe the bug

In my setup, when files are replaced with higher quality versions, the file name will likely change. This causes the version synced to the Kodi database to not be found and Kodi prompts to delete the file. If you delete the file, no matter how many times you restart Kodi or force a sync, the new file will not be added until you completely wipe the database from the PlexKodiConnect settings.

To Reproduce

Steps to reproduce the behavior:

  1. Add a file to your Plex library and sync to Kodi database via PKC
  2. Rename the file/replace it with a better version that has a different file name
  3. Sync PKC
  4. Try and play the file in Kodi and be told Kodi can't find the file, would you like to delete it.
  5. Delete the file and PKC will not sync the new file to t he library until you reset the database

Expected behavior

Ideally PKC would just update the path to the new file, given that it's mapped to the same episode/movie in Plex, just a new filename

log kodi.log

jaimbo avatar Dec 27 '22 21:12 jaimbo

I took a look in the MyVideos119.db and can see the episode is not present in the "episode" table, but I can see the file in the "files" table, with the correct file name etc. Does this help?

jaimbo avatar Dec 27 '22 22:12 jaimbo

Doing some more investigation, this seems to work as expected with media in my "Movies" and "TV" Plex Libraries, but doesn't work for my "Anime" library

jaimbo avatar Dec 27 '22 23:12 jaimbo

Here's your issue: sqlite3.DatabaseError: database disk image is malformed

This means that your database is screwed anyway, nothing PlexKodiConnect can do about it. This is probably due to a bad/very cheap SD card. You could try and start from scratch with Kodi, but I'd also suggest to get a new SD card.

More context:

T:29351   error <general>: PLEX.utils: _____________________________________________________________
T:29351   error <general>: PLEX.utils:     Traceback (most recent call last):
T:29351   error <general>: PLEX.utils:       File "/storage/emulated/0/Android/data/net.kodinerds.maven.kodi20/files/.kodi/addons/plugin.video.plexkodiconnect/resources/lib/artwork.py", line 68, in run
T:29351   error <general>: PLEX.utils:         self._run()
T:29351   error <general>: PLEX.utils:       File "/storage/emulated/0/Android/data/net.kodinerds.maven.kodi20/files/.kodi/addons/plugin.video.plexkodiconnect/resources/lib/artwork.py", line 91, in _run
T:29351   error <general>: PLEX.utils:         if self._loop():
T:29351   error <general>: PLEX.utils:            ^^^^^^^^^^^^
T:29351   error <general>: PLEX.utils:       File "/storage/emulated/0/Android/data/net.kodinerds.maven.kodi20/files/.kodi/addons/plugin.video.plexkodiconnect/resources/lib/artwork.py", line 81, in _loop
T:29351   error <general>: PLEX.utils:         for url in self._url_generator(kind, kodi_type):
T:29351   error <general>: PLEX.utils:       File "/storage/emulated/0/Android/data/net.kodinerds.maven.kodi20/files/.kodi/addons/plugin.video.plexkodiconnect/resources/lib/artwork.py", line 54, in _url_generator
T:29351   error <general>: PLEX.utils:         if texture_db.url_not_yet_cached(url):
T:29351   error <general>: PLEX.utils:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
T:29351   error <general>: PLEX.utils:       File "/storage/emulated/0/Android/data/net.kodinerds.maven.kodi20/files/.kodi/addons/plugin.video.plexkodiconnect/resources/lib/kodi_db/texture.py", line 13, in url_not_yet_cached
T:29351   error <general>: PLEX.utils:         self.artcursor.execute('SELECT url FROM texture WHERE url = ? LIMIT 1',
T:29351   error <general>: PLEX.utils:     sqlite3.DatabaseError: database disk image is malformed
T:29351   error <general>: PLEX.utils: _____________________________________________________________

croneter avatar Dec 28 '22 06:12 croneter

Apologies, the database issues were a separate issue only recently caused by (I think) crashing of the Nexus build I'd recently upgraded to. I've since gone back to my Matrix build and no longer have the database errors but the original issue is still present.

Additionally I've had this issue for months and it's not related to the corrupt database in the original kodi.log. I can provide a new kodi.log later today from my current build (with a healthy database) but will need to wait for an episode or movie to be upgraded before I can pull the log file!

jaimbo avatar Dec 28 '22 10:12 jaimbo

Then please provide a new DEBUG log file where you replicate your issue

croneter avatar Dec 28 '22 12:12 croneter

Okay, here is the new kodi.log

  • I updated the file with a better quality and so the filename changed.
  • The file was available in the Plex app and Plex WebUI, ready to play etc.
  • Opened Kodi, gave it a few moments for PKC to sync automatically
  • Tried to play file, Kodi advised the file couldn't be found and asked if I wanted to remove the file (I didn't remove it)
  • Opened the PKC addon and chose "Perform Manual Library Sync" (side note, this seems to also have an issue where it will just say "Please Wait" after the sync has completed seemingly forever and I have to press back to cancel it/exit. This is worse on Nexus where the back button doesn't let you exit at all and I have to force close Kodi).
  • Went back to the episode and tried to play it again, same message about file being missing (Again, I chose not to remove it).

Some information about the file:

Library: Anime Old filename: Rascal Does Not Dream of Bunny Girl Senpai (2018) - S01E02 - 002 - On First Dates Trouble Is Essential [HDTV-1080p][8bit][HEVC][AAC 2.0][JA]-E.mkv New filename: Rascal Does Not Dream of Bunny Girl Senpai (2018) - S01E02 - 002 - On First Dates Trouble Is Essential [Bluray-1080p][10bit][x264][FLAC 2.0][JA]-Arid.mkv Plex Episode ID: 17980 Plex Season ID: 17977 Plex Show ID: 17976

Some information from the MyVideos119.db:

episode table: Filename: Rascal Does Not Dream of Bunny Girl Senpai (2018) - S01E02 - 002 - On First Dates Trouble Is Essential [HDTV-1080p][8bit][HEVC][AAC 2.0][JA]-E.mkv

files table: Filename: Rascal Does Not Dream of Bunny Girl Senpai (2018) - S01E02 - 002 - On First Dates Trouble Is Essential [HDTV-1080p][8bit][HEVC][AAC 2.0][JA]-E.mkv

Some information from the plex.db:

Plex Episode ID: 17980 is present in table episode, though I'm not sure there's any more useful information to take from this table!

I hope this helps and please let me know if I can get any other information for you :)

jaimbo avatar Dec 28 '22 17:12 jaimbo

Unfortunately, this is a bug/missing feature on the Plex Media Server side 😢. If you update the filename and the PMS detects this, the PMS will NOT update the timestamp flag updatedAt for the item's metadata. PKC relies on this updatedAt being updated as otherwise PKC would have to re-scan every single item all the time.

Kindly take this up with the Plex team. Should be a small bug fix on their side.

croneter avatar Jan 03 '23 15:01 croneter

Here's my bug report, kindly endorse it: https://forums.plex.tv/t/bug-changing-an-items-file-name-does-not-update-the-metadata-field-updatedat/825372

croneter avatar Jan 03 '23 15:01 croneter

Unfortunately, this is a bug/missing feature on the Plex Media Server side 😢. If you update the filename and the PMS detects this, the PMS will NOT update the timestamp flag updatedAt for the item's metadata. PKC relies on this updatedAt being updated as otherwise PKC would have to re-scan every single item all the time.

Kindly take this up with the Plex team. Should be a small bug fix on their side.

Interesting, thank you for looking into this. I've reviewed it on my side and it looks like due to the way sonarr upgrades items (deletes the old episode and then moves the new episode in), Plex treats this as a removal and new episode, so the XML doesn't have the "updatedAt" field. Whereas if I just change the filename of an existing file, the XML does have the "updatedAt"

jaimbo avatar Jan 03 '23 16:01 jaimbo

Looks like someone has replied saying that if a file is renamed but the data hasn't changed, then it is intended functionality for updatedAt to not be updated. I replied stating as above that the same occurs when a file is removed and replaced with a different file with different data and it still doesn't have the updatedAt field but I was (rather rudely) informed that was a different issue and so a different topic was needed.

I replied with a new topic and left a comment that but the comment and linked topic were both removed from your topic:

This is the new topic I created: https://forums.plex.tv/t/bug-replacing-a-media-file-with-a-new-file-and-filename-does-not-updated-meta-field-updatedat/826164

jaimbo avatar Jan 09 '23 15:01 jaimbo

Darn, not looking good if Plex argues that this is a "feature" 😢.

croneter avatar Jan 09 '23 18:01 croneter