Skip to content

Instantly share code, notes, and snippets.

@JonnyWong16
Created August 30, 2022 17:38
Show Gist options
  • Save JonnyWong16/5850a467893aec44af36bb13aab106a5 to your computer and use it in GitHub Desktop.
Save JonnyWong16/5850a467893aec44af36bb13aab106a5 to your computer and use it in GitHub Desktop.
Move a TV show's special episode to it's own season in Plex
from plexapi.server import PlexServer
plex = PlexServer('http://localhost:32400', token='XXXXXXXXXXXXXXXXXXXX')
tvshows = plex.library.section('TV Shows')
show = tvshows.get('Dragon Ball')
# Get season 2
season = show.season(2)
# Lock all the season 2 episode metadata
for episode in season:
episode.batchEdits()
episode \
.editTitle(episode.title) \
.editSortTitle(episode.titleSort) \
.editOriginallyAvailable(episode.originallyAvailableAt) \
.editContentRating(episode.contentRating) \
.editSummary(episode.summary) \
.addWriter(episode.writers) \
.addDirector(episode.directors) \
.lockArt() \
.lockPoster()
episode.saveEdits()
# Change season 2 to season 3 (keep title "Season 2")
# Technically all episodes from season 2 will be in season 3 but with season 2 metadata
season.batchEdits()
season \
.editTitle(season.title) \
.editSummary(season.summary) \
.lockArt() \
.lockPoster()
season._edits['index.value'] = season.index + 1
season._edits['index.locked'] = 1
season.saveEdits()
# Get season 0
season = show.season(0)
# Lock all season 0 episode 1 metadata
episode = season.episode(1)
episode.batchEdits()
episode \
.editTitle(episode.title) \
.editSortTitle(episode.titleSort) \
.editOriginallyAvailable(episode.originallyAvailableAt) \
.editContentRating(episode.contentRating) \
.editSummary(episode.summary) \
.addWriter(episode.writers) \
.addDirector(episode.directors) \
.lockArt() \
.lockPoster()
episode._edits['index.value'] = 1
episode._edits['index.locked'] = 1
episode.saveEdits()
# Change season 0 to season 2 (change season title to episode title)
# Technically all episodes from season 0 will be in season 2 but with season 0 metadata
# Can only change an entire season number at once, so add episodes to season 0 one at a time
season.batchEdits()
season \
.editTitle(episode.title) \
.editSummary(season.summary) \
.lockArt() \
.lockPoster()
season._edits['index.value'] = 2
season._edits['index.locked'] = 1
season.saveEdits()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment