Created
November 13, 2019 04:47
-
-
Save pmow/167a04d67da6488b7ec29ecbfc92c30b to your computer and use it in GitHub Desktop.
generate symlinked structure of unwatched or tagged items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from plexapi.myplex import MyPlexAccount | |
import os, sys, regex | |
path = "/home/pmow/plex_paths" | |
account = MyPlexAccount('username', 'password') | |
plex = account.resource('servername').connect() # returns a PlexServer instance | |
# oldpath,newpath,spath(specific/section path) | |
def symit(location,path,spath): | |
print(os.path.basename(location)) | |
rlocation = regex.subf(r'/data/','/mnt/',location) | |
print("Current location: "+rlocation) | |
newfilepath=path+spath+"/"+os.path.basename(os.path.dirname(rlocation)) | |
print("Creating path: "+newfilepath) | |
if not os.path.exists(newfilepath): | |
os.makedirs(newfilepath) | |
os.symlink(rlocation,path+spath+"/"+os.path.basename(os.path.dirname(rlocation))+"/"+os.path.basename(rlocation)); | |
#unwatched movies | |
spath = "/unwatched/MOVIES" | |
movies = plex.library.section('Movies') | |
for movie in movies.search(unwatched=True): | |
for location in movie.locations: | |
symit(location,path,spath) | |
#unwatched TV | |
spath = "/unwatched/TV" | |
tvsection = plex.library.section('TV Shows') | |
for show in tvsection.all(): | |
if(show.isWatched): | |
continue | |
for episode in show.episodes(): | |
if(episode.isWatched): | |
continue | |
print(show.title+" - "+episode.seasonEpisode) | |
for location in episode.locations: | |
symit(location,path,spath) | |
#tagged Luca | |
spath = '/Luca' | |
for show in tvsection.search(collection='Luca'): | |
for episode in show.episodes(): | |
for location in episode.locations: | |
symit(location,path,spath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment