Added logic to remap the main plex libraries in config. Also added logic to get plex token from a file in the parent dir called plex_token.py

This commit is contained in:
Justin Emter
2017-07-22 14:26:48 -07:00
parent 54f7f6535f
commit c5c8c3d2a3
2 changed files with 113 additions and 92 deletions

View File

@@ -7,7 +7,6 @@ from src import Episode
from src import Music from src import Music
from src import Video from src import Video
from src import PseudoDailyScheduleController from src import PseudoDailyScheduleController
from pseudo_config import *
from plexapi.server import PlexServer from plexapi.server import PlexServer
@@ -22,9 +21,11 @@ import xml.etree.ElementTree as ET
from time import sleep from time import sleep
import pseudo_config as config
class PseudoChannel(): class PseudoChannel():
PLEX = PlexServer(baseurl, token) PLEX = PlexServer(config.baseurl, config.token)
MEDIA = [] MEDIA = []
@@ -32,7 +33,7 @@ class PseudoChannel():
self.db = PseudoChannelDatabase("pseudo-channel.db") self.db = PseudoChannelDatabase("pseudo-channel.db")
self.controller = PseudoDailyScheduleController(baseurl, token, plexClients) self.controller = PseudoDailyScheduleController(config.baseurl, config.token, config.plexClients)
"""Database functions. """Database functions.
@@ -76,97 +77,103 @@ class PseudoChannel():
self.db.create_tables() self.db.create_tables()
libs_dict = config.plexLibraries
sections = self.PLEX.library.sections() sections = self.PLEX.library.sections()
for section in sections: for section in sections:
if section.title == "Movies": for correct_lib_name, user_lib_name in libs_dict.items():
sectionMedia = self.PLEX.library.section(section.title).all() if section.title.lower() in [x.lower() for x in user_lib_name]:
for i, media in enumerate(sectionMedia): if correct_lib_name == "Movies":
self.db.add_movies_to_db(1, media.title, media.duration) sectionMedia = self.PLEX.library.section(section.title).all()
self.print_progress( for i, media in enumerate(sectionMedia):
i + 1,
len(sectionMedia),
prefix = 'Progress '+section.title+": ",
suffix = 'Complete',
bar_length = 40
)
self.db.add_movies_to_db(1, media.title, media.duration)
elif section.title == "TV Shows": self.print_progress(
i + 1,
sectionMedia = self.PLEX.library.section(section.title).all() len(sectionMedia),
prefix = 'Progress '+section.title+": ",
for i, media in enumerate(sectionMedia): suffix = 'Complete',
bar_length = 40
backgroundImagePath = self.PLEX.library.section(section.title).get(media.title)
backgroundImgURL = ''
if isinstance(backgroundImagePath.art, str):
backgroundImgURL = baseurl+backgroundImagePath.art+"?X-Plex-Token="+token
self.db.add_shows_to_db(2, media.title, media.duration, '', backgroundImgURL)
self.print_progress(
i + 1,
len(sectionMedia),
prefix = 'Progress '+section.title+": ",
suffix = 'Complete',
bar_length = 40
)
#add all episodes of each tv show to episodes table
episodes = self.PLEX.library.section(section.title).get(media.title).episodes()
for episode in episodes:
duration = episode.duration
if duration:
self.db.add_episodes_to_db(
4,
episode.title,
duration,
episode.index,
episode.parentIndex,
media.title
) )
else:
self.db.add_episodes_to_db( elif correct_lib_name == "TV Shows":
4,
episode.title, sectionMedia = self.PLEX.library.section(section.title).all()
0,
episode.index, for i, media in enumerate(sectionMedia):
episode.parentIndex,
media.title backgroundImagePath = self.PLEX.library.section(section.title).get(media.title)
backgroundImgURL = ''
if isinstance(backgroundImagePath.art, str):
backgroundImgURL = config.baseurl+backgroundImagePath.art+"?X-Plex-Token="+config.token
self.db.add_shows_to_db(2, media.title, media.duration, '', backgroundImgURL)
self.print_progress(
i + 1,
len(sectionMedia),
prefix = 'Progress '+section.title+": ",
suffix = 'Complete',
bar_length = 40
) )
elif section.title == "Commercials": #add all episodes of each tv show to episodes table
episodes = self.PLEX.library.section(section.title).get(media.title).episodes()
sectionMedia = self.PLEX.library.section(section.title).all() for episode in episodes:
media_length = len(sectionMedia) duration = episode.duration
for i, media in enumerate(sectionMedia): if duration:
self.db.add_commercials_to_db(3, media.title, media.duration) self.db.add_episodes_to_db(
4,
episode.title,
duration,
episode.index,
episode.parentIndex,
media.title
)
self.print_progress( else:
i + 1,
media_length, self.db.add_episodes_to_db(
prefix = 'Progress '+section.title+":", 4,
suffix = 'Complete', episode.title,
bar_length = 40 0,
) episode.index,
episode.parentIndex,
media.title
)
elif correct_lib_name == "Commercials":
sectionMedia = self.PLEX.library.section(section.title).all()
media_length = len(sectionMedia)
for i, media in enumerate(sectionMedia):
self.db.add_commercials_to_db(3, media.title, media.duration)
self.print_progress(
i + 1,
media_length,
prefix = 'Progress '+section.title+":",
suffix = 'Complete',
bar_length = 40
)
def update_schedule(self): def update_schedule(self):

View File

@@ -1,7 +1,32 @@
#!/usr/bin/python #!/usr/bin/python
"""
1) Create a file outside of this proj dir called "plex_token.py":
touch ../plex_token.py
2) add this line to the newly created file:
token = 'your plex token'
3) Edit the "basurl" variable below to point to your Plex server
4) Edit the "plexClients" variable to include the name of your plex client(s) this app will control.
5) Edit the "plexLibraries" variable to remap your specific library names to the app specific names.
...for instance, if your Plex "Movies" are located in your Plex library as "Films", update that
line so it looks like:
"Movies" : ["Films"],
"""
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# import ../plex_token.py
import plex_token as plex_token
baseurl = 'http://media.home:32400' baseurl = 'http://media.home:32400'
token = 'token' token = plex_token.token
''' '''
* *
@@ -10,20 +35,9 @@ token = 'token'
''' '''
plexClients = ['RasPlex'] plexClients = ['RasPlex']
''' plexLibraries = {
* "TV Shows" : ["TV Shows"],
* The increment value between scheduled shows. Let's say you want to reposition all shows to have a clean start time divisable by 15 (i.e. 12:30 or 12:45). Use the value "-1" to disregard. "Movies" : ["Movies"],
* "Music" : ["Music"],
* "Commercials" : ["Commercials"],
''' }
timeGap = 15
timeBetweenShows = -1
'''
*
* If there is an overlap, then the overlapGap var in config will determine the next increment. If it is set to "15", then the show will will bump up to the next 15 minute interval past the hour. If it is set to 30, then it will find the next 30 minute interval past the hour to place the episode. Useful for keeping clean schedules.
*
'''
overlapGap = 15