Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Add option to mark rated titles as watched in trakt #103

Closed
1 task done
iPaulis opened this issue Aug 7, 2024 · 1 comment · Fixed by #140
Closed
1 task done

[Feature Request]: Add option to mark rated titles as watched in trakt #103

iPaulis opened this issue Aug 7, 2024 · 1 comment · Fixed by #140
Labels
enhancement New feature or request

Comments

@iPaulis
Copy link

iPaulis commented Aug 7, 2024

Is there already a request for your feature?

  • I have checked older issues, open and closed

Feature Request

Right now, the script syncs ratings into trakt, but does not mark them as watched. It would be nice to have that option.

If a rating is synced into trakt and there is no play count, it should be quite safe to assume the show should have been watched at least once to rate it, and it makes sense that the date when it was rated should not be too far apart from the real watching date most of the times.
However, as trakt allows for multiple play counts, and it behaves differently for movies or tv shows, the best idea might be to give those options to the user and save them in the settings. Some users may be interested in adding a play count to a movie, even also to individual episodes, but not to a whole tv show, which could mess with their progress in trakt.

Alternatives you've considered

I adapted part of the code in "IMDBTraktSyncer.py" to add the functionality by default when syncing ratings, because that is what I needed for my use case, and it works. It tries to add the date when it was rated as the watch date, and if there is none is found, it adds today's date.
You may use it if it helps:

# Set Trakt Ratings
           if trakt_ratings_to_set:
               print('Setting Trakt Ratings')

               # Set the API endpoints
               rate_url = "https://api.trakt.tv/sync/ratings"
               watched_url = "https://api.trakt.tv/sync/history"
               
               # Count the total number of items
               num_items = len(trakt_ratings_to_set)
               item_count = 0
                       
               # Loop through your data table and rate each item on Trakt
               for item in trakt_ratings_to_set:
                   item_count += 1
                   data = None
                   watched_data = None
                   
                   if item["Type"] == "show":
                       # This is a TV show
                       data = {
                           "shows": [{
                               "ids": {
                                   "imdb": item["IMDB_ID"]
                               },
                               "rating": item["Rating"]
                           }]
                       }
                       watched_data = {
                           "shows": [{
                               "ids": {
                                   "imdb": item["IMDB_ID"]
                               },
                               "watched_at": item.get("Date_Added", datetime.now().isoformat() + "Z")
                           }]
                       }
                       print(f" - Rating TV show ({item_count} of {num_items}): {item['Title']} ({item['Year']}): {item['Rating']}/10 on Trakt")
                   elif item["Type"] == "movie":
                       # This is a movie
                       data = {
                           "movies": [{
                               "ids": {
                                   "imdb": item["IMDB_ID"]
                               },
                               "rating": item["Rating"]
                           }]
                       }
                       watched_data = {
                           "movies": [{
                               "ids": {
                                   "imdb": item["IMDB_ID"]
                               },
                               "watched_at": item.get("Date_Added", datetime.now().isoformat() + "Z")
                           }]
                       }
                       print(f" - Rating movie ({item_count} of {num_items}): {item['Title']} ({item['Year']}): {item['Rating']}/10 on Trakt")
                   elif item["Type"] == "episode":
                       # This is an episode
                       data = {
                           "episodes": [{
                               "ids": {
                                   "imdb": item["IMDB_ID"]
                               },
                               "rating": item["Rating"]
                           }]
                       }
                       watched_data = {
                           "episodes": [{
                               "ids": {
                                   "imdb": item["IMDB_ID"]
                               },
                               "watched_at": item.get("Date_Added", datetime.now().isoformat() + "Z")
                           }]
                       }
                       print(f" - Rating episode ({item_count} of {num_items}): {item['Title']} ({item['Year']}): {item['Rating']}/10 on Trakt")
                   else:
                       print(f" - Skipping unknown type ({item_count} of {num_items}): {item['Title']} ({item['Year']})")
                       continue
                   
                   if data:
                       # Make the API call to rate the item
                       response = EH.make_trakt_request(rate_url, payload=data)

                       if response is None:
                           error_message = f"Failed rating {item['Type']} ({item_count} of {num_items}): {item['Title']} ({item['Year']}): {item['Rating']}/10 on Trakt. IMDB ID not found: {item['IMDB_ID']}"
                           print(f"   - {error_message}")
                           EL.logger.error(error_message)

                   if watched_data:
                       # Make the API call to mark item as watched
                       response = EH.make_trakt_request(watched_url, payload=watched_data)

                       if response is None:
                           error_message = f"Failed marking {item['Type']} as watched ({item_count} of {num_items}): {item['Title']} ({item['Year']}) on Trakt. IMDB ID not found: {item['IMDB_ID']}"
                           print(f"   - {error_message}")
                           EL.logger.error(error_message)

               print('Setting Trakt Ratings Complete')
           else:
               print('No Trakt Ratings To Set')
@RileyXX
Copy link
Owner

RileyXX commented Jan 21, 2025

This feature is added now in v3.4.0.

python -m pip install IMDBTraktSyncer --upgrade

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants