Jellyfin Forum
Saving a Person's Info Locally - Printable Version

+- Jellyfin Forum (https://forum.jellyfin.org)
+-- Forum: Support (https://forum.jellyfin.org/f-support)
+--- Forum: General Questions (https://forum.jellyfin.org/f-general-questions)
+--- Thread: Saving a Person's Info Locally (/t-saving-a-person-s-info-locally)



Saving a Person's Info Locally - PriestMarmore - 2024-05-25

I only have my stuff offline and I know there are plugins for getting information about the actors (but it's not for Hollywood actors if you know what I mean). 

 Here's my first problem. I know there are folders for each person and when I move a photo to someone's folder, and that photo is named "folder", the Primary photo of that actor will change, however if I do the same with a photo named backdrop, it will not change on jellyfin. Why is that? Do I really need to upload it through jellyfin.

 Secondly, I thought about creating a program that would read a folder and that folder contained 3 things: a Primary photo, a Backdrop and a .txt file with info about the person. I wanted that program to change the info of the actor in question based on what was there on the folder. Does that exist? Is there any way I can have information on a .txt file or a .nfo and I'm able to run a program that updates that information about the actor in question?

 I wrote a bit of code, I'll leave bellow, but it's not working. This is only for the information, I didn't touch on the photos yet

import os
import requests
import json
# Jellyfin server details
jellyfin_url = 'http://localhost:8096'
api_key = ''
# Function to read person info from the info.txt file
def read_person_info_from_file(file_path):
    person_info = {}
    with open(file_path, 'r', encoding='utf-8') as f:
        lines = f.readlines()
        for line in lines:
            if ':' in line:
                key, value = line.split(':', 1)
                person_info[key.strip()] = value.strip()
    return person_info
# Function to update person information
def update_person_info(person_id, new_info):
    headers = {
        'X-Emby-Token': api_key,
        'Content-Type': 'application/json'
    }
    url = f'{jellyfin_url}/Items/{person_id}'
    response = requests.post(url, headers=headers, data=json.dumps(new_info))
    print(f'Updating person info at {url} with data: {json.dumps(new_info, indent=2)}')
    print(f'Response: {response.status_code} - {response.text}')
    if response.status_code == 204:
        print('Person information updated successfully.')
    else:
        print(f'Failed to update person information: {response.status_code} - {response.text}')
# Example usage
folder_path = r'D:\Quick Access\Downloads\jelly'
info_file_path = os.path.join(folder_path, 'info.txt')
person_id = ''  # Tom Cruise's person ID
person_info = read_person_info_from_file(info_file_path)
# Prepare person info payload
update_info = {
    "Name": person_info.get("Name"),
    "Overview": person_info.get("Overview"),
    "PremiereDate": person_info.get("BirthDate"),
    "ProductionYear": int(person_info.get("BirthDate")[:4]),  # Assuming the birth year is the production year
    "Type": "Person"
}
update_person_info(person_id, update_info)