diff --git a/Commercial.py b/Commercial.py deleted file mode 100644 index e6cc911..0000000 --- a/Commercial.py +++ /dev/null @@ -1,8 +0,0 @@ - -import Media - -def Commericial(Media): - - def __init__(self, sectionType, title, naturalStartTime, naturalEndTime, duration, dayOfWeek): - - super().__init__(self, sectionType, title, naturalStartTime, naturalEndTime, duration, dayOfWeek) diff --git a/Episode.py b/Episode.py deleted file mode 100644 index ca8e076..0000000 --- a/Episode.py +++ /dev/null @@ -1,12 +0,0 @@ - -import Media - -def Episode(Media): - - def __init__(self, sectionType, title, naturalStartTime, naturalEndTime, duration, dayOfWeek, showSeriesTitle, episodeNumnber, seriesNumber): - - super().__init__(self, sectionType, title, naturalStartTime, naturalEndTime, duration, dayOfWeek) - - self.showSeriesTitle = showSeriesTitle - self.episodeNumnber = episodeNumnber - self.seriesNumber = seriesNumber diff --git a/Media.py b/Media.py deleted file mode 100644 index 7d4ebc7..0000000 --- a/Media.py +++ /dev/null @@ -1,13 +0,0 @@ - - -def Media(): - - def __init__(self, sectionType, title, naturalStartTime, naturalEndTime, duration, dayOfWeek): - - self.sectionType = sectionType - self.title = title - self.naturalStartTime = naturalStartTime - self.naturalEndTime = naturalEndTime - self.duration = duration - self.dayOfWeek = dayOfWeek - diff --git a/Movie.py b/Movie.py deleted file mode 100644 index 16f1a40..0000000 --- a/Movie.py +++ /dev/null @@ -1,8 +0,0 @@ - -import Media - -def Movie(Media): - - def __init__(self, sectionType, title, naturalStartTime, naturalEndTime, duration, dayOfWeek): - - super().__init__(self, sectionType, title, naturalStartTime, naturalEndTime, duration, dayOfWeek) diff --git a/PseudoChannel.py b/PseudoChannel.py new file mode 100644 index 0000000..4154c89 --- /dev/null +++ b/PseudoChannel.py @@ -0,0 +1,309 @@ +from src import PseudoChannelDatabase +from src import Movie +from src import Commercial +from src import Episode +from src import Music +from src import Video +from pseudo_config import * + +from plexapi.server import PlexServer + +import datetime +from xml.dom import minidom +import xml.etree.ElementTree as ET + +class PseudoChannel(): + + PLEX = PlexServer(baseurl, token) + + MEDIA = [] + + def __init__(self): + + self.db = PseudoChannelDatabase("pseudo-channel.db") + + """Database functions. + + update_db(): Grab the media from the Plex DB and store it in the local pseudo-channel.db. + + drop_db(): Drop the local database. Fresh start. + + update_schedule(): Update schedule with user defined times. + + drop_schedule(): Drop the user defined schedule table. + + generate_daily_schedule(): Generates daily schedule based on the "schedule" table. + """ + + def update_db(self): + + print("Updating Local Database") + + self.db.create_tables() + + sections = self.PLEX.library.sections() + + for section in sections: + + if section.title == "Movies": + + sectionMedia = self.PLEX.library.section(section.title).all() + + for media in 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 media in 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) + + #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(4, episode.title, 0, episode.index, episode.parentIndex, media.title) + + elif section.title == "Commercials": + + sectionMedia = self.PLEX.library.section(section.title).all() + + for media in sectionMedia: + + self.db.add_commercials_to_db(3, media.title, media.duration) + + def update_schedule(self): + + scheduled_days_list = [ + "mondays", + "tuesdays", + "wednesdays", + "thursdays", + "fridays", + "saturdays", + "sundays", + "weekdays", + "weekends", + "everyday" + ] + + section_dict = { + "TV Shows" : ["series", "shows", "tv", "episodes", "tv shows"], + "Movies" : ["movie", "movies", "films", "film"], + "Videos" : ["video", "videos", "vid"], + "Music" : ["music", "songs", "song", "tune", "tunes"] + } + + tree = ET.parse('pseudo_schedule.xml') + + root = tree.getroot() + + for child in root: + + if child.tag in scheduled_days_list: + + print child.find( "time" ) + + for time in child.iter("time"): + + for key, value in section_dict.items(): + + if time.attrib['type'] == key or time.attrib['type'] in value: + + print time.tag, time.text, time.attrib['title'] + + title = time.attrib['title'] + + natural_start_time = time.text + + section = key + + strict_time = time.attrib['strict-time'] + + def drop_db(self): + + self.db.drop_db() + + def drop_schedule(self): + + self.db.drop_schedule() + + def remove_all_scheduled_items(): + + self.db.remove_all_scheduled_items() + + + + """App functions. + + generate_daily_schedule(): Generate the daily_schedule table. + """ + + ''' + * + * Using datetime to figure out when the media item will end based on the scheduled start time or the offset + * generated by the previous media item. + + * Returns time + * + ''' + def get_end_time_from_duration(self, startTime, duration): + + time = datetime.datetime.strptime(startTime, '%I:%M %p') + + show_time_plus_duration = time + datetime.timedelta(milliseconds=duration) + + #print(show_time_plus_duration.minute) + + return show_time_plus_duration + + def generate_daily_schedule(self): + + print("Generating Daily Schedule") + + schedule = self.db.get_schedule() + + for entry in schedule: + + section = entry[9] + + if section == "TV Shows": + + next_episode = self.db.get_next_episode(entry[3]) + + if next_episode != None: + + episode = Episode( + section, # section_type + next_episode[3], # title + entry[5], # natural_start_time + self.get_end_time_from_duration(entry[5], next_episode[4]), # natural_end_time + next_episode[4], # duration + entry[7], # day_of_week + False, # is_strict_time + entry[3], # show_series_title + next_episode[5], # episode_number + next_episode[6] # season_number + ) + + else: + + print("Cannot find TV Show Episode, {} in the local db".format(entry[3])) + + #print(episode) + + self.MEDIA.append(episode) + + elif section == "Movies": + + the_movie = self.db.get_movie(entry[3]) + + if the_movie != None: + + movie = Movie( + section, # section_type + the_movie[3], # title + entry[5], # natural_start_time + self.get_end_time_from_duration(entry[5], the_movie[4]), # natural_end_time + the_movie[4], # duration + entry[7], # day_of_week + False, # is_strict_time + ) + + #print(movie.natural_end_time) + + self.MEDIA.append(movie) + + else: + + print("Cannot find Movie, {} in the local db".format(entry[3])) + + elif section == "Music": + + the_music = self.db.get_music(entry[3]) + + if the_music != None: + + music = Music( + section, # section_type + the_music[3], # title + entry[5], # natural_start_time + self.get_end_time_from_duration(entry[5], the_music[4]), # natural_end_time + the_music[4], # duration + entry[7], # day_of_week + False, # is_strict_time + ) + + #print(music.natural_end_time) + + self.MEDIA.append(music) + + else: + + print("Cannot find Music, {} in the local db".format(entry[3])) + + elif section == "Video": + + the_video = self.db.get_video(entry[3]) + + if the_music != None: + + video = Video( + section, # section_type + the_video[3], # title + entry[5], # natural_start_time + self.get_end_time_from_duration(entry[5], the_video[4]), # natural_end_time + the_video[4], # duration + entry[7], # day_of_week + False, # is_strict_time + ) + + #print(music.natural_end_time) + + self.MEDIA.append(video) + + else: + + print("Cannot find Video, {} in the local db".format(entry[3])) + + else: + + pass + +if __name__ == '__main__': + + pseudo_channel = PseudoChannel() + + pseudo_channel.update_schedule() + + #pseudo_channel.generate_daily_schedule() + + """for item in pseudo_channel.MEDIA: + + if item.day_of_week == "saturdays": + + print(item.title)""" + #pass + + #pseudo_channel.update_db() + diff --git a/PseudoChannel.pyc b/PseudoChannel.pyc new file mode 100644 index 0000000..59fb126 Binary files /dev/null and b/PseudoChannel.pyc differ diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..7e72c80 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +from PseudoChannel import PseudoChannel \ No newline at end of file diff --git a/pseudo_channel.py b/old/pseudo_channel.py similarity index 100% rename from pseudo_channel.py rename to old/pseudo_channel.py diff --git a/pseudo_commercial_injection.py b/old/pseudo_commercial_injection.py similarity index 100% rename from pseudo_commercial_injection.py rename to old/pseudo_commercial_injection.py diff --git a/pseudo_config-sample.py b/old/pseudo_config-sample.py similarity index 100% rename from pseudo_config-sample.py rename to old/pseudo_config-sample.py diff --git a/pseudo_generate_daily_scheduledb.py b/old/pseudo_generate_daily_scheduledb.py similarity index 100% rename from pseudo_generate_daily_scheduledb.py rename to old/pseudo_generate_daily_scheduledb.py diff --git a/pseudo_tv_controller.py b/old/pseudo_tv_controller.py similarity index 100% rename from pseudo_tv_controller.py rename to old/pseudo_tv_controller.py diff --git a/pseudo_updatedb.py b/old/pseudo_updatedb.py similarity index 100% rename from pseudo_updatedb.py rename to old/pseudo_updatedb.py diff --git a/schedule.sh b/old/schedule.sh similarity index 100% rename from schedule.sh rename to old/schedule.sh diff --git a/pseudo-channel.db b/pseudo-channel.db new file mode 100644 index 0000000..b92bbbf Binary files /dev/null and b/pseudo-channel.db differ diff --git a/pseudo_schedule.xml b/pseudo_schedule.xml new file mode 100644 index 0000000..eb223c2 --- /dev/null +++ b/pseudo_schedule.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Commercial.py b/src/Commercial.py new file mode 100644 index 0000000..b681f27 --- /dev/null +++ b/src/Commercial.py @@ -0,0 +1,36 @@ +from Media import Media + +class Commercial(Media): + + """Inherits Media. + + Attributes: + section_type: The type of library this is (i.e. "TV Shows") + title: The title of the media item + natural_start_time: The scheduled start time before any shifting happens. + natural_end_time: The end time of the scheduled content. + duration: The duration of the media item. + day_of_week: When the content is scheduled to play + is_strict_time: If strict time, then anchor to "natural_start_time" + """ + + def __init__( + self, + section_type, + title, + natural_start_time, + natural_end_time, + duration, + day_of_week, + is_strict_time + ): + + super(Commercial, self).__init__( + section_type, + title, + natural_start_time, + natural_end_time, + duration, + day_of_week, + is_strict_time + ) diff --git a/src/Commercial.pyc b/src/Commercial.pyc new file mode 100644 index 0000000..b0a6816 Binary files /dev/null and b/src/Commercial.pyc differ diff --git a/src/Episode.py b/src/Episode.py new file mode 100644 index 0000000..2bffa60 --- /dev/null +++ b/src/Episode.py @@ -0,0 +1,46 @@ +from Media import Media + +class Episode(Media): + + """Inherits Media. + + Attributes: + section_type: The type of library this is (i.e. "TV Shows") + title: The title of the media item + natural_start_time: The scheduled start time before any shifting happens. + natural_end_time: The end time of the scheduled content. + duration: The duration of the media item. + day_of_week: When the content is scheduled to play + is_strict_time: If strict time, then anchor to "natural_start_time" + show_series_title: The series title (i.e. "Friends") + episode_number: The episode number in the Season + season_number: The number of season in the series. + """ + + def __init__( + self, + section_type, + title, + natural_start_time, + natural_end_time, + duration, + day_of_week, + is_strict_time, + show_series_title, + episode_number, + season_number + ): + + super(Episode, self).__init__( + section_type, + title, + natural_start_time, + natural_end_time, + duration, + day_of_week, + is_strict_time + ) + + self.show_series_title = show_series_title + self.episode_number = episode_number + self.season_number = season_number diff --git a/src/Episode.pyc b/src/Episode.pyc new file mode 100644 index 0000000..aae3406 Binary files /dev/null and b/src/Episode.pyc differ diff --git a/src/Media.py b/src/Media.py new file mode 100644 index 0000000..2cffa53 --- /dev/null +++ b/src/Media.py @@ -0,0 +1,43 @@ +""" +*** Inherited by Commercial, Episode & Movie +""" +class Media(object): + + plex_server_url = '' + plex_server_token = '' + media_image = '' + + """A base class for media objects. + + Attributes: + section_type: The type of library this is (i.e. "TV Shows") + title: The title of the media item + natural_start_time: The scheduled start time before any shifting happens. + natural_end_time: The end time of the scheduled content. + duration: The duration of the media item. + day_of_week: When the content is scheduled to play + is_strict_time: If strict time, then anchor to "natural_start_time" + """ + + def __init__( + self, + section_type, + title, + natural_start_time, + natural_end_time, + duration, + day_of_week, + is_strict_time + ): + + self.section_type = section_type + self.title = title + self.natural_start_time = natural_start_time + self.natural_end_time = natural_end_time + self.duration = duration + self.day_of_week = day_of_week + self.is_strict_time = is_strict_time + + self.start_time = natural_start_time + self.end_time = natural_end_time + diff --git a/src/Media.pyc b/src/Media.pyc new file mode 100644 index 0000000..07dd7cd Binary files /dev/null and b/src/Media.pyc differ diff --git a/src/Movie.py b/src/Movie.py new file mode 100644 index 0000000..ce2c649 --- /dev/null +++ b/src/Movie.py @@ -0,0 +1,36 @@ +from Media import Media + +class Movie(Media): + + """Inherits Media. + + Attributes: + section_type: The type of library this is (i.e. "TV Shows") + title: The title of the media item + natural_start_time: The scheduled start time before any shifting happens. + natural_end_time: The end time of the scheduled content. + duration: The duration of the media item. + day_of_week: When the content is scheduled to play + is_strict_time: If strict time, then anchor to "natural_start_time" + """ + + def __init__( + self, + section_type, + title, + natural_start_time, + natural_end_time, + duration, + day_of_week, + is_strict_time + ): + + super(Movie, self).__init__( + section_type, + title, + natural_start_time, + natural_end_time, + duration, + day_of_week, + is_strict_time + ) diff --git a/src/Movie.pyc b/src/Movie.pyc new file mode 100644 index 0000000..e6655ca Binary files /dev/null and b/src/Movie.pyc differ diff --git a/src/Music.py b/src/Music.py new file mode 100644 index 0000000..a968858 --- /dev/null +++ b/src/Music.py @@ -0,0 +1,36 @@ +from Media import Media + +class Music(Media): + + """Inherits Media. + + Attributes: + section_type: The type of library this is (i.e. "TV Shows") + title: The title of the media item + natural_start_time: The scheduled start time before any shifting happens. + natural_end_time: The end time of the scheduled content. + duration: The duration of the media item. + day_of_week: When the content is scheduled to play + is_strict_time: If strict time, then anchor to "natural_start_time" + """ + + def __init__( + self, + section_type, + title, + natural_start_time, + natural_end_time, + duration, + day_of_week, + is_strict_time + ): + + super(Music, self).__init__( + section_type, + title, + natural_start_time, + natural_end_time, + duration, + day_of_week, + is_strict_time + ) diff --git a/src/Music.pyc b/src/Music.pyc new file mode 100644 index 0000000..b4308c6 Binary files /dev/null and b/src/Music.pyc differ diff --git a/src/PseudoChannelDatabase.py b/src/PseudoChannelDatabase.py new file mode 100644 index 0000000..352ac83 --- /dev/null +++ b/src/PseudoChannelDatabase.py @@ -0,0 +1,417 @@ +import sqlite3 +import datetime +import time + +class PseudoChannelDatabase(): + + def __init__(self, db): + + self.db = db + + self.conn = sqlite3.connect(self.db) + + self.cursor = self.conn.cursor() + + """Database functions. + + Utilities, etc. + """ + + def create_tables(self): + + self.cursor.execute('CREATE TABLE IF NOT EXISTS ' + 'movies(id INTEGER PRIMARY KEY AUTOINCREMENT, ' + 'unix INTEGER, mediaID INTEGER, title TEXT, duration INTEGER)') + + self.cursor.execute('CREATE TABLE IF NOT EXISTS ' + 'videos(id INTEGER PRIMARY KEY AUTOINCREMENT, ' + 'unix INTEGER, mediaID INTEGER, title TEXT, duration INTEGER)') + + self.cursor.execute('CREATE TABLE IF NOT EXISTS ' + 'music(id INTEGER PRIMARY KEY AUTOINCREMENT, ' + 'unix INTEGER, mediaID INTEGER, title TEXT, duration INTEGER)') + + self.cursor.execute('CREATE TABLE IF NOT EXISTS ' + 'shows(id INTEGER PRIMARY KEY AUTOINCREMENT, ' + 'unix INTEGER, mediaID INTEGER, title TEXT, duration INTEGER, ' + 'lastEpisodeTitle TEXT, fullImageURL TEXT)') + + self.cursor.execute('CREATE TABLE IF NOT EXISTS ' + 'episodes(id INTEGER PRIMARY KEY AUTOINCREMENT, ' + 'unix INTEGER, mediaID INTEGER, title TEXT, duration INTEGER, ' + 'episodeNumber INTEGER, seasonNumber INTEGER, showTitle TEXT)') + + self.cursor.execute('CREATE TABLE IF NOT EXISTS ' + 'commercials(id INTEGER PRIMARY KEY AUTOINCREMENT, unix INTEGER, ' + 'mediaID INTEGER, title TEXT, duration INTEGER)') + + self.cursor.execute('CREATE TABLE IF NOT EXISTS ' + 'schedule(id INTEGER PRIMARY KEY AUTOINCREMENT, unix INTEGER, ' + 'mediaID INTEGER, title TEXT, duration INTEGER, startTime INTEGER, ' + 'endTime INTEGER, dayOfWeek TEXT, startTimeUnix INTEGER), section TEXT)') + + self.cursor.execute('CREATE TABLE IF NOT EXISTS ' + 'daily_schedule(id INTEGER PRIMARY KEY AUTOINCREMENT, unix INTEGER, ' + 'mediaID INTEGER, title TEXT, episodeNumber INTEGER, seasonNumber INTEGER, ' + 'showTitle TEXT, duration INTEGER, startTime INTEGER, endTime INTEGER, dayOfWeek TEXT)') + + self.cursor.execute('CREATE TABLE IF NOT EXISTS ' + 'app_settings(id INTEGER PRIMARY KEY AUTOINCREMENT, version TEXT') + + #index + self.cursor.execute('CREATE UNIQUE INDEX IF NOT EXISTS idx_episode_title ON episodes (title);') + + self.cursor.execute('CREATE UNIQUE INDEX IF NOT EXISTS idx_movie_title ON movies (title);') + + self.cursor.execute('CREATE UNIQUE INDEX IF NOT EXISTS idx_movie_title ON videos (title);') + + self.cursor.execute('CREATE UNIQUE INDEX IF NOT EXISTS idx_music_title ON music (title);') + + self.cursor.execute('CREATE UNIQUE INDEX IF NOT EXISTS idx_commercial_title ON commercials (title);') + + """Setting Basic Settings + + """ + try: + self.cursor.execute("INSERT OR REPLACE INTO app_settings " + "(version) VALUES (?)", + ("0.1")) + + self.conn.commit() + # Catch the exception + except Exception as e: + # Roll back any change if something goes wrong + self.conn.rollback() + raise e + + def drop_db(self): + + pass + + def drop_schedule(self): + + pass + + def remove_all_scheduled_items(): + + sql = "DELETE FROM schedule WHERE id > -1" + + self.cursor.execute(sql) + + self.conn.commit() + + self.cursor.close() + + self.conn.close() + + """Database functions. + + Setters, etc. + """ + + def add_movies_to_db(self, mediaID, title, duration): + unix = int(time.time()) + try: + self.cursor.execute("INSERT OR REPLACE INTO movies " + "(unix, mediaID, title, duration) VALUES (?, ?, ?, ?)", + (unix, mediaID, title, duration)) + + self.conn.commit() + # Catch the exception + except Exception as e: + # Roll back any change if something goes wrong + self.conn.rollback() + raise e + + def add_videos_to_db(self, mediaID, title, duration): + unix = int(time.time()) + try: + self.cursor.execute("INSERT OR REPLACE INTO videos " + "(unix, mediaID, title, duration) VALUES (?, ?, ?, ?)", + (unix, mediaID, title, duration)) + + self.conn.commit() + # Catch the exception + except Exception as e: + # Roll back any change if something goes wrong + self.conn.rollback() + raise e + + def add_shows_to_db(self, mediaID, title, duration, lastEpisodeTitle, fullImageURL): + unix = int(time.time()) + try: + self.cursor.execute("INSERT OR REPLACE INTO shows " + "(unix, mediaID, title, duration, lastEpisodeTitle, fullImageURL) VALUES (?, ?, ?, ?, ?, ?)", + (unix, mediaID, title, duration, lastEpisodeTitle, fullImageURL)) + self.conn.commit() + # Catch the exception + except Exception as e: + # Roll back any change if something goes wrong + self.conn.rollback() + raise e + + def add_episodes_to_db(self, mediaID, title, duration, episodeNumber, seasonNumber, showTitle): + unix = int(time.time()) + try: + self.cursor.execute("INSERT OR REPLACE INTO episodes " + "(unix, mediaID, title, duration, episodeNumber, seasonNumber, showTitle) VALUES (?, ?, ?, ?, ?, ?, ?)", + (unix, mediaID, title, duration, episodeNumber, seasonNumber, showTitle)) + self.conn.commit() + # Catch the exception + except Exception as e: + # Roll back any change if something goes wrong + self.conn.rollback() + raise e + + def add_commercials_to_db(self, mediaID, title, duration): + unix = int(time.time()) + try: + self.cursor.execute("INSERT OR REPLACE INTO commercials " + "(unix, mediaID, title, duration) VALUES (?, ?, ?, ?)", + (unix, mediaID, title, duration)) + self.conn.commit() + # Catch the exception + except Exception as e: + # Roll back any change if something goes wrong + self.conn.rollback() + raise e + + def add_schedule_to_db(self, mediaID, title, duration, startTime, endTime, dayOfWeek, section): + unix = int(time.time()) + try: + self.cursor.execute("INSERT INTO schedule " + "(unix, mediaID, title, duration, startTime, endTime, dayOfWeek) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", + (unix, mediaID, title, duration, startTime, endTime, dayOfWeek, section)) + self.conn.commit() + # Catch the exception + except Exception as e: + # Roll back any change if something goes wrong + self.conn.rollback() + raise e + + def add_daily_schedule_to_db(self, mediaID, title, duration, startTime, endTime, dayOfWeek): + unix = int(time.time()) + startTimeUnix = str(datetime.datetime.strptime(startTime, '%I:%M %p')) + try: + + self.cursor.execute("INSERT OR REPLACE INTO schedule " + "(unix, mediaID, title, duration, startTime, endTime, dayOfWeek, startTimeUnix) " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?)", + (unix, mediaID, title, duration, startTime, endTime, dayOfWeek, startTimeUnix)) + self.conn.commit() + self.cursor.close() + self.conn.close() + # Catch the exception + except Exception as e: + # Roll back any change if something goes wrong + self.conn.rollback() + self.cursor.close() + self.conn.close() + raise e + + + """Database functions. + + Getters, etc. + """ + def get_media(self, title, mediaType): + + media = mediaType + + sql = "SELECT * FROM "+media+" WHERE (title LIKE ?) COLLATE NOCASE" + self.cursor.execute(sql, ("%"+title+"%", )) + media_item = self.cursor.fetchone() + + return media_item + + def get_schedule(self): + + self.cursor.execute("SELECT * FROM schedule ORDER BY datetime(startTimeUnix) ASC") + + datalist = list(self.cursor.fetchall()) + + return datalist + + def get_daily_schedule(self): + + return None + + def get_movie(self, title): + + media = "movies" + + return self.get_media(title, media) + + def get_shows(self, title): + + media = "shows" + + return self.get_media(title, media) + + def get_music(self, title): + + media = "music" + + return self.get_media(title, media) + + def get_video(self, title): + + media = "videos" + + return self.get_media(title, media) + + def get_episodes(self, title): + + media = "episodes" + + return self.get_media(title, media) + + def update_shows_table_with_last_episode(self, showTitle, lastEpisodeTitle): + + sql1 = "UPDATE shows SET lastEpisodeTitle = ? WHERE title = ?" + + self.cursor.execute(sql1, (lastEpisodeTitle, showTitle, )) + + self.conn.commit() + + def get_first_episode(self, tvshow): + + sql = ("SELECT id, unix, mediaID, title, duration, MIN(episodeNumber), MIN(seasonNumber), " + "showTitle FROM episodes WHERE ( showTitle = ?) COLLATE NOCASE") + + self.cursor.execute(sql, (tvshow, )) + + datalist = list(self.cursor.fetchone()) + + if datalist > 0: + + return datalist + + else: + + print("No entry found in DB to add to schedule.") + + return None + + ''' + * + * When incrementing episodes in a series I am advancing by "id" + * + ''' + def get_episode_id(self, episodeTitle): + + sql = "SELECT id FROM episodes WHERE ( title = ?) COLLATE NOCASE" + + self.cursor.execute(sql, (episodeTitle, )) + + datalist = list(self.cursor.fetchone()) + + if datalist > 0: + + return datalist[0] + + else: + + print("No entry found in DB to add to schedule.") + + return None + + def get_next_episode(self, series): + + #print(series) + ''' + * + * As a way of storing a "queue", I am storing the *next episode title in the "shows" table so I can + * determine what has been previously scheduled for each show + * + ''' + self.cursor.execute("SELECT lastEpisodeTitle FROM shows WHERE title = ?", (series, )) + + last_title_list = list(self.cursor.fetchone()) + ''' + * + * If the last episode stored in the "shows" table is empty, then this is probably a first run... + * + ''' + if last_title_list[0] == '': + + ''' + * + * Find the first episode of the series + * + ''' + first_episode = self.get_first_episode(series) + + first_episode_title = first_episode[3] + + #print(first_episode_title) + ''' + * + * Add this episdoe title to the "shows" table for the queue functionality to work + * + ''' + self.update_shows_table_with_last_episode(series, first_episode_title) + + return first_episode + + else: + ''' + * + * The last episode stored in the "shows" table was not empty... get the next episode in the series + * + ''' + #print("First episode already set in shows, advancing episodes forward") + + #print(str(self.get_episode_id(last_title_list[0]))) + + """ + * + * If this isn't a first run, then grabbing the next episode by incrementing id + * + """ + sql = ("SELECT * FROM episodes WHERE ( id > " + +str(self.get_episode_id(last_title_list[0]))+ + " AND showTitle LIKE ? ) ORDER BY seasonNumber LIMIT 1 COLLATE NOCASE") + + self.cursor.execute(sql, (series, )) + ''' + * + * Try and advance to the next episode in the series, if it returns None then that means it reached the end... + * + ''' + next_episode = self.cursor.fetchone() + + if next_episode != None: + + #print(next_episode[3]) + + self.update_shows_table_with_last_episode(series, next_episode[3]) + + return next_episode + + else: + + print("Not grabbing next episode restarting series, series must be over. Restarting from episode 1.") + + first_episode = self.get_first_episode(series) + + self.update_shows_table_with_last_episode(series, first_episode[3]) + + return first_episode + + def get_commercials(self, title): + + media = "commercials" + + sql = "SELECT * FROM "+media+" WHERE (title LIKE ?) COLLATE NOCASE" + self.cursor.execute(sql, (title, )) + datalist = list(self.cursor.fetchone()) + if datalist > 0: + print(datalist) + + return datalist + + else: + + return None + diff --git a/src/PseudoChannelDatabase.pyc b/src/PseudoChannelDatabase.pyc new file mode 100644 index 0000000..0986043 Binary files /dev/null and b/src/PseudoChannelDatabase.pyc differ diff --git a/src/PseudoDatabase.pyc b/src/PseudoDatabase.pyc new file mode 100644 index 0000000..4150a91 Binary files /dev/null and b/src/PseudoDatabase.pyc differ diff --git a/src/Video.py b/src/Video.py new file mode 100644 index 0000000..d938528 --- /dev/null +++ b/src/Video.py @@ -0,0 +1,36 @@ +from Media import Media + +class Video(Media): + + """Inherits Media. + + Attributes: + section_type: The type of library this is (i.e. "TV Shows") + title: The title of the media item + natural_start_time: The scheduled start time before any shifting happens. + natural_end_time: The end time of the scheduled content. + duration: The duration of the media item. + day_of_week: When the content is scheduled to play + is_strict_time: If strict time, then anchor to "natural_start_time" + """ + + def __init__( + self, + section_type, + title, + natural_start_time, + natural_end_time, + duration, + day_of_week, + is_strict_time + ): + + super(Video, self).__init__( + section_type, + title, + natural_start_time, + natural_end_time, + duration, + day_of_week, + is_strict_time + ) diff --git a/src/Video.pyc b/src/Video.pyc new file mode 100644 index 0000000..a9a21a4 Binary files /dev/null and b/src/Video.pyc differ diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..0c3e84b --- /dev/null +++ b/src/__init__.py @@ -0,0 +1,7 @@ +from PseudoChannelDatabase import PseudoChannelDatabase +from Commercial import Commercial +from Episode import Episode +from Movie import Movie +from Media import Media +from Music import Music +from Video import Video \ No newline at end of file diff --git a/src/__init__.pyc b/src/__init__.pyc new file mode 100644 index 0000000..700179f Binary files /dev/null and b/src/__init__.pyc differ