Jump to content

"Allow media playback” behavior via API


Go to solution Solved by Luke,

Recommended Posts

Posted

Hello,

For context, I'm developing a Telegram bot to manage my users and I've created a button that allows you to authorize or not media playback for a specific user.

Except that I have a problem when I disable or re-enable access with my button it also checks “Enable access to all libraries” when I only want to work with the “Allow media playback” function on Emby.

image.png.8c6e8f17189273886e1a32869ee607d4.png

Here's an extract of my 2 functions 

def disable_user_access(emby_user_id: str) -> bool:
    """
    Fonction qui désactive l'accès aux bibliotèque Emby et TV 

    Args:
        emby_user_id (str): L'ID user à configurer

    Returns:
        int: 0 = OK , 1 = Erreur
    """
    headers = {'X-Emby-Token': EMBY_API_KEY, 'Content-Type': 'application/json'}
    url_policy_user = f'{EMBY_URL}/Users/{emby_user_id}/Policy'
    user_policy = {
        'EnableLiveTvAccess': False,
        'EnableMediaPlayback': False
    }

    try:
        response = requests.post(url_policy_user, headers=headers, json=user_policy)
        response.raise_for_status()  # Gère les erreurs HTTP
        logger.info(f"L'accès aux médias du compte {emby_user_id} a bien été désactivé.")
        return 0
    except requests.exceptions.HTTPError as e:
      
...

def enable_emby_access(emby_user_id: str) -> bool:
    """
    Fonction qui donne accès à un utilisateur membre aux médias Emby

    Args:
        emby_user_id (str): L'ID de l'utilisateur

    Returns:
        int: 0 = OK, 1 = Erreur
    """
    headers = {'X-Emby-Token': EMBY_API_KEY, 'Content-Type': 'application/json'}
    url_policy_user = f'{EMBY_URL}/Users/{emby_user_id}/Policy'
    user_policy = {
        'EnableLiveTvAccess': True,
        'EnableMediaPlayback': True
    }

    try:
        response = requests.post(url_policy_user, headers=headers, json=user_policy)
        response.raise_for_status()  # Gère les erreurs HTTP
        logger.info(f"The member plan activated for the ID : {emby_user_id}")
        return 0
    except requests.exceptions.HTTPError as e:
      
      ...

 

Is this normal behavior? 

Thank you for your answers 

Posted

Hi, are you pulling down the user policy, making your changes, and then sending the updated version back?

Posted

Hi, 

No, I just want to push with only this change.

  • Solution
Posted

OK that's how the api currently works though. It does not accept partial changes like that, so you have to pull down the original object first.

The good news though is that some api's in the server are now being updated to accept partial changes like that, but user policy hasn't gotten that yet.

Posted

Okay, now I understand.
I will modify my code to get the current user policy before then make changes and resend.

Thanks for your answer

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...