Jump to content

metadata >> People (bulk refresh posters)


crunchyemby
 Share

Recommended Posts

crunchyemby

Hello All

 

First of all, Emby is turning out to be a pretty amazing application... Very glad I found it. I have attempted to find the answer to my problem, before posting, without a clear answer. So, here goes:

 

Due to inconsistencies and mis-matched identification, I have disabled all metadata services and authored a script to publish my own "People" data to the emby metadata location ( /var/db/emby-server/metadata/People/*/* ). The problem is, the updated images "poster.jpg" are not being picked up on a "Scheduled tasks >> Refresh people" ... Rather, I have to manually "Refresh", from the context menu, for each Person. Obviously this is not going to work for the long-run.

 

I have found a workaround, if I delete these two files: "library.db" and "refreshinfo.db" ... I can rebuild the complete database and start over. Also a pain in the ... but better than manually refreshing through the GUI.

 

Any recommendations?

 

Cheers!

Link to comment
Share on other sites

crunchyemby

In case anybody else is having this problem, here's a snippet to get you started... I'm still trying to track down some "enhanced image caching" that occurs at times... but I have tested that the functionality works as expected.

 

Cheers!

 

 

BEGIN PYTHON SCRIPT:

import requests
import json
import hashlib

#config
emby_server_ip = 'xxx.xxx.xxx.xxx' #EXAMPLE: 192.168.0.100'
emby_server_port = 'xxxx' #EXAMPLE: '8096'
emby_username = 'USERNAME'
password_plain_text = 'PASSWORD'
refresh_name_list = [] #EXAMPLE: ['John Doe', 'Mary Palmer']

def authenticate_user():
    global user_id
    global user_api_key
    password_sha1 = hashlib.sha1(password_plain_text).hexdigest()
    password_md5 = hashlib.md5(password_plain_text).hexdigest()
    request_url = "http://%s:%s/Users/AuthenticateByName" % (emby_server_ip, emby_server_port)
    request_params = {'Username': emby_username, 'Password': password_sha1, 'PasswordMd5': password_md5, 'Authorization': 'MediaBrowser', 'Client': 'Python', 'Device': 'PythonScript', 'DeviceId': '12345678910987654321', 'Version': '1.0.0.0', 'format': 'json'}
    r = requests.post(request_url, params=request_params)
    print 'Authenticating. Status: %s' % (r.status_code)
    j = json.loads(r.text)
    user_id = j['User']['Id']
    user_api_key = j['AccessToken']
    print 'user_id: %s' % (user_id)
    print 'user_api_key: %s' % (user_api_key)
    return user_id, user_api_key

def refresh_primary_image_for_person(full_name):
    print '\nProcessing refresh: %s' % (full_name)
    search_name = full_name.strip().replace(' ', '+')
    request_url = "http://%s:%s/Persons/%s" % (emby_server_ip, emby_server_port, search_name)
    request_params = {'api_key': user_api_key, 'format': 'json'}
    r = requests.get(request_url, params=request_params)
    print 'Fetch primary image id, response: (%s, %s)' % (r.status_code, r.reason)
    j = json.loads(r.text)
    try:
        primary_image_id = j['ImageTags']['Primary']
        print 'primary_image_id: %s' % (primary_image_id)
    except:
        print 'WARNING: primary image not found for: %s' % (full_name)
        return
    request_url = 'http://%s:%s/emby/Items/%s/Refresh?Recursive=true&ImageRefreshMode=FullRefresh&MetadataRefreshMode=FullRefresh&ReplaceAllImages=false&ReplaceAllMetadata=true' % (emby_server_ip, emby_server_port, primary_image_id)
    params={'UserId': user_id, 'X-MediaBrowser-Token': user_api_key, 'Authorization': 'MediaBrowser', 'Client': 'Python', 'Device': 'PythonScript', 'DeviceId': '12345678910987654321', 'Version': '1.0.0.0', 'Recursive': 'true', 'ImageRefreshMode': 'FullRefresh', 'MetadataRefreshMode': 'FullRefresh', 'ReplaceAllImages': 'true', 'ReplaceAllMetadata': 'true'}
    r = requests.post(request_url, params=request_params)
    print 'Refresh primary image. Status: (%s, %s)' % (r.status_code, r.reason)
    if str(r.status_code) == '204':
        print 'STATUS: %s\'s primary image was refreshed.' % (full_name)
    return

user_id, user_api_key = authenticate_user()
for name in refresh_name_list:
    refresh_primary_image_for_person(name)



Edited by crunchyemby
Link to comment
Share on other sites

crunchyemby

I'm pulling my hair out, tracking down the cached images...

 

Things I've tried:

  • Cleared the browser cache.
  • [DISABLED] Manage Server >> Advanced >> Developer Options >> Enable web client response caching
  • [DISABLED] Manage Server >> Advanced >> Developer Options >> Enable web client resource minification
  • Looked through the SQL database, found the People table... confirmed that there is not a cache path.
  • Found a json data object in the SQL table 'TypedBaseItems', containing the path to the Person's directory... confirmed that there is not a reference to a cached resource.
  • Searched emby-server/* file system for any reference to the image ID or tag=ID, found in the image url... no result found.

OBSERVATION:

From my black box testing, there seems to be inconsistent caching rules, depending on where the images are used... for example, the Primary image on this page [server:port/web/itemdetails.html?id=PERSONID] does not adhere to the same rules as the Person's Primary Image on [server:port/web/itemdetails.html?id=MOVIEID] page. 

POSSIBLE EXPLANATION:

One possible explanation is the optimization (ImageMagick) of the source images are getting stored somewhere (yet to be discovered by me) and not being refreshed... or have a TTL (time-to-live) set on the asset, which makes testing very difficult.

 

ANYBODY:

Please, if anybody can point me where to look for TTL/caching rules, cached assets with a method for cross reference, other (e.g., Fix my api call above. Maybe I'm missing a critical header in my request?)...

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...