Skip to content

Instantly share code, notes, and snippets.

@JonnyWong16
Last active August 28, 2023 17:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonnyWong16/53be5e222cc293191680c4fe11727a30 to your computer and use it in GitHub Desktop.
Save JonnyWong16/53be5e222cc293191680c4fe11727a30 to your computer and use it in GitHub Desktop.
Rename season title for TV shows on Plex.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Description: Rename season title for TV shows on Plex.
# Author: /u/SwiftPanda16
# Requires: plexapi
from plexapi.server import PlexServer
### EDIT SETTINGS ###
PLEX_URL = "http://localhost:32400"
PLEX_TOKEN = "xxxxxxxxxx"
TV_SHOW_LIBRARY = "TV Shows"
TV_SHOW_NAME = "Sailor Moon"
SEASON_MAPPINGS = {
"Season 1": "Sailor Moon", # Season 1 will be renamed to Sailor Moon
"Season 2": "Sailor Moon R", # Season 2 will be renamed to Sailor Moon R
"Season 3": "Sailor Moon S", # etc.
"Season 4": "Sailor Moon SuperS",
"Season 5": "Sailor Moon Sailor Stars",
"Bad Season Title": "", # Blank string "" to reset season title
}
## CODE BELOW ##
def main():
plex = PlexServer(PLEX_URL, PLEX_TOKEN)
show = plex.library.section(TV_SHOW_LIBRARY).get(TV_SHOW_NAME)
print("Found TV show '{}' in the '{}' library on Plex.".format(TV_SHOW_NAME, TV_SHOW_LIBRARY))
for season in show.seasons():
old_season_title = season.title
new_season_title = SEASON_MAPPINGS.get(season.title)
if new_season_title:
season.editTitle(new_season_title)
print("'{}' renamed to '{}'.".format(old_season_title, new_season_title))
elif new_season_title == "":
season.edit(new_season_title, locked=False)
print("'{}' reset to '{}'.".format(old_season_title, season.reload().title))
else:
print("No mapping for '{}'. Season not renamed.".format(old_season_title))
if __name__ == "__main__":
main()
print("Done.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment