How to delete a Plex movie trailer correctly?

Hi guys’n’girls,

I have a German language movie library and it always hurt my feelings that I have movie trailers in my library with English audio.

Using PlexAPI and Python, I found a way to delete all trailers with audio not in German language. And those trailer disappear.

To make a long story short, I am searching for all movies with trailer extras, then check the audio track languages and in addition to that I check also the extra title for mentioning of German language. All non-German trailers are deleted.

Here’s the relevant section of the code:

    try:
        plex = PlexServer(baseurl, token)
        movies = plex.library.sectionByID(library_id).search(libtype='movie')
    except Exception as e:
        print(f"Fehler beim Verbinden mit dem Plex-Server oder Abrufen der Bibliothek: {e}")
        return []

    movie_data = []
    for movie in movies:
        film_info = {
            "title": movie.title,
            "year": movie.year,
            "trailer_available": False,
            "trailer_audio_languages": [],
            "has_german_trailer": False
        }

        # Überprüfen, ob Extras vorhanden sind und ob es Trailer gibt
        if movie.extras():
            for extra in movie.extras():
                extra_title = extra.title
                if extra.subtype == 'trailer':
                    film_info["trailer_available"] = True
                    # Durchlaufe alle Streams des Trailers, um Audiospuren zu finden
                    for part in extra.iterParts():
                        for stream in part.audioStreams():
                            if stream.streamType == 2 and stream.language:  # StreamType 2 ist Audio
                                film_info["trailer_audio_languages"].append(stream.language)
                            if 'german' in extra_title.lower():
                                film_info["trailer_audio_languages"].append("German")
                            if 'deutsch' in extra_title.lower():
                                film_info["trailer_audio_languages"].append("Deutsch")
                    break # Nur den ersten Trailer prüfen

        # Prüfen, ob eine der Audiosprachen Deutsch ist oder Deutsch im Titel genannt wird
        if "Deutsch" in film_info["trailer_audio_languages"] or "German" in film_info["trailer_audio_languages"]:
            film_info["has_german_trailer"] = True

        movie_data.append(film_info)

        if film_info["has_german_trailer"] == False:
            if movie.extras():
                for extra in movie.extras():
                    if extra.subtype == 'trailer':
                        print(f"  - Lösche Trailer: {extra.title}")
                        extra.delete()

...

The trailer is removed from the movie object (view and XML). But unfortunately the link of the trailer to the “Play Trailer button” is not removed…

This is what it looks like:

Movie with German trailer (correct display: trailer visible, play trailer button above also):

Movie that never had a trailer (also correct display: no trailer and no button to play trailer):

The relevant XML of that movie looks like this:

<Extras size="0"> </Extras>

Movie where I removed the trailer (incorrect display: trailer gone, button to play trailer there):

The relevant XML of that movie looks like this (the same as the other movie):

<Extras size="0"> </Extras>

And since the trailer is deleted, an attempt to play it results in an error message:
image

My question:
How do I delete the extras of a movie in a way that Plex also removes the play trailer button?

That one:
image

Is there a way to get rid of this button? I tried “refresh metadata” for that movie, “Analyze” that movie, and re-read the library files of that library.
If I add another local trailer and try to remove it again, the reference of that local trailer trailer stays.

Only if I remove the movie itself from the library and re-add it without any trailer, the trailer and the trailer play button go away.

Of course, it’s not every day’s work for Plex to remove existing trailers as they are meant to stay. But if the file is gone, the play button should be gone, too. Shouldn’t it?

Can you try to Clean Bundles and then Optimize Database in the Troubleshooting section?

Has the server gone through a maintenance window (scheduled tasks)?

Maybe add the following to the end of your script.

plex.library.cleanBundles()
plex.library.optimize()

Thx @Atomatth for caring. The evening before yesterday, I deleted around 100 trailers. Yesterday evening, I added around 90 German trailers for these movies.

Then, I started a full swing on English trailers in that library which deleted almost 1000 non-German trailers.

Just doin’ it now, will report. Cleaning bundles takes a while… :slight_smile:

How do I know? But if this happens once a week, then I doubt it.
These are my maintainance settings:

Unfortunately, this did not help. Still the same symptom. Does it help you that almost all of the script-deleted trailers were trailers that go automatically added to my library by Plex - not local media.

I’m able to reproduce your reported problem pretty easily. I’ve filed an issue internally to track. Thanks for reporting.

1 Like

Would be perfect to have this fixed as well as to have a solution for somebody who already ran into this problem :slight_smile:

@Atomatth any news on this bug/inconcistency?

Sorry to bother you about this.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.