Taxel / PlexTraktSync

A python script that syncs the movies, shows and ratings between trakt and Plex (without needing a PlexPass or Trakt VIP subscription)
MIT License
1.55k stars 101 forks source link

Feature request: Add AniDB as a provider, Hama.Bundle (anidb|tvdb guid) #1018

Open Amateur-God opened 2 years ago

Amateur-God commented 2 years ago

Feature description

add anidb along with tvdb and imdb for anime,

Use case

i use the hama plugin for plex to use anidb for metadata for my anime shows as tvdb isnt always correct and doesnt handle anime very well, however this results in a Unable to parse a valid provider from guid <PlexGuid:com.plexapp.agents.hama://anidb-4776?lang=en> error.

zeroquinc commented 1 year ago

Would like to see this added as I have the same problem.

Amateur-God commented 1 year ago

Would like to see this added as I have the same problem.

I've just ended up switching to emby and using the emby anidb and trakt plugins, works perfectly. I recommend it if your system can handle emby

simonc56 commented 1 year ago

Can you give examples of anime which are "not handled very well" by Plex agent and for which anidb is a best choice ?

zeroquinc commented 1 year ago

Can you give examples of anime which are "not handled very well" by Plex agent and for which anidb is a best choice ?

Dragon Ball Z Kai for example on Trakt: https://trakt.tv/shows/dragon-ball-z-kai

Shows 6 seasons because it follows tmdb. But with the hama plugin you get only 2 seasons because it follows tvdb and anidb I guess.

simonc56 commented 1 year ago

You don't answer the question. Using Plex agent for Dragon Ball Z Kai is working good. Matches and sync perfectly with trakt.

zeroquinc commented 1 year ago

You don't answer the question. Using Plex agent for Dragon Ball Z Kai is working good. Matches and sync perfectly with trakt.

Renamed my DBZ Kai pack back to tvdb numbering with FileBot (how it orginally downloaded my files, i renamed them to the Trakt order with 6 seasons to fix scrobbling)

Changed the agent back to Plex with as default tmdb ordering. It changed my 6 seasons back to 2 seasons. Everything up to a certain episode in season 1 won't scrobble anymore because Trakt only knows DBZ Kai as 6 seasons.

image

Metadata dissapeared and scrobbling doesn't work.

         <PlexGuid:local://4158> because provider local has no external Id      
WARNING  <Episode:4159:Dragon-Ball-Z-Kai-s01e158>: Skipping                     
         <PlexGuid:local://4159> because provider local has no external Id      
WARNING  <Episode:4160:Dragon-Ball-Z-Kai-s01e159>: Skipping                     
         <PlexGuid:local://4160> because provider local has no external Id

So not sure what you mean with it matches and syncs perfectly tbh. It only scrobbles fine if I rename my DBZ Kai to the TMDB episode ordering in FileBot. Then it makes it 6 seasons instead of 2 and everything works fine.

If i change the episode ordering back to TVDB in Plex the metadata looks fine for the 2 seasons for all episodes. But still scrobbling wont work, sync gives this error:

         <PlexGuid:imdb://tt1528230> not found on Trakt                         
WARNING  <Episode:4356:Dragon-Ball-Z-Kai-s01e29>: Skipping guid                 
         <PlexGuid:tvdb://1233481> not found on Trakt                           
WARNING  <Episode:4356:Dragon-Ball-Z-Kai-s01e29>: Skipping guid                 
         <PlexGuid:imdb://tt1531707> not found on Trakt        
simonc56 commented 1 year ago
  1. Keep your DBZ Kai pack files to tvdb numbering (how it orginally downloaded)
  2. Use Plex TV Series agent
  3. Check the show settings ordering to be TheTVDB (Aired)
  4. Temporary rename your plextraktsync cache trakt_cache.sqlite to trakt_cache.sqlite.backup
  5. Make sure you have latest plextraktsync version 0.25.3
  6. Sync with command plextraktsync sync --sync=shows

You will only have mismatch with season 1 episode 98 because it is a special (s00e01) and shouldn't be in season 1.

AniDB is not needed here. Any other example where AniDB is supposed to be better than Plex TV Series agent ?

BitterSweetcandyshop commented 1 year ago

@twolaw I bring back this, not only due to the fact of Hama being far feature rich beyond the Plex TV options, it's not only series being handled wrong (very rare cases), but also some of these reasons:

I will say plex tv scanner does a great job with anime, but not the best and these additonal features and settings is why I use hama

BitterSweetcandyshop commented 1 year ago

Hama also works with the vip trakt scrobbling, which I presume works with a lucky search of sorts.

Amateur-God commented 10 months ago

you could write a script to get the metadata provider of the library and then use the metadata provider of the library to sync with trakt, something like to get the libraries metadata provider

import requests

PLEX_SERVER_IP = "YOUR_PLEX_SERVER_IP"
PLEX_API_KEY = "YOUR_PLEX_API_KEY"

def get_all_plex_metadata_providers():
    url = f"http://{PLEX_SERVER_IP}:32400/library/sections"
    params = {
        "X-Plex-Token": PLEX_API_KEY
    }
    response = requests.get(url, params=params)
    if response.status_code == 200:
        libraries = response.json()["MediaContainer"]["Directory"]
        metadata_providers = {}
        for library in libraries:
            library_id = library["key"]
            metadata_provider = library.get("agent")
            metadata_providers[library_id] = metadata_provider
        return metadata_providers
    else:
        print(f"Error retrieving metadata providers. Status code: {response.status_code}")
        return None

# Example usage
metadata_providers = get_all_plex_metadata_providers()

if metadata_providers:
    for library_id, metadata_provider in metadata_providers.items():
        print(f"Library ID {library_id} uses metadata provider: {metadata_provider}")

then something like to set the prefered provider based on the libraries metadata provider

def choose_correct_show_info(anidb_info, tvdb_info, tmdb_info, imdb_info, plex_metadata_provider):
    # Define the preferred metadata providers for each Plex metadata provider
    provider_preferences = {
        "anidb": [anidb_info, tvdb_info, tmdb_info, imdb_info],
        "tvdb": [tvdb_info, anidb_info, tmdb_info, imdb_info],
        "tmdb": [tmdb_info, tvdb_info, anidb_info, imdb_info],
        "imdb": [imdb_info, tmdb_info, tvdb_info, anidb_info]
    }

    # Use the Plex metadata provider to get the preferred order
    preferred_providers = provider_preferences.get(plex_metadata_provider, [])

    for provider_info in preferred_providers:
        if provider_info and "id" in provider_info:
            return provider_info

    # If none of the preferred providers have valid information, you might want to handle this case
    return None

and then something like to get show information from each of the providers

# Function to get show information from AniDB
def get_anidb_info(title):
    url = f"http://api.anidb.net:9001/httpapi?request=anime&client=plex-sync&clientver=1&protover=1&aid=0&title={title}"
    response = requests.get(url)
    return response.json()

# Function to get show information from TVdb
def get_tvdb_info(title):
    url = f"https://api.thetvdb.com/search/series?name={title}"
    headers = {
        "Authorization": f"Bearer {TVDB_API_KEY}"
    }
    response = requests.get(url, headers=headers)
    return response.json()

# Function to get show information from TMdb
def get_tmdb_info(title):
    url = f"https://api.themoviedb.org/3/search/tv?api_key={TMDB_API_KEY}&query={title}"
    response = requests.get(url)
    return response.json()

# Function to get show information from IMDb
def get_imdb_info(title):
    url = f"https://v2.sg.media-imdb.com/suggests/{title[0]}/{title}.json"
    response = requests.get(url)
    return response.json()

however my python isnt great so ive probably made lots of mistakes in this but its just to give an idea of how i would personally implement it