From 83bdf4914853f292baf5ab69f2e31d4697d29a83 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Sun, 27 Oct 2019 15:59:14 -0700 Subject: [PATCH] Add Plex modifying metadata scripts --- utility/remove_movie_collections.py | 22 ++++++++++++ utility/rename_seasons.py | 52 +++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 utility/remove_movie_collections.py create mode 100644 utility/rename_seasons.py diff --git a/utility/remove_movie_collections.py b/utility/remove_movie_collections.py new file mode 100644 index 0000000..891de13 --- /dev/null +++ b/utility/remove_movie_collections.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Description: Removes ALL collections from ALL movies. +# Author: /u/SwiftPanda16 +# Requires: plexapi + +from plexapi.server import PlexServer + +### EDIT SETTINGS ### + +PLEX_URL = "http://localhost:32400" +PLEX_TOKEN = "xxxxxxxxxx" +MOVIE_LIBRARY_NAME = "Movies" + + +## CODE BELOW ## + +plex = PlexServer(PLEX_URL, PLEX_TOKEN) + +for movie in plex.library.section(MOVIE_LIBRARY_NAME).all(): + movie.removeCollection([c.tag for c in movie.collections]) diff --git a/utility/rename_seasons.py b/utility/rename_seasons.py new file mode 100644 index 0000000..7747044 --- /dev/null +++ b/utility/rename_seasons.py @@ -0,0 +1,52 @@ +#!/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.edit(**{"title.value": new_season_title, "title.locked": 1}) + print("'{}' renamed to '{}'.".format(old_season_title, new_season_title)) + elif new_season_title == "": + season.edit(**{"title.value": new_season_title, "title.locked": 0}) + 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.")