ghomasHudson / Jellyfin-Auto-Collections

Automatically make jellyfin collections from IMDB, Letterboxd lists and more.
MIT License
60 stars 9 forks source link

I seem to be having issues with wrong movie being picked up by imdb_chart #47

Open vortex91 opened 2 weeks ago

vortex91 commented 2 weeks ago

I added

imdb_id_filter:  true
year_filter:  true

but I keep getting wrong movie added to collection for box office for "IF" movie 2024 instead I keep getting "IF ONLY" 2004 picked up.

It also has same issue wityh mdblist plugin

ghomasHudson commented 2 weeks ago

Hmmm if you're comfortable with python, try printing item at line 111 of utils/jellyfin.py. Hopefully imdb_id should be there

vortex91 commented 2 weeks ago

Nevermind it seems like its adding correct one now. WHen I was having issues it was 10.9.6 now im on 10.9.7 and its adding correct movie even though its giving the error below.,

Checking for exact IMDb ID match... Result IMDb ID: tt0332136, Item IMDb ID: tt11152168 Result IMDb ID: tt11152168, Item IMDb ID: tt11152168 Exact IMDb ID match found. Item ID to add to collection: 74b10010ea45ed62ce9b5d48d45fbbe7 2024-06-25 12:36:49.822 | ERROR | utils.jellyfin:add_item_to_collection:149 - Error adding IF to collection - Status Code: 204 Error adding IF to collection - Status Code: 204 Final match: {'Name': 'IF', 'ServerId': '95e70d793a464bb6addaf24ff336e99c', 'Id': '74b10010ea45ed62ce9b5d48d45fbbe7', 'HasSubtitles': True, 'Container': 'mkv', 'PremiereDate': '2024-05-08T00:00:00.0000000Z', 'CriticRating': 49, 'OfficialRating': 'PG', 'ChannelId': None, 'CommunityRating': 7.06, 'RunTimeTicks': 64454510000, 'ProductionYear': 2024, 'ProviderIds': {'Tmdb': '639720', 'Imdb': 'tt11152168'}, 'IsFolder': False, 'Type': 'Movie', 'UserData': {'PlaybackPositionTicks': 0, 'PlayCount': 1, 'IsFavorite': False, 'LastPlayedDate': '2024-06-21T20:27:50.5315968Z', 'Played': False, 'Key': '639720'}, 'VideoType': 'VideoFile', 'ImageBlurHashes': {}, 'LocationType': 'FileSystem', 'MediaType': 'Video'}

vortex91 commented 2 weeks ago

I have no idea what i did. But using original codd on 10.9.7 the movie IF now does not get added but If only also does not get added. However editing the code to print debug info somehow makes it add the correct movies even though it prints the error in above comment. Here is my udpated code to print debug info which somehow fixed adding the correct movies.

    # Check if there's an exact imdb_id match first
    match = None
    if "imdb_id" in item:
        print("Checking for exact IMDb ID match...")
        for result in res.json()["Items"]:
            imdb_id = result["ProviderIds"].get("Imdb", None)
            print(f"Result IMDb ID: {imdb_id}, Item IMDb ID: {item['imdb_id']}")
            if imdb_id == item["imdb_id"]:
                match = result
                print("Exact IMDb ID match found.")
                break
    else:
        # Check if there's a year match
        if match is None and year_filter:
            print("Checking for production year match...")
            for result in res.json()["Items"]:
                production_year = result.get("ProductionYear", None)
                print(f"Result Production Year: {production_year}, Item Release Year: {item['release_year']}")
                if production_year == item["release_year"]:
                    match = result
                    print("Production year match found.")
                    break

        # Otherwise, just take the first result
        if match is None and len(res.json()["Items"]) == 1:
            print("No exact IMDb ID or production year match found. Taking the first result.")
            match = res.json()["Items"][0]

    if match is None:
        logger.warning(f"Item {item['title']} not found in jellyfin")
        print(f"Item {item['title']} not found in jellyfin")
    else:
        try:
            item_id = match["Id"]
            print(f"Item ID to add to collection: {item_id}")
            response = requests.post(f'{self.server_url}/Collections/{collection_id}/Items?ids={item_id}', headers={"X-Emby-Token": self.api_key})
            if response.status_code == 200:
                logger.info(f"Added {item['title']} to collection")
                print(f"Added {item['title']} to collection")
            else:
                logger.error(f"Error adding {item['title']} to collection - Status Code: {response.status_code}")
                print(f"Error adding {item['title']} to collection - Status Code: {response.status_code}")
        except json.decoder.JSONDecodeError:
            logger.error(f"Error adding {item['title']} to collection - JSONDecodeError")
            print(f"Error adding {item['title']} to collection - JSONDecodeError")
            return

    # Final match debugging
    print("Final match:", match)