How can an agent remove previously downloaded posters from a bundle?

I’ve written an iTunes metadata agent because i prefer iTunes genres. I’ve made it configurable through the UI so you can specify what metadata from iTunes is use or skipped (support title, summary, collections, release date, rating, runtime, genres, and artwork). For the most part it works great. However, i have one issue that i can’t seem to figure out.

When i configure it to use iTunes artwork, it will download and use the poster from iTunes. However, if i then change the preferences to NOT use iTunes artwork and Refresh Metadata, it keeps the iTunes artwork. I believe this happens because the server just looks at agent ordering and since iTunes is at the top and it had downloaded posters previously, it will use the iTunes artwork. I tested by putting iTunes agent under Plex Movie and then it uses the artwork from the Plex Movie agent.

So my thinking is that i need to delete from the bundle the previously downloaded itunes artwork so that it wont be available and my preference to NOT use iTunes artwork will prevent a new copy from being downloaded. So is there a way to delete this artwork from the bundle from within the metadata python code?

Keep track of the posters you’d like to keep (could be none), then use metadata.posters.validate_keys to clear the list/keep the ones you want, based on user preferences set.

# In this list we are going to save the posters that we want to keep
valid_names = list()

# Grab the data we need for posters
json_obj = GetJSON(......)

# If our agent's "i_want_posters" preference is set to True and our (API) request contains posters, go ahead an process those posters
if Prefs['i_want_posters'] == True and json_obj and 'movieposter' in json_obj:

	i = 0

	for img in json_obj['movieposter']:

		poster_url = img['url']
		valid_names.append(poster_url) # Keep track of the posters we want to keep

		if poster_url not in metadata.posters:
			try:
				i += 1
				metadata.posters[poster_url] = Proxy.Preview(HTTP.Request(poster_url).content, sort_order=i)
			except:
				pass

# Clean up the list with posters (keep only the ones we process, or not if the "i_want_posters" was set to False)
metadata.posters.validate_keys(valid_names)

@sander1 Unfortunately that didn’t work. My code is already very similar (see below). It works as expected if i have never retrieved any metadata from iTunes and i’ve configured the agent to not use the iTunes artwork. However, if set the preference to use itunes artwork, then refresh metadata (at which point the artwork changes), then i change the preference to not use iTunes artwork, refresh again, i’m stuck with the itunes artwork. Looking into the bundle, even though the artwork is removed from the agent folder (in my case, “com.plexapp.agents.itunesmetadata”), there is still a copy of the image in the _stored and _combined folder.

So it looks as though once the posters have been downloaded, it uses the agent ordering to pick one, regardless of whether on a refresh an agent pulls any artwork or not.

Any other suggestions? Here’s my code section for pulling the posters from iTunes:

`

# Posters
# List to keep track of valid poster urls
valid_names = list()

if Prefs['artwork'] == True:

    Log('Refreshing artwork from iTunes')

    if 'artworkUrl100' in itunes_lookup_dict:
        if "100x100bb-85" in itunes_lookup_dict['artworkUrl100']:
            fullURL = itunes_lookup_dict['artworkUrl100'].replace("100x100bb-85", "10000x10000bb-100")
            previewURL = itunes_lookup_dict['artworkUrl100'].replace("100x100bb-85", "1000x1000bb-100")
        else:
            fullURL = itunes_lookup_dict['artworkUrl100'].replace("100x100bb", "10000x10000bb")
            previewURL = itunes_lookup_dict['artworkUrl100'].replace("100x100bb", "1000x1000bb")

        valid_names.append(fullURL)

        if fullURL not in metadata.posters:
            try:
                metadata.posters[fullURL] = Proxy.Preview(HTTP.Request(previewURL).content, sort_order=1)
            except:
                try:
                    metadata.posters[itunes_lookup_dict['artworkUrl100']] = Proxy.Media(HTTP.Request(itunes_store_dict['artworkUrl100']).content, sort_order=100)
                    valid_names.append(itunes_lookup_dict['artworkUrl100'])
                except:
                  pass

# Validate movie posters
metadata.posters.validate_keys(valid_names)

`

@rcork said:
@sander1 Unfortunately that didn’t work.

It has been a while since I looked at agents, but I can confirm, you are correct. It should work that way, but it simply does not :frowning: I know of no other way to remove posters from agents. I’m going to create a bug report for this.

Thanks @sander1 for filing the bug report. Once this gets fixed i’ll continue to finalize my iTunes metadata agent. Will you report back to this thread once it has been released in a PMS build?

Any update on this @sander1 ?
It still doesn’t work