User Tools

Jellyfin

Change items ratings

import requests
import json
import time

# create a formatted string of the Python JSON object
def jprint(obj):
    text = json.dumps(obj, sort_keys=True, indent=4)
    print(text)

ip = "***********"
user_id = "***************"
token = "**************"
music_folder_id = "**************"

# get all items
url_get_all = 'http://'+ ip+ ':8096/Items'

params_get_all = {
    'parentId': music_folder_id,
    'recursive': True}

headers = {
    'Authorization' : 'MediaBrowser Token="'+ token+'"',
    'Content-Type': 'application/json'}

response_get = requests.get(url_get_all, params=params_get_all, headers=headers)
json_result = response_get.json()

url_get_item = 'http://'+ ip+ ':8096/Users/'+ user_id+ '/Items'

# gt all items list (not all the fields are received)
for item in json_result['Items']:
    if 'IsFolder' in item:
        if item['IsFolder']:
            # get individual item (to get all fields)
            response_get_individual = requests.get(url_get_item+'/'+item['Id'], params=[], headers=headers)
            if response_get_individual.status_code == 200:
                json_result_individual = response_get_individual.json()
                json_result_individual['OfficialRating'] = "Tous Publics"
                # send item back
                url_post = url_get_all+'/'+item['Id']
                response_post = requests.post(url_post, params=[], data=json.dumps(json_result_individual), headers=headers)
                if response_post.status_code != 204:
                    print('---------------')
                    print('Id = '+ item['Id'])
                    print('Name = '+ item['Name'])
                    print(response_post.status_code)
                    print(response_post.reason)
                time.sleep(0.2)

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also, you acknowledge that you have read and understand our Privacy Policy. If you do not agree, please leave the website.

More information