diff --git a/PseudoChannel.py b/PseudoChannel.py index eb362fa..e1e2e01 100644 --- a/PseudoChannel.py +++ b/PseudoChannel.py @@ -7,7 +7,6 @@ from src import Episode from src import Music from src import Video from src import PseudoDailyScheduleController -from pseudo_config import * from plexapi.server import PlexServer @@ -22,9 +21,11 @@ import xml.etree.ElementTree as ET from time import sleep +import pseudo_config as config + class PseudoChannel(): - PLEX = PlexServer(baseurl, token) + PLEX = PlexServer(config.baseurl, config.token) MEDIA = [] @@ -32,7 +33,7 @@ class PseudoChannel(): self.db = PseudoChannelDatabase("pseudo-channel.db") - self.controller = PseudoDailyScheduleController(baseurl, token, plexClients) + self.controller = PseudoDailyScheduleController(config.baseurl, config.token, config.plexClients) """Database functions. @@ -76,97 +77,103 @@ class PseudoChannel(): self.db.create_tables() + libs_dict = config.plexLibraries + sections = self.PLEX.library.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( - i + 1, - len(sectionMedia), - prefix = 'Progress '+section.title+": ", - suffix = 'Complete', - bar_length = 40 - ) + for i, media in enumerate(sectionMedia): + self.db.add_movies_to_db(1, media.title, media.duration) - elif section.title == "TV Shows": - - sectionMedia = self.PLEX.library.section(section.title).all() - - for i, media in enumerate(sectionMedia): - - 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 + self.print_progress( + i + 1, + len(sectionMedia), + prefix = 'Progress '+section.title+": ", + suffix = 'Complete', + bar_length = 40 ) - else: - self.db.add_episodes_to_db( - 4, - episode.title, - 0, - episode.index, - episode.parentIndex, - media.title + elif correct_lib_name == "TV Shows": + + sectionMedia = self.PLEX.library.section(section.title).all() + + for i, media in enumerate(sectionMedia): + + 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( - i + 1, - media_length, - prefix = 'Progress '+section.title+":", - suffix = 'Complete', - bar_length = 40 - ) + else: + + self.db.add_episodes_to_db( + 4, + episode.title, + 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): diff --git a/pseudo_config.py b/pseudo_config.py index 3e6ec53..bd79793 100644 --- a/pseudo_config.py +++ b/pseudo_config.py @@ -1,7 +1,32 @@ #!/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' -token = 'token' +token = plex_token.token ''' * @@ -10,20 +35,9 @@ token = 'token' ''' plexClients = ['RasPlex'] -''' -* -* 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. -* -* -''' -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 +plexLibraries = { + "TV Shows" : ["TV Shows"], + "Movies" : ["Movies"], + "Music" : ["Music"], + "Commercials" : ["Commercials"], +}