I’ve previously managed to build a custom Movie metadata agent for my needs and am fairly familiar with the inner workings of Plex, with Python and programming in general. However, the documentation for custom Scanners and Metadata Agents is so severely lacking that even after hours and hours of detailed debugging and studying the source code of other Metadata Agents multiple times, I still can’t get my first draft of a custom TV Series Metadata Agent to work.
From what I think I’ve learned: My Agent.TV_Shows needs two methods: search() and update(). By means of logging I have verified that my update() method is definitely called. It is called once for each show that the scanner created, which seems fine to me.
Inside my update() method I have @parallelize def UpdateEpisodes() and finally a @task def UpdateEpisode(episode=episode) which I also confirmed via logging are called for each episode.
For testing I wanted to set each episodes title to “AGENT: $originalTitle” and check if the “AGENT:” prefix is applied. However, the title always stays the original title that was set by the scanner. So I tried settling for something even simpler, updating nothing but the metadata of the show. But again, no luck when checking the web interface for the data I was trying to set.
Here is my very, very simple code. (The code tags of this forum didn’t format it correctly, so I put it on Github…)
I checked all the log files and could not see any errors that might explain why the data is not being updated. Even more weirdly: The data is present when I check in the xml files directly, here is an excerpt:
less ‘~/Library/Application Support/Plex Media Server/Metadata/TV Shows/0/66718ce56a10dc3c41b7ab4c9e17404b612695b.bundle/Contents/com.plexapp.agents.mytestcom/Info.xml’
`<?xml version='1.0' encoding='utf-8'?>
<TV_Show id=“MyTest.com”>
<title_sort/>
123 test test test
1981-12-03
test test test
`
As I said, I’ve honestly spent many evenings doing nothing but trying to find out what I’m missing or doing differently than existing agents. It feels like I’m just missing one final metadata.actually_save_everything() call or something like that, but I finally have to give up and admit that I’m unable to solve this on my own. Any help would be greatly appreciated.
if class is called MyTestAgent then name = ‘MyTest’
filename should be called ‘code.py’ with double underscore around code
you should paste the agent log and system log located in same folder, if there is any python error then the metadata will not be saved
thanks a lot for your reply.
Don’t you mean init.py instead of code.py?
Neither log file contains any errors, I’m afraid. I already searched all the log files. I’m also using them to verify my code is actually executed, which it definitely is. (E.g. the “before” and “after” lines from the code I linked to above are in the logs, but the metadata isn’t showing up in the web interface, just in the xml files.) So I’m fairly certain that everything with the filenames/structure and class names etc. is working.
I adapted my draft mostly from studying your HAMA and the official TheTVDB agent, but it is really hard to figure out which method and property names are “the official ones” that are required for an agent to work and which ones are only used by a specific agent for their own reasons. Would you say from your knowledge that I correctly identified the required parts for a TV_Shows agent or is there more to it than the search() and update() methods?
Yes you are correct.
You might be missing some fields and some name mismatch…:
the name should match the class without “Agent”
name, primary_provider, fallback_agent, contributes_to, languages, accepts_from = (‘HamaTV’, True, False, None, [Locale.Language.English,], [‘com.plexapp.agents.localmedia’] ) #, ‘com.plexapp.agents.opensubtitles’
Also try to output metadata.id in logs in your update function. Try ro replace metadata.title. logs should say update failed.):
name, primary_provider, fallback_agent, contributes_to, languages, accepts_from = (‘HamaTV’, True, False, None, [Locale.Language.English,], [‘com.plexapp.agents.localmedia’] ) #, ‘com.plexapp.agents.opensubtitles’
Thank you so much, after comparing your sample to my code I quickly found two major differences: I hadn’t set the required attribute primary_provider. Setting it didn’t change anything, though. What seems to have been the deciding factor is that my test code was only updating summary, studio and originally_available_at. Once I added title to that list, it worked.