vosmiic / jellyfin-ani-sync

Synchronize anime watch status between Jellyfin and anime tracking sites.
GNU General Public License v3.0
243 stars 17 forks source link

2-way sync maybe possible now? #20

Closed Andy2244 closed 2 years ago

Andy2244 commented 2 years ago

With the higher accuracy, maybe a 2-way sync like the trakt plugin is now possible?

Maybe there is a somewhat reasonable way to-do this now, its just super convienent to have all your watched status in trakt and simply do a sync on a fresh install, so everything is back where you left.

So for normal shows/movies using the trakt plugin i dont have to care about any backup or library state, i can just reinstall the server point it to my libs and via a trakt resync all watched states are set to where i left off.

Would be super cool to have this also for Anime, but i understand that this can be more complex to get right.

vosmiic commented 2 years ago

So instead of doing an "outwards" sync (Jellyfin -> AniList/MAL/Kitsu), we sync the Jellyfin library to a provider (AniList/MAL/Kitsu -> Jellyfin)? This has been requested before here #12. While it wasn't exactly the original idea of the plugin, I still feel like it falls into the same realm. We could even make it an optional scheduled event, for those who update their AniList/MAL/Kitsu manually outside of Jellyfin. I can't see how it would be that difficult to achieve, simply retrieve the users complete/in progress list and update the Jellyfin library. I'll look into it and keep you updated.

Andy2244 commented 2 years ago

The main issue is you need to-be very carefully how/what you sync and also offer/study the settings options the trakt plugin has.

There can be catastrophic cases, where you wrongly sync the "unwatched" state from remote to local library or vice-versa and than quickly via a scheduled task, resync this new bad "unwatched" state back to the external list, basically wiping your watched states.

To prevent this case all trakt plugins by default disable remote->local "unwatched" sync via settings and also arrange the update jobs, so that the user has a chance to fix setting issues, before a full resync happens.

So by default you want the plugin to handle mainly "watched" states between local<->remote lists and via settings allow certain "unwatched" state combinations.

As example, the trakt plugin has specific settings to only set remote "watched/unwatched" if the user manually set the state. This is safer, since we detect a specific user toggled state change instead of doing some general assumptions on the whole library.

So if you don't use the trakt plugin already, i strongly recommend to check it out and check what settings combinations it offers, so you can avoid running into those catastrophic cases. We want safe defaults and carefully worded settings, similar to trakt so users quickly understand whats happening.

Andy2244 commented 2 years ago

@vosmiic btw i took the liberty to add the plugin to the official documentation: https://github.com/jellyfin/jellyfin-docs/pull/675

vosmiic commented 2 years ago

btw i took the liberty to add the plugin to the official documentation

Ah great, thanks. I think we are now in a comfortable enough position to have it there.

Nocifer commented 2 years ago

Just as a FYI, #12 isn't really about what @Andy2244 is asking for here, which is importing watch status from a remote Trakt-like third-party provider (i.e. AniList/MAL/Kitsu -> Jellyfin) but rather an extended functionality of what Ani-Sync already does, which is exporting watch status to a third-party provider (i.e. Jellyfin -> AniList/MAL/Kitsu) but without the hard requirement that I must first initiate playback of an anime for AniSync to scan it and update its remote status.

My issue (and I'm pretty certain I'm far from the only one affected) is that many of my anime were already watched or in various states of in medias res before I ever installed AniSync, but I'd just never bothered to manually update my MAL profile. So what I'd love for AniSync to be able to do, and what I asked for in #12, would be that it be able to scan my local Jellyfin library, find which anime I have already watched and which shows I'm currently watching, and then update my MAL profile accordingly. And if it could also add my completely untouched anime to the "plan to watch" category, that would be even more awesome.

After this has been done, then adding what @Andy2244 is actually asking for, i.e. the ability to also import watch state from MAL et al to Jellyfin, would be the cherry on top.

Andy2244 commented 2 years ago

I kinda included your scenario, its just a subpart of what a full 2-way sync does.

Nocifer commented 2 years ago

I know, I was replying to @vosmiic here:

So instead of doing an "outwards" sync (Jellyfin -> AniList/MAL/Kitsu), we sync the Jellyfin library to a provider (AniList/MAL/Kitsu -> Jellyfin)? This has been requested before here https://github.com/vosmiic/jellyfin-ani-sync/issues/12.

"This" isn't what has been requested in #12 :)

vosmiic commented 2 years ago

"This" isn't what has been requested in #12 :)

Yeah sorry I got a bit confused. I think I understand what would like to be achieved here, as it has been said before we would like both way sync between Jellyfin and the providers. I also understand what @Andy2244 said with being careful how we handle it. Need to make sure it doesn't turn into a nasty loop of updating each others lists and end up with broken watch statuses on both sides. I can see that you explained how the trakt plugin handles it, and it seems to be the best method. I'll take all of this into account when implementing these changes.

vosmiic commented 2 years ago

Hitting into some trouble syncing Jellyfin from the providers (AniList/MAL/Kitsu -> Jellyfin). As most of the APIs don't contain the season number, we can't actually tell what season the user is on. Luckily each item in the providers database is a separate season. The obvious way to accomplish this is to get the users watch list from the appropriate provider, get the IDs of the anime in said list and then run them through the anime offline database to get the AniDB ID and AniList ID of each season (if we are not using it as the selected provider to sync from) and then cross reference that to Jellyfin's database to see which seasons we have locally that match the IDs (we cannot use the local anime list XML file as that would only give us a TVDB ID which is bound to the series, not the season). Only problem being is that Jellyfin does not seem to store season provider IDs, at least not for me. It stores the series provider IDs, but not separate seasons. The only time that we will get a match with a provider ID from the Jellyfin database is if we are working with the first season of a show from the users watch list. Could someone please confirm that it isn't only me not having any provider IDs (labelled "external IDs" in the Jellyfin interface) for seasons? I have tried running the metadata fetcher multiple times and I don't get any extra provider IDs for seasons. I get a TVDB ID, but when I cross reference it with the XML file I get no results. I'm not entirely sure what the ID represents as I even tried looking it up on TVDB but got no results.

Andy2244 commented 2 years ago

As most of the APIs don't contain the season number

Thats tobe expected as most Anime has no "official" seasons, so have no season numbers. Those are just made up by TVDB/TMDB based on air dates.

Only problem being is that Jellyfin does not seem to store season provider IDs, at least not for me. It stores the series provider IDs, but not separate seasons.

Same for me, i think tvdb does not have separate season id's for a series?

So here is how this can work, lets use "Megalo Box 2nd" aka Second seasons as example:

we may need to also filter by ova/movies/special stuff. The full Anime offline db file has those infos:

      "title": "Nomad: Megalo Box 2",
      "type": "TV",
      "episodes": 13,
      "status": "FINISHED",
      "animeSeason": {
        "season": "SPRING",
        "year": 2021 }

So i think the type, animeSeason can be used to ensure we actually match a series or movie, just check for examples.

vosmiic commented 2 years ago

find the AniDB entry in the anime-list.xml

Good idea, yeah this should work. Feels like its really inefficient but we have to work with what we have.

we may need to also filter by ova/movies/special stuff

Luckily AniList uses GraphQL so we can filter our results on the API side. Much more efficient. But we will have to manually filter by checking the anime offline db with MAL.

vosmiic commented 2 years ago

I have now got it updating shows from a users AniList watched list. Just need to clean it up and get it working with other providers.

vosmiic commented 2 years ago

Forgot to update here recently but I believe I have got updating the Jellyfin library from providers anime list fully working. I have added a warning to let users know that the feature is in "alpha" and that it may disrupt their Jellyfin libraries. Next to do is to get the other direction working (Jellyfin to provider anime list).

vosmiic commented 2 years ago

This feature is now fully implemented on master. Just doing some testing and then I should be able to release a new version with this functionality included.

vosmiic commented 2 years ago

Okay, the update with this has been released. Currently testing it locally and I am not hitting into any trouble. That being said, I would be very careful using this - it could quite easily mess up your Jellyfin library or provider watch lists.