Python-PlexAPI
This unofficial app installation guide is provided for your convenience. The guide is provided as-is and may not be updated or maintained by Ultra.cc. Unofficial support may be offered via Discord only and at the sole discretion of Ultra.cc staff. Use at your own risk and only proceed if you are comfortable managing the application on your own.
Python-PlexAPI is a utility tool with intent of performing actions on your Plex instance by interacting with the Plex API. Included features are library actions such as scan, analyze, empty trash among many other things.
- More information can be found here.
Prerequisites
Installation
Do note, Python-PlexAPI requires some familiarity with the Linux terminal and scripting in general. If you are new to this, you should start by reading Your Ultra.cc Shell - A Beginner's Guide.
- Connect to your Ultra.cc service via SSH
- Once connected, execute the following command:
pip install plexapi
- Once the installation has completed, you can begin using the utility tool.
- In this guide, we will
createuseaour pre-made script that lists all your media titles in a.txt
file.- However, this is just one of many usecases. Other examples can be found here.
- However, this is just one of many usecases. Other examples can be found here.
- Start by
creatingdownloadinga Pythonthe scriptfiletoandyourmakeUltraitserviceexecutable.with the following command.
touchwget plexapi.py && chmod +x plexapi.https://scripts.usbx.me/util/Python-PlexAPI/main.py
- Next, open the file in the Nano editor.
nano plexapi.main.py
PasteBefore you can use the
followingscript,scriptyouintoneedthe editor andto edit theplex_url
and,plex_token
.and the library names of your Plex server.- You can find your Plex IP in the Plex webUI. Navigate to Settings > Remote Access and copy the Private IP. It will be in the format of
172.17.0.xxx
. Do note, if Plex is restarted/upgraded, the private IP might change, and you will need to update your script with the new IP. - You can find your Plex token by following the instructions in this link.
- Additionally, you must edit the script to reflect your library names instead of 4K Movies, 1080p Movies and TV Shows.
- You can find your Plex IP in the Plex webUI. Navigate to Settings > Remote Access and copy the Private IP. It will be in the format of
from plexapi.server import PlexServer
# Replace 'http://YOUR-PLEX-IP:32400' and 'YOUR-PLEX-TOKEN' with your Plex server details
plex_url = 'http://YOUR-PLEX-IP:32400'
plex_token = 'YOUR-PLEX-TOKEN'
# Connect to the Plex server
plex = PlexServer(plex_url, plex_token)
# Output file name
output_file = 'plex_media_titles_with_year.txt'
# Replace library names to align with your Plex server's library names.
with open(output_file, 'w', encoding='utf-8') as file:
file.write("4K Movies:\n")
for movie in plex.library.section('4K Movies').all():
file.write(f"{movie.title} ({movie.year})\n")
file.write("\n1080p Movies:\n")
for movie in plex.library.section('1080p Movies').all():
file.write(f"{movie.title} ({movie.year})\n")
file.write("\nTV Shows:\n")
for show in plex.library.section('TV Shows').all():
file.write(f"{show.title} ({show.year})\n")
print(f"Media titles with release year have been written to {output_file}")
Once you have edited the script with your Plex server details and library names, you can save and exit the editor.
- To save and exit, press
CTRL+X
andY
, then pressENTER
to confirm.
- To save and exit, press
-
To run the script, execute the following command:
python plexapi.main.py
- Depending on the size of your library, it may take some time to execute.
- If the execution of the script was successful, you should see the following output in your terminal.
ultradocs@spica:~$ python plexapi.py
Media titles with release year have been written to plex_media_titles_with_year.txt
- You can find your media titles listed in
plex_media_titles_with_year.txt