rocstack / plex-recommendations-ai

Creates a recommended collection on you Plex server using OpenAI
28 stars 6 forks source link

Feature: Single User Recommendations #4

Open hevalito opened 10 months ago

hevalito commented 10 months ago

I think this is super important: As more than one users are watching movies on my plex, the recommendations are not helpful. If the utility generated one collection per user and also shared the users recommendation only to them, it would be fantastic.

rocstack commented 9 months ago

I agree this would be a great feature, although I don't think it's possible yet because collections are sort of "global" in Plex and not user specific.

hevalito commented 9 months ago

It should be possible to share it to a single user. the run function could be modified to be ran for each user as follows: `def run():

Connect

while True:
    logger.info("Starting collection run")
    try:
        plex = PlexServer(userInputs.plex_url, userInputs.plex_token)
        logging.info("Connected to Plex server")
    except Exception as e:
        logging.error("Plex Authorization error")
        return

    try:
        # Fetch all users
        users = plex.myPlexAccount().users()
        for user in users:
            account_id = user.id
            generate_recommendations_for_user(plex, account_id)
    except Exception as e:
        logging.error("Failed to fetch users: " + str(e))
        return

    logging.info("Waiting on next call...")
    time.sleep(userInputs.wait_seconds) `

and then generate the recommendation for a single user

`def generate_recommendations_for_user(plex, account_id): try: library = plex.library.section(userInputs.library_name) history_items_titles = get_user_watch_history(plex, library.key, account_id) if history_items_titles: movie_recommendations = get_movie_recommendations(history_items_titles) if movie_recommendations: create_collection(plex, movie_recommendations, library, account_id)

Optionally, handle wishlist here (see issue I wrote about in github)

except Exception as e:
    logging.error("Error processing recommendations for user ID " + str(account_id) + ": " + str(e)) `

eventually the collection can be created with the user name in the title:

`def create_collection(plex, movie_items, description, library, user_name): logging.info(f"Finding matching movies in {user_name}'s library...") movie_list = [] wishlist = []

for item in movie_items:
    movie_search = plex.search(item, mediatype="movie", limit=3)
    if len(movie_search) > 0:
        movie_list.append(movie_search[0])
        logging.info(item + " - found")
    else:
        wishlist.append(item)
        logging.info(item + " - not found")

# Naming the collection with user's name for identification
user_collection_title = f"{userInputs.collection_title} - {user_name}"

if len(movie_list) > userInputs.minimum_amount:
    try:
        collection = library.collection(user_collection_title)
        collection.removeItems(collection.items())
        collection.addItems(movie_list)
        collection.editSummary(description)
        logging.info(f"Updated pre-existing collection for {user_name}")
    except:
        collection = plex.createCollection(
            title=user_collection_title,
            section=userInputs.library_name,
            items=movie_list
        )
        collection.editSummary(description)
        logging.info(f"Added new collection for {user_name}")
else:
    logging.info(f"Not enough movies were found for {user_name}'s collection") `
rocstack commented 9 months ago

Awesome, thanks for sharing you're implementation - I understand what you mean now. So it will generate various collections based on each users watch history/wishlist and then create their personal collections with their username concatenated at the end.

That's a good solution although I was looking for a way to completely hide the collection based on the user. I have about 8 family member accounts on mine and it would look a bit cluttered with 8 recommended collections for everyone.

stevezau commented 2 months ago

damn, i'd also love to do this for my users.. I was thinking to use labels/tags.. But plex does not allow for a dynamic filter.. i.e show me all movies with tag :(

stevezau commented 2 months ago

maybe this could help https://github.com/lostb1t/replex/issues/132 ... 🤔

jl94x4 commented 2 months ago

Awesome, thanks for sharing you're implementation - I understand what you mean now. So it will generate various collections based on each users watch history/wishlist and then create their personal collections with their username concatenated at the end.

That's a good solution although I was looking for a way to completely hide the collection based on the user. I have about 8 family member accounts on mine and it would look a bit cluttered with 8 recommended collections for everyone.

You could use labels on each collection that would only display it for the users that you give the label access to. This gets rid of the clutter?

stevezau commented 2 months ago

@jl94x4 how would you do that ? I couldn't see how to manage permissions to collections based on labels?

jl94x4 commented 2 months ago

@jl94x4 how would you do that ? I couldn't see how to manage permissions to collections based on labels?

image

In here, you would set a label on a collection for example "User 123's Collection" and then just share that collection with only "User 123"

Set a dynamic "Collections" label on every other collection you have, share that + the custom "User 123" to mimmick the "share all labels"

lostb1t commented 2 months ago

Plex does not apply restrictions to hubs.

So i have added this feature to replex. You can follow @jl94x4 instructions to restrict collections to a specific user and have hub filtered on home and recommended with replex