• Login
  • Register
  • Login Register
    Login
    Username/Email:
    Password:
    Or login with a social network below
  • Forum
  • Website
  • GitHub
  • Status
  • Translation
  • Features
  • Team
  • Rules
  • Help
  • Feeds
User Links
  • Login
  • Register
  • Login Register
    Login
    Username/Email:
    Password:
    Or login with a social network below

    Useful Links Forum Website GitHub Status Translation Features Team Rules Help Feeds
    Jellyfin Forum Support Troubleshooting SOLVED: Issue: First two users created via the Jellyfin API inherit session data (e.g., “Cont

     
    • 0 Vote(s) - 0 Average

    SOLVED: Issue: First two users created via the Jellyfin API inherit session data (e.g., “Cont

    ca2ju
    Offline

    Junior Member

    Posts: 19
    Threads: 5
    Joined: 2024 May
    Reputation: 0
    Country:Canada
    #1
    2024-08-16, 06:57 PM (This post was last modified: 2024-08-21, 02:44 AM by ca2ju. Edited 1 time in total.)
    Jellyfin Version: 10.9.9

    Installation Method and Platform: Ubuntu Server

    Hello, I have a Python script that creates users through the Jellyfin API. However, the first two users it creates are inheriting session data such as “Continue Watching” and “Last Watched.” This shouldn’t happen because it’s a new user. However, this issue only occurs with the first two users; starting from the third user, everything is clean as it should be. Can someone help me with this?

    OBS:I’ve already checked the logs, and there’s nothing different, so I didn’t post them here.
    Jellyfin 10.10.7 (natively installed)
    Ubuntu Server 24.04.2 LTS
    No dedicated GPU
    Main storage: 2x 4TB NVMe SSDs

    TheDreadPirate
    Offline

    Community Moderator

    Posts: 15,375
    Threads: 10
    Joined: 2023 Jun
    Reputation: 460
    Country:United States
    #2
    2024-08-16, 07:18 PM
    Can you show us the script or the particular endpoint you are using plus the parameters used?
    Jellyfin 10.10.7 (Docker)
    Ubuntu 24.04.2 LTS w/HWE
    Intel i3 12100
    Intel Arc A380
    OS drive - SK Hynix P41 1TB
    Storage
        4x WD Red Pro 6TB CMR in RAIDZ1
    [Image: GitHub%20Sponsors-grey?logo=github]
    ca2ju
    Offline

    Junior Member

    Posts: 19
    Threads: 5
    Joined: 2024 May
    Reputation: 0
    Country:Canada
    #3
    2024-08-16, 09:27 PM
    import requests
    import logging
    import os
    from flask import current_app as app
    from dotenv import load_dotenv

    load_dotenv() # Essa chamada deve estar antes de acessar variáveis de ambiente

    JELLYFIN_URL = os.getenv("JELLYFIN_URL")
    REQUIRESELEVATION_API_KEY = os.getenv("REQUIRESELEVATION_API_KEY")
    DEFAULTAUTHORIZATION_API_KEY = os.getenv("DEFAULTAUTHORIZATION_API_KEY")
    PRODUCT_ID_BASICO = os.getenv("PRODUCT_ID_BASICO")
    PRODUCT_ID_ESTANDAR = os.getenv("PRODUCT_ID_ESTANDAR")
    PRODUCT_ID_PREMIUM = os.getenv("PRODUCT_ID_PREMIUM")

    def create_jellyfin_user(username, password):
    url = f"{JELLYFIN_URL}/Users/New"
    headers = {"X-Emby-Token": REQUIRESELEVATION_API_KEY}
    payload = {"Name": username, "Password": password}
    response = requests.post(url, json=payload, headers=headers)
    if response.status_code == 200 or response.status_code == 204:
    app.logger.info(f"Jellyfin user created successfully for {username}") # Log de sucesso
    if response.status_code == 200:
    return response.json() # Retorna as informações do novo usuário se houver retorno
    return None # Retorna None para status 204, pois geralmente não há corpo de resposta
    else:
    app.logger.error(f"Failed to create Jellyfin user with status code {response.status_code}")
    return None

    def update_user_configuration(jellyfin_user_id):
    url = f"{JELLYFIN_URL}/Users/{jellyfin_user_id}/Configuration"
    payload = {
    "AudioLanguagePreference": "spa",
    "PlayDefaultAudioTrack": False,
    "SubtitleLanguagePreference": "spa",
    "DisplayMissingEpisodes": False,
    "SubtitleMode": "None"
    }
    headers = {"X-Emby-Token": DEFAULTAUTHORIZATION_API_KEY}
    response = requests.post(url, json=payload, headers=headers)
    if response.status_code == 200 or response.status_code == 204:
    app.logger.info(f"User configuration updated successfully.")
    return response.status_code # Retorna o status code para indicar sucesso
    else:
    app.logger.error(f"Failed to update user configuration with status code {response.status_code}")
    return response.status_code # Continua retornando o status code para indicar o tipo de erro

    def update_user_policy(jellyfin_user_id, product_id):
    # Mapeamento de product_id para max_sessions usando variáveis carregadas
    session_limits = {
    PRODUCT_ID_BASICO: 1, # Assinatura básica permite 1 sessão
    PRODUCT_ID_ESTANDAR: 2, # Assinatura padrão permite 2 sessões
    PRODUCT_ID_PREMIUM: 4 # Assinatura premium permite 4 sessões
    }

    # Recupera o limite de sessões baseado no product_id, padrão para 1 se não mapeado
    max_sessions = session_limits.get(product_id, 1)

    url = f"{JELLYFIN_URL}/Users/{jellyfin_user_id}/Policy"
    payload = {
    'IsAdministrator': False,
    'IsHidden': True,
    'EnableCollectionManagement': False,
    'EnableSubtitleManagement': False,
    'EnableLyricManagement': False,
    'EnableLiveTvManagement': False,
    'EnableLiveTvAccess': False,
    'EnableContentDownloading': False,
    'InvalidLoginAttemptCount': 6,
    'LoginAttemptsBeforeLockout': 6,
    'MaxActiveSessions': max_sessions,
    'EnableAllChannels': False,
    'AuthenticationProviderId': "Jellyfin.Server.Implementations.Users.DefaultAuthenticationProvider",
    'PasswordResetProviderId': "Jellyfin.Server.Implementations.Users.DefaultPasswordResetProvider",
    'SyncPlayAccess': "None"
    }
    headers = {"X-Emby-Token": REQUIRESELEVATION_API_KEY}
    response = requests.post(url, json=payload, headers=headers)
    if response.status_code == 200 or response.status_code == 204:
    app.logger.info(f"User policy updated successfully with product ID: {product_id}")
    return response.status_code
    else:
    app.logger.error(f"Failed to update user policy for user: status code {response.status_code}")
    return response.status_code

    def disable_user(jellyfin_user_id):
    url = f"{JELLYFIN_URL}/Users/{jellyfin_user_id}/Policy"
    payload = {
    'IsAdministrator': False,
    'EnableContentDownloading': False,
    'IsHidden': True,
    'IsDisabled': True,
    'AuthenticationProviderId': "Jellyfin.Server.Implementations.Users.DefaultAuthenticationProvider",
    'PasswordResetProviderId': "Jellyfin.Server.Implementations.Users.DefaultPasswordResetProvider"
    }
    headers = {"X-Emby-Token": REQUIRESELEVATION_API_KEY}

    try:
    response = requests.post(url, json=payload, headers=headers)
    if response.status_code == 200 or response.status_code == 204:
    app.logger.info(f"User disabled successfully for user ID: {jellyfin_user_id}")
    return response.status_code # Retorna o status code para indicar sucesso
    else:
    app.logger.error(f"Failed to disable user with user ID: {jellyfin_user_id}, status code {response.status_code}")
    return response.status_code # Retorna o status code mesmo em caso de falha
    except requests.exceptions.RequestException as e:
    app.logger.error(f"Failed to disable user with user ID: {jellyfin_user_id} due to network error: {e}")
    return None # Retorna None para indicar uma falha na chamada da API

    def check_server_connectivity():
    url = f"{JELLYFIN_URL}/System/Ping"
    try:
    response = requests.get(url)
    if response.status_code == 200:
    app.logger.info("Jellyfin server is online.")
    return True
    else:
    app.logger.warning(f"Failed to ping Jellyfin server with status code {response.status_code}")
    return False
    except requests.exceptions.RequestException as e:
    app.logger.error(f"Failed to ping Jellyfin server due to network error: {e}")
    return False
    .

    Don't worry about the comments in the script, they're in Portuguese. Just to provide more information, the API keys I'm using were created within the server for both REQUIRESELEVATION and DEFAULTAUTHORIZATION. I've also tested using the administrator's access token for REQUIRESELEVATION_API_KEY, but I encountered the same issue with the "first two users."
    Jellyfin 10.10.7 (natively installed)
    Ubuntu Server 24.04.2 LTS
    No dedicated GPU
    Main storage: 2x 4TB NVMe SSDs

    xaque
    Offline

    Member

    Posts: 76
    Threads: 1
    Joined: 2023 Jun
    Reputation: 3
    Country:United States
    #4
    2024-08-17, 02:56 AM
    Have you tried using the jellyfin api client python?

    https://github.com/jellyfin/jellyfin-apiclient-python

    I haven't noticed your issue when I've used this to create multiple clients, albeit I'm not using apikeys. Rather, I'm using an access token from an elevated user.
    ca2ju
    Offline

    Junior Member

    Posts: 19
    Threads: 5
    Joined: 2024 May
    Reputation: 0
    Country:Canada
    #5
    2024-08-21, 02:43 AM
    I came back to give feedback and say that I tried everything. What worked for me was creating a new administrator user and using their access token; everything went back to normal.
    Jellyfin 10.10.7 (natively installed)
    Ubuntu Server 24.04.2 LTS
    No dedicated GPU
    Main storage: 2x 4TB NVMe SSDs

    « Next Oldest | Next Newest »

    Users browsing this thread: 1 Guest(s)


    • View a Printable Version
    • Subscribe to this thread
    Forum Jump:

    Home · Team · Help · Contact
    © Designed by D&D - Powered by MyBB
    L


    Jellyfin

    The Free Software Media System

    Linear Mode
    Threaded Mode