This is a fork of the discontinued TBN Plex Controller script by amazingr4b
These scripts should theoretically run on any system capable of running python, however, the system_setup.py script only currently supports Linux and Windows based installs. How to do a manual install will be added as a help doc at a later date.
Install the following python libraries
The Python Plex API pip install plexapi
Enchant pip install pyenchant
web.py for Webhooks integration pip install web.py
Important Note: You will need to add the IP or subnet for your Plex controller device to the autorized IP list in your Plex Server Settings. Look for "allowed without authorization." If not added you may run into issues updating your Plex Controller database.
Download the most recent version of the system_setup.py file. Place it in your home directory and run it as your preferred user.
Example:
$ curl "https://raw.githubusercontent.com/MoeFwacky/Python-Plex-Controller/master/system_setup.py" -o "system_setup.py" $ python system_setup.py
If you're running Linux, the system_setup.py script will create a subdirectory in your home directory, "hasystem/". If you're running Windows, it will prompt you for a directory, depending on your OS, which it will store its necessary files and database in.
The system setup script will prompt you for information in order to get the data it needs to proceed. Once installation is complete, it will prompt you to update the database. Updating the database is optional, but recommended. The Plex controller functions best when the database is up-to-date.
Note: If you enter an incorrect value during setup, which prevents the Plex controller from working properly, you can run python system_setup.py reset
from your home directory and it will delete the previously stored data and prompt you to re-enter it.
upddatedb_pi.py The upddatedb_pi.py script will update your Plex controller database. The Plex controller uses a separate database so as to avoid corrupting the existing Plex database.
You can update the database python upddatedb_pi.py movie|shows|custom_shows|prerolls|commercials|custom|all
Larger libraries will take more time to scan versus smaller libraries.
- movie - scans your Movie section
- shows - scans your TV Show section
- custom_shows - scans alternate TV Show sections
- prerolls - scans your prerolls section
- commercials - scans your commercials section
- custom. - scans alternate library types, ie- fights, music_videos, comedy. usage ex- "python upddatedb_py.py custom.fights"
- all - scans the TV Show and Movie sections
getshows.py
To upddate a single show, instead of whole sections of the database, use getshows.py.
$ python getshows.py "Name of Show
This script will check your plex server for the specified show, and any new entries are added to the database.
Note: does not update existing entires 2nd note: Is pretty much obsolete now that the script automatically updates add entires when found on the server.
It is recommended you run python system.py updatehelp
to populdate you help table with the most recent help entries. 99% of the commands now support the -h
argument, which will give a description and useage details for the given command.
Before you can use the block package commands, or block package playback, you first need to create a block package. You can use the addblock
modifier to create a block package.
When you run system_setup.py the playmode is set/reset to normal, and your queue is set to " ". It is recommended you do a whatupnext
after you run the system_setup.py script. From there your queue should never be empty. The controller is designed so something will always be up next.
Note: Always back up your hasystem folder before initiating an update
There are two ways to update. The easiest is to use the updatechecker. You will need to turn auto-update on first.
setautoupdate on updatechecker
If your version is a lower version number than the latest version, the updater will download and install the new files.
If the autoupdate isn't working or if you would like to install a different version, then you can manually install. First, remove all files except myplex.db (and any other files you might wish to retain) from the hasystem directory. Then, download the latest system_setup.py file and run it from your home directory.
python system_setup.py
Note: When running system_setup.py, you may be prompted for your server, client, and wild card show again.
- system.py - The controller's main script, this runs most functions of the script.
- upddatedb_pi.py - This script manages updates to the database. You must run this script (with arguments) after updating your Plex server library
- system_setup.py - As mentioned above, this is the script that manages the initial setup. It will download and screate files, prompt for Plex server information and populate or update the database.
- piplaystate.py - Uses API access to check the playback state of the client at a regular interval. When play checking is turned on (
playcheckstart
), the script will check playback status and if none is detected, it will issue thestartnextprogram
command, which starts media playback, based on the playback mode the controller is set to. - playstatus.py - Runs in the background. When enabled uses piplaystate.py to get the status of your client.
- getshows.py - Updates database entries for a single specified show.
- tbn_schedule.py - On linux systems, is run once a minute by cron to trigger scheduled TBN-Plex actions.
- add_to_bash.py - On linux systems, updates bash shortcut entries. Needs to be run as sudo, and username specified as an argument.
- add_to_cron.py - On linux systems, updates entries in etc/crontab
These are the various play modes you can set the script to. When play checking is turned on, or the startnextprogram
command is used, the script will play an item according to the mode it's set to. You can check the play mode with getplaymode
and set it with setplaymode
.
- normal - Plays items from the queue. Will find content when the queue is exhausted.
- block.blockname - Plays through the specified block, when it reaches the end of the block, it will drop back into normal mode.
- marathon.show - Plays the specified show until the mode is changed.
- holiday.usercreatedholiday - Plays items from the user created holiday list.
- commercialmode - Plays random items from the commercials table unless user plays something else or changes playmode. Useful to have on to play in between scheduled content
- custom.customsectionname - plays items from a custom.table user added using
upddateddb.py custom.insertablenamehere
.
If the system_setup.py script succeeded in adding commands to your bash shell, and after you have restarted it, you should be able to use the following commands without having python system.py
in front of them. If that failed, or if say you do not use the bash shell, you will need to add python system.py
in front of the following commands. Similarly, if you want to use this script in concert with something like a webserver or voice control agent, you can use python system.py actionshere
to use any one of the following commands.
Note: If the option you are giving contains a space(" ") you will need to put quotes ("" or '') around that option.
2nd Note: Commands that return a list of items, like findmovie
, support the -l
argument. When not included, if more than 30 items are retuned you get a column list of 30 items with longer titles shortened. When more than 30 items are returned and the -l
argument is included, you will get the list in 10s, with no titles shortened.
Command | Description | Syntax Example |
---|---|---|
addapproved |
Adds a title to the approved list. | addapproved Predator |
addblock |
Adds a block. Note: If no block name and item are specified you will be prompted to created a block. | addblock monday_block Deadwood |
addcustomtitle |
Adds a custom title association for an original title | addcustomtitle "Ghostbusters 3" "Ghostbusters(2016)" |
addfavoritemovie |
Adds the favorite genre to the specified movie. | addfavoritemovie Tremors |
addfavoriteshow |
Adds the favorite genre to the specified show. | addfavoriteshow Deadwood |
addgenremovie |
Adds the specified genre to the specified movies genre list. | addgenremovie Deadwood superhero |
addgenreshow |
Adds the specified genre to the specified shows genre list. | addgenreshow deadwood wildwest |
addholiday |
Adds/associates a given title with a holiday | addholiday xmas "die hard" |
addrejected |
Adds a title to the rejected list | addrejected Jaws |
addschedule |
Schedule an action to happen at a specified time. Note: Time must be formatted "HH:MM AM/PM". When using "today" that entry will be removed once executed. When using a day of the week the action will repeat weekly on the specified day/time. | addschedule "setplaymode normal" "11:27 PM" today. |
addschedule |
Adds item to the schedule | addschedule "setplaymode normal" 6:00 PM" today |
addsuggestion |
Adds suggestion to the play queue. | addsuggestion |
addtoblock |
Adds the specified item to the specified block. | addtoblock monday_block Psych |
availableactions |
Lists the actions supported by the system.py file | availableactions -l |
availableblocks |
Lists the available blocks. | availableblocks |
backupmoviedb |
Backs up the movie tables | backupmoviedb |
backuptvcounts |
Backs up the tv count entries | backuptvcounts |
backuptvdb |
Backs up the TV tables | backuptvdb |
blocktoplist |
Convers the given block to a plex playlist | blocktoplist Monday_Block |
changeclient |
Changes the video client to the chosen client.Note: Client list is querryed from server and returned for choise. | changeclient |
changehonorific |
Changes what the server calls you example: sir, lady, bill, etc | changehonorific "My Lord" |
changeplexpw |
Change the plex PW stored by TBN-Plex | changeplexpw blah |
changewildcard |
Changes the current wild card show to the specified show. | changewildcard "my name is earl" |
checkblockrandom |
Lists status of blockrandom mode | checkblockrandom |
checkholidays |
Lists the saved holidays with associations | checkholidays |
collectiondetails |
Gets the movies in the given Collection | collectiondetails "The Die Hard Collection" |
commercialbreak |
Interuppts the current program with a commercial break | commercialbreak |
customtitlecheck |
Checks if the given custom title exists | customtitlecheck "Ghostbusters 3" |
disablecommercials |
Disables Commercials Between Programs | disablecommercials |
disablefavoritesmode |
Disables favorites mode for shows or movies. Note: You must specify either "shows" or "movies" to use this command. | disablefavoritesmode shows |
disablekidsmode |
Disables Kids Mode | disablekidsmode |
enablecommercials |
Enables Commercials Between Programs | enablecommercials |
enablefavoritesmode |
Enables Favorites mode for shows or movies. Note: You must specify either "shows" or "movies" to use this command. | enablefavoritesmode shows |
enablekidsmode |
Enables Kids Mode | enablekidsmode |
epdetails |
Gets the details for the specified show episode. Note: You must specify a show name a season number and an episode number. | epdetails "deadwood" 1 1 |
explainblock |
Explains the specified block. Note: When a block is active you can use this command without specifying a block. | explainblock monday_block |
faqs |
Gets a FAQ for the given movie | faqs "The Matrix" |
findmovie |
Finds movies based on name/rating/genre/actors. | findmovie genre.action |
findnewmovie |
Finds a new random movie Note: used for random movies in blocks. | findnewmovie |
findshow |
Finds shows based on name/rating/genre/duration. | findshow rating.TV-MA |
getalbums |
Lists the albums for the given artist | getalbums "Willie Nelson" |
getallcollections |
Scans your movie library and compares it to themoviedb to find the collections in your library | getallcollections |
getautoupdate |
Gets the current AUTOUPDATE value | getautoupdate |
getcollection |
Gets the Collection associated with a given movie. NOTE: supports "-b" flag to create a smartblock using the results and "-p" to create a smartplaylist on your Plex server | getcollection "Die Hard" -p |
getcustomtable |
Lists stored entries for the given custom table | getcustomtable Fights |
getlikemovie |
Checks themoviedb for similar movies to the given movie. NOTE: supports "-b" flag to create a smartblock using the results | getlikemovie "Lethal Weapon" -b |
getplaymode |
Identifies the current playmode. | getplaymode |
getprintmode |
Gets the PRINTMODE state | getprintmode |
hitok |
Hits OK on onscreen popups | hitok |
idplaymode |
Identifies the current playmode. | idplaymode |
idtonightsmovie |
When in block package mode this command identifies the next random movie. | idtonightsmovie |
jumpinblock |
Jump to a specific place in the active block | jumpinblock 2 |
listclients |
Lists the available clients | listclients |
listcollections |
Lists the Collections found in your library. NOTE: You must do a "getallcollections" before this will return results | listcollections |
listcommercials |
Lists the available Commercials stored in the TBN-Plex DB | listcommercials |
listcustomtables |
Lists the available custom tables in the TBN-Plex db. | listcustomtables |
listepisodes |
Lists the episodes for a specific show. | listepisodes Deadwood |
listmoviegenres |
Lists the movie genres found in your library. | listmoviegenres |
listplexplaylists |
Lists the playlists stored on the Plex Server | listplexplaylists |
listprerolls |
Lists the available Prerolls stored in the TBN-Plex DB | listprerolls |
listwildcard |
Lists the current wild card show | listwildcard |
moviechoice |
Gives a choice of 3 items from the specified genre/rating/actor | moviechoice genre.favorite |
moviedetails |
Gets the details for the specified movie. | moviedetails "The quick and the dead" |
musicstartnext |
Starts the next music track | musicstartnext |
muteaudio |
Mutes audio on your video client. | muteaudio |
mutemusic |
Mutes audio on your music client. | mutemusic |
nextep |
Gets the next episode from the specified show. | nextep Deadwood |
nowplaying |
Lists what is currently playing on your specified video client. | nowplaying |
pausemusic |
Pauses/Resumes Music | pausemusic |
pauseplayback |
Pauses/Resumes Playback on your video client. | pauseplayback |
playchecksleep |
Enables Playback Sleep function. | playchecksleep |
playcheckstart |
Enables Playback State Checking. | playcheckstart |
playcheckstatus |
Checks that status of the play checking script. | playcheckstatus |
playcheckstop |
Disables Playback State Checking. | playcheckstop |
playcommercial |
Plays a specific commercial | playcommercial "rogue one trailer" |
playme |
Play a specific item | playme psych |
playmusic |
Plays the given artist/track | playmusic "Willie Nelson" |
playpending |
Plays the last pending(suggested) item | playpending |
playplaylist |
Plays the given playlist | playplaylist "Half-Nelson" |
playspshow |
Plays a specifiec episode for the given show. Format show season number episode number | playspshow Psych 4 15 |
playwhereleftoff |
Resumes the specified item from where you left off rather than starting it from the beginning. | playwhereleftoff "The quick and the dead" |
queuead |
Adds specified item to the queue. | queueadd 'the matrix' |
queueremove |
Removes the specified item from the play queue. | queueremove "the matrix" |
queueshow |
Lists the contents of the queue. | queueshow |
queuetoplaylist |
Converts the TBN queue to a plex playlist | queuetoplaylist |
randommovieblock |
Generates a random movie block of the specified genre. | randommovieblock action |
randomtvblock |
Generates a random show block of the specified genre. | randomtvblock comedy |
removeblock |
Removes the specified block. | removeblock monday_block |
removecustomtitle |
Removes the given custom title association | removecustomtitle "Ghostbusters 3" |
removefromblock |
Removes the specified item from the specified block. | removefromblock monday_block psych |
removefromholiday |
removes an item from being associated with the given holiday | removefromholiday xmas "die hard" |
removegenremovie |
Removes the specified genre from the specified movies genre list. | removegenremovie Deadpool romance |
removegenreshow |
Removes the specified genre from the specified shows genre list. | removegenreshow Psych crime |
removeschedule |
Removes the scheduled item at the specified day/date and time | removeschedule "7:00AM" sunday |
reorderblock |
Chanage the order of the specified block. | reorderblock monday_block |
replaceshowinblock |
Sets the given title to be replaced in the given block when its epiosde list resets | replaceshowinblock Psych Test1 |
replacestatus |
Lists replaces status for the given title | replacestatus psych |
replacewildcard |
designates the current wild card show to be replaced by the specified show once the current show plays through its episode list. | replacewildcard Psych |
restartblock |
Restarts the specified block from the beginning. Note: can be used without specifying a block when you are a block is active. | restartblock monday_block |
restartshow |
Restarts the given shows episode count to episode 1 | restartshow Psych |
restoremoviedb |
restores the movies tables from backup | restoremoviedb |
restoretvcounts |
Restores the tv count entires.Note: tvcounts must be in your /hasystem directory. | restoretvcounts |
restoretvdb |
Restors the TV tables from backup | restoretvdb |
resumeplay |
Resumes the specified item from where you left off rather than starting it from the beginning. | resumeplay "The quick and the dead" |
resumestatus |
Shows resumestatus state | resumestatus |
seriesskipahead |
Skips ahead to the next episode in the given series. | seriesskipahead Deadwood |
seriesskipback |
Skips back to the previous episode in the given series. | seriesskipback Deadwood |
setautoupdate |
Change the AUTOUPDATE value. This is ON or OFF | setautoupdate ON |
setblockrandom |
Sets blockrandom to on/off | setblockrandom on |
setcommercialbreakcount |
Sets the number of commercils in a commercial break. | setcommercialbreakcount 2 |
setmusicclient |
Changes the current music client | setmusicclient |
setnextep |
Sets the next episode to play from the specified show to the specified season and episode number. | setnextep Deadwood 1 3 |
setplaymode |
Sets playmode to the specified value. | setplaymode monday_block |
setprintmode |
Set PRINTMODE ON or OF | setprintmode ON |
setqueuetoplex |
Enable/Disable the automatic plex playlist feature. | setqueuetoplex on/off |
settonightsmovie |
Sets tonights movie to the specified movie. Note: used for random movie items in blocks. | settongitsmovie "tremors" |
setupnext |
Sets the next item in the queue to the specified item. | setupnext Deadwood |
showapproved |
Lists titlses in the kids mode approved list. | showapproved |
showdetails |
Gets the details for the specified show. | showdetails Psych. |
showrejected |
Lists items in the kids mode rejected list. | showrejected |
skipafterthat |
Skips the second item in the queue. Note: only supports normal mode. | skipafterthat |
skipahead |
Skips ahead in the current feature 30 seconds. | skipahead |
skipback |
Skips back in the current feature 30 seconds. | skipback |
skipthat |
Skips the item up next. Note: Can use "-m" and "-t" flags to restrict next selection to "movies" or "tv shows". | skipthat |
smartplist |
Generates a playlist on your plex server (add "-p" flag) or a holidaymode playlist (no "-p" flag) using the specified words. | smartplist christmas |
startnextprogram |
Starts the next program. | startnextprogram |
statuscheck |
Lists status of various options | statuscheck |
stopmusic |
Stops playback on music client | stopmusic |
stopplayback |
Stops playback on your video client. | stopplayback |
suggestblock |
Suggests a block from the available blocks. | suggestblock |
suggestmovie |
Suggests a movie. Can add "genre.genrehere" or "actor.actorhere" or "rating.ratinghere" to limit your suggestion. | suggestmovie genre.action. |
suggestsomething |
Suggests a random show or movie. | suggestsomething |
suggestsomething |
Suggests a random show or movie | suggestsomething |
suggesttv |
Suggests a show. Can optionally restrict by "genre." or "duration." or "rating.". | suggesttv genre.action |
trivia |
Gets a trivia item for the given movie | trivia "The Matrix" |
triviaanswer |
Shows the Answer to the last trivia question asked | triviaanswer |
triviagame |
Generates a trivia question using a title from your movie library. | triviagame |
triviahint |
Gives a hint for the last Trivia Question asked | triviahint |
triviaquestion |
Shows the Last Trivia Question Asked | triviaquestion |
tvchoice |
Gives a choice of 3 items from the specified genre/rating/duration | tvchoice genre.action |
tvgenres |
Lists available TV genres | tvgenres |
unmuteaudio. |
unmutes audio on your video client. | unmuteaudio |
unmutemusic |
unmutes audio on your music client. | unmutemusic |
updatechecker |
Checks to see if you are running the most recent TBN-Plex files | updatechecker |
updatedb |
Updates the TBN-Plex database. | updatedb shows |
versioncheck |
Lists the version of the system file. | versioncheck |
viewschedules |
Lists the scheduled actions. | viewschedules |
viewschedules |
Lists currently scheduled items. Can use -d for date filter -a for action filter and -t for time | viewschedules |
whatispending |
Lists what is in the pending(previously suggested) queue. | whatispending |
whatsafterthat |
Lists the second item in the queue.Note: Only works in normal mode. | whatsafterthat |
whatupnext |
Lists the item that will play next. Can Optionally add "-q" flag to specify next up in the queue when not in normal mode. | whatupnext |
whereat |
Lists where you are at in the current program. | whereat |
There are 3 .php files and a .jpg that can be used in the event you desire a UI. Drop them in your apache web directory and have at it. Others should be able to easily interact with them and make a custom UI, voice controller, mobile app,... whatever that makes use of them as one sees fit. This should be considered an unsupported feature. No bug/feature requests for UI please.
Schedules not running, and/or playchecking not automatically starting on reboot
Verify you have a single entry for each in your etc/crontab. Also make sure the formatting is correct. They should look like this:
* * * * * pi python /home/pi/hasystem/tbn_schedule.py >/dev/null 2>&1 &
@reboot pi python /home/pi/hasystem/piplaystate.py > /dev/null 2>&1 &