trakt / Plex-Trakt-Scrobbler

Add what you are watching on Plex to trakt.tv
1.45k stars 166 forks source link

Trakt collection for TV shows got almost entirely cleared, not getting readded #622

Open OttoWerse opened 2 years ago

OttoWerse commented 2 years ago

Recently my library in Trakt got almost entirely cleared. I am using the clean collection setting, but nothing on my PMS was deleted so I have no idea why id did remove almost all my shows from Trakt now randomly. They are also not added back even after estarting everything, so now my Trakt library is just not syncing at all anymore. Movies seem unaffected.

STJBaxter commented 2 years ago

The same thing has happened to me. I've checked the plugin logs and it is full of the following message: "Invalid value provided for DateTimeField: 0123456789 (expected datetime instance)" - the number is a varaible, so it is different on each line.

I'm speculating, but maybe the new PMS version that I installed this week (1.26.0.5715 ) has changed the database slightly?

kbgvirus commented 2 years ago

The same thing has happened to me but for both movies and tv shows

alexperrault commented 2 years ago

Same issue here, just after upgrading to 1.26.0.5715.
Did some troubleshooting and came to the same conclusion.

Did anyone try to rollback to previous version (1.25.9.5721) ?

jahmad commented 2 years ago

Plex changed field type on metadata_items, from datetime to timestamp. the correct way to fix it would probably require update of pewee and some big changes. quick and dirty workaround, just convert it again..

on Trakttv.bundle/Contents/Libraries/Shared/plex_database/library.py (above the errored line).

--- library.py.orig     2022-04-23 15:14:49.784602915 +0700
+++ library.py  2022-04-23 15:10:09.340612008 +0700
@@ -183,6 +183,10 @@
             if not value:
                 return None

+            if isinstance(value, int):
+                value = datetime.fromtimestamp(value)
+
             if not isinstance(value, datetime):
                 log.debug('Invalid value provided for DateTimeField: %r (expected datetime instance)', value)
                 return None
StroescuTheo commented 2 years ago

Same issue here, just after upgrading to 1.26.0.5715. Did some troubleshooting and came to the same conclusion.

Did anyone try to rollback to previous version (1.25.9.5721) ?

Noticed the same issue. Both TvShows and Movies were missing from my trakt collection. Just tried to rollback to tag 1.25.9.5721-965587f64 and ran a full sync on the trakt plugin and it worked. All my collected items synced to trakt

jahmad's workaround did not work for me.

alexperrault commented 2 years ago

I also rolled back to 1.25.9.5721 and everything went back to normal after a full sync.
I'll try @jahmad's workaround next week 👍

the-jeffski commented 2 years ago

The patch worked for me - all synced again.

STJBaxter commented 2 years ago

Patch worked for me too - thank you

MarioMan632 commented 2 years ago

I think I did it the patch by @jahmad right but I'm still getting this error: 2022-04-25 19:29:08,980 - plex_database.library (14640be48b38) : DEBUG (plex_database.library:187) - Invalid value provided for DateTimeField: 1650456824 (expected datetime instance)

Here is the section of the library.py:

        if type(field) is DateTimeField:
            if not value:
                return None

            if isinstance(value, int):
                value = datetime.fromtimestamp(value)
                return value

            if not isinstance(value, datetime):
                log.debug('Invalid value provided for DateTimeField: %r (expected datetime instance)', value)
                return None
STJBaxter commented 2 years ago

Did you restart the plugin after you made the change?

On Mon, 25 Apr 2022 at 19:34, Jamie Bode @.***> wrote:

I think I did it the patch by @jahmad https://github.com/jahmad right but I'm still getting this error: 2022-04-25 19:29:08,980 - plex_database.library (14640be48b38) : DEBUG (plex_database.library:187) - Invalid value provided for DateTimeField: 1650456824 (expected datetime instance)

Here is the section of the library.py:

   if type(field) is DateTimeField:
       if not value:
           return None

       if isinstance(value, int):
           value = datetime.fromtimestamp(value)
           return value

       if not isinstance(value, datetime):
           log.debug('Invalid value provided for DateTimeField: %r (expected datetime instance)', value)
           return None

— Reply to this email directly, view it on GitHub https://github.com/trakt/Plex-Trakt-Scrobbler/issues/622#issuecomment-1108906995, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADKV55ZCECATDAKANFQGORTVG3QSLANCNFSM5SQTKM7Q . You are receiving this because you commented.Message ID: @.***>

the-jeffski commented 2 years ago

Yes, just restarted the docker container so it all reloaded.

MarioMan632 commented 2 years ago

I rebooted and it seems to be working, is this error going to be normal now?

TypeError: can't compare offset-naive and offset-aware datetimes
2022-04-25 20:12:54,820 - plugin.sync.modes.core.base.mode (14fce77eeb38) :  WARNING (plugin.sync.modes.core.base.mode:190) - Exception raised in handlers[1].run(8, ...): can't compare offset-naive and offset-aware datetimes
Traceback (most recent call last):
  File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/modes/core/base/mode.py", line 188, in execute_handlers
    self.handlers[d].run(m, mode, *args, **kwargs)
  File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/handlers/core/base/mode.py", line 42, in run
    module.run(media, mode, *args, **kwargs)
  File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/handlers/core/base/data.py", line 45, in run
    module.run(mode, *args, **kwargs)
  File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/handlers/core/base/media.py", line 95, in run
    return self.push(*args, **kwargs)
  File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/handlers/core/base/push.py", line 37, in push
    action = self.get_action(p_value, t_value)
  File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/handlers/core/base/push.py", line 23, in get_action
    if p_value != t_value:
STJBaxter commented 2 years ago

I get that error too, but I haven’t seen any negative impact yet.

On Mon, 25 Apr 2022 at 20:19, Jamie Bode @.***> wrote:

I rebooted and it seems to be working, is this error going to be normal now?

TypeError: can't compare offset-naive and offset-aware datetimes 2022-04-25 20:12:54,820 - plugin.sync.modes.core.base.mode (14fce77eeb38) : WARNING (plugin.sync.modes.core.base.mode:190) - Exception raised in handlers[1].run(8, ...): can't compare offset-naive and offset-aware datetimes Traceback (most recent call last): File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/modes/core/base/mode.py", line 188, in execute_handlers self.handlers[d].run(m, mode, *args, kwargs) File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/handlers/core/base/mode.py", line 42, in run module.run(media, mode, *args, *kwargs) File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/handlers/core/base/data.py", line 45, in run module.run(mode, args, kwargs) File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/handlers/core/base/media.py", line 95, in run return self.push(*args, **kwargs) File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/handlers/core/base/push.py", line 37, in push action = self.get_action(p_value, t_value) File "/config/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/sync/handlers/core/base/push.py", line 23, in get_action if p_value != t_value:

— Reply to this email directly, view it on GitHub https://github.com/trakt/Plex-Trakt-Scrobbler/issues/622#issuecomment-1108946724, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADKV554HWT6ATZVNZTLF4Y3VG3V4PANCNFSM5SQTKM7Q . You are receiving this because you commented.Message ID: @.***>

jahmad commented 2 years ago

@MarioMan632 @STJBaxter an unfortunate useless line got pasted, sorry.. remove the "return value" line, so it could keep processed by the tz lines below.

MarioMan632 commented 2 years ago

@jahmad I'll try it later to see if that helps but at the moment it works just with the errors stated before.

Conundrum1911 commented 2 years ago

Plex changed field type on metadata_items, from datetime to timestamp. the correct way to fix it would probably require update of pewee and some big changes. quick and dirty workaround, just convert it again..

on Trakttv.bundle/Contents/Libraries/Shared/plex_database/library.py (above the errored line).

--- library.py.orig     2022-04-23 15:14:49.784602915 +0700
+++ library.py  2022-04-23 15:10:09.340612008 +0700
@@ -183,6 +183,10 @@
             if not value:
                 return None

+            if isinstance(value, int):
+                value = datetime.fromtimestamp(value)
+
             if not isinstance(value, datetime):
                 log.debug('Invalid value provided for DateTimeField: %r (expected datetime instance)', value)
                 return None

Forgive me, but where exactly do I put this in library.py? I just looked through that file and couldn't find any references.

Also in my case I don't see any errors jumping out at me, but it seems for the last month or so Plex has been syncing plays to Trakt, but not collections/items collected.

StroescuTheo commented 2 years ago

Plex changed field type on metadata_items, from datetime to timestamp. the correct way to fix it would probably require update of pewee and some big changes. quick and dirty workaround, just convert it again.. on Trakttv.bundle/Contents/Libraries/Shared/plex_database/library.py (above the errored line).

--- library.py.orig     2022-04-23 15:14:49.784602915 +0700
+++ library.py  2022-04-23 15:10:09.340612008 +0700
@@ -183,6 +183,10 @@
             if not value:
                 return None

+            if isinstance(value, int):
+                value = datetime.fromtimestamp(value)
+
             if not isinstance(value, datetime):
                 log.debug('Invalid value provided for DateTimeField: %r (expected datetime instance)', value)
                 return None

Forgive me, but where exactly do I put this in library.py? I just looked through that file and couldn't find any references.

Also in my case I don't see any errors jumping out at me, but it seems for the last month or so Plex has been syncing plays to Trakt, but not collections/items collected.

Hey! You can open a text editor and go at line 183. Around there you can identify the 2 "if" statements "if not value" and "if not isinstance" and add the extra if statement between them. Don't forget to restart the service/container for the change to take effect.

Conundrum1911 commented 2 years ago

StroescuTheo -- Thanks, that was the bit I was missing in what to do. Lines added, and it appears to be syncing collections again. Strange though when I used Kitana to restart the plugin I got a bunch of errors/figured I had a syntax error but couldn't see anything. Restarted the entire plex process, used Kitana to do a full sync, and now all appears to be working.

TobiasRuano commented 2 years ago

I had the same issue and @jahmad solution worked!

rg9400 commented 2 years ago

the patch by jahmad should be modified as below to allow timestamps to be compared. This is important for the differential push/pull (quick sync rather than scrobble) tasks, namely to pull stuff you watch on Trakt into Plex.

            if isinstance(value, int):
               value = datetime.fromtimestamp(value)
               return TZ_LOCAL.localize(value).astimezone(pytz.utc)

I am thinking to maybe figure out a way to host these patches in a separate fork so people can easily pull the latest code. But I haven't done some patches mentioned in various issues here because my current build works fine. I am worried those patches might break other things that are currently functional, so never added them.

EDIT: patched version here: https://github.com/rg9400/Plex-Trakt-Scrobbler should have the patches to auto-grab Plex account from settings (since token is deprecated), as well as handle the new timestamp objects Plex is using (from this issue). Nothing else was included, but seems to be fully functional at my end

Mushin commented 2 years ago

Thanks for that. It would be really helpful to have an up to date and 100% working fork.

On 18 August 2022 04:22:53 rg9400 @.***> wrote:

the patch by jahmad should be modified as below to allow timestamps to be compared. This is important for the differential push/pull (quick sync rather than scrobble) tasks, namely to pull stuff you watch on Trakt into Plex.

       if isinstance(value, int):
          value = datetime.fromtimestamp(value)
          return TZ_LOCAL.localize(value).astimezone(pytz.utc)

I am thinking to maybe figure out a way to host these patches in a separate fork so people can easily pull the latest code. But I haven't done some patches mentioned in various issues here because my current build works fine. I am worried those patches might break other things that are currently functional, so never added them.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.

carlosmg2 commented 2 years ago

the patch by jahmad should be modified as below to allow timestamps to be compared. This is important for the differential push/pull (quick sync rather than scrobble) tasks, namely to pull stuff you watch on Trakt into Plex.

            if isinstance(value, int):
               value = datetime.fromtimestamp(value)
               return TZ_LOCAL.localize(value).astimezone(pytz.utc)

I am thinking to maybe figure out a way to host these patches in a separate fork so people can easily pull the latest code. But I haven't done some patches mentioned in various issues here because my current build works fine. I am worried those patches might break other things that are currently functional, so never added them.

EDIT: patched version here: https://github.com/rg9400/Plex-Trakt-Scrobbler should have the patches to auto-grab Plex account from settings (since token is deprecated), as well as handle the new timestamp objects Plex is using (from this issue). Nothing else was included, but seems to be fully functional at my end

Thank you! Confirm this 3 edited files fix the Collection issue.

karadoulis commented 2 years ago

Hello, i have the same problem since the plex server update it doesn't sync anymore with trakt.tv at all. Tried the updated version but without success. Any help would be really appreciated it.