Updating project to oop.

This commit is contained in:
Justin Emter
2017-07-20 00:05:35 -07:00
parent 005d6fdea2
commit f1d777a95d
33 changed files with 1026 additions and 41 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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)

309
PseudoChannel.py Normal file
View File

@@ -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()

BIN
PseudoChannel.pyc Normal file

Binary file not shown.

1
__init__.py Normal file
View File

@@ -0,0 +1 @@
from PseudoChannel import PseudoChannel

BIN
pseudo-channel.db Normal file

Binary file not shown.

59
pseudo_schedule.xml Normal file
View File

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<schedule>
<mondays></mondays>
<tuesdays></tuesdays>
<wednesdays></wednesdays>
<thursdays></thursdays>
<fridays></fridays>
<saturdays></saturdays>
<sundays></sundays>
<weekends></weekends>
<everyday></everyday>
<weekdays>
<time title="Looney Tunes" type="series" strict-time="false" time-shift="5" overlap-max="">6:00 AM</time>
<time title="Looney Tunes" type="series" strict-time="false" time-shift="5" overlap-max="">6:30 AM</time>
<time title="Looney Tunes" type="series" strict-time="false" time-shift="5" overlap-max="">7:00 AM</time>
<time title="Looney Tunes" type="series" strict-time="false" time-shift="5" overlap-max="">7:30 AM</time>
<time title="Garfield and Friends" type="series" strict-time="false" time-shift="5" overlap-max="">8:00 AM</time>
<time title="Garfield and Friends" type="series" strict-time="false" time-shift="5" overlap-max="">8:30 AM</time>
<time title="Garfield and Friends" type="series" strict-time="false" time-shift="5" overlap-max="">9:00 AM</time>
<time title="Garfield and Friends" type="series" strict-time="false" time-shift="5" overlap-max="">9:30 AM</time>
<time title="talespin" type="series" strict-time="false" time-shift="5" overlap-max="">10:00 AM</time>
<time title="talespin" type="series" strict-time="false" time-shift="5" overlap-max="">10:30 AM</time>
<time title="macgyver" type="series" strict-time="false" time-shift="5" overlap-max="">11:00 AM</time>
<time title="boy meets world" type="series" strict-time="false" time-shift="5" overlap-max="">12:00 PM</time>
<time title="full house" type="series" strict-time="false" time-shift="5" overlap-max="">12:30 PM</time>
<time title="full house" type="series" strict-time="false" time-shift="5" overlap-max="">1:00 PM</time>
<time title="the it crowd" type="series" strict-time="false" time-shift="5" overlap-max="">1:30 PM</time>
<time title="the it crowd" type="series" strict-time="false" time-shift="5" overlap-max="">2:00 PM</time>
<time title="the office (us)" type="series" strict-time="false" time-shift="5" overlap-max="">2:30 PM</time>
<time title="the office (us)" type="series" strict-time="false" time-shift="5" overlap-max="">3:00 PM</time>
<time title="friends" type="series" strict-time="false" time-shift="5" overlap-max="">3:30 PM</time>
<time title="friends" type="series" strict-time="false" time-shift="5" overlap-max="">4:00 PM</time>
<time title="seinfeld" type="series" strict-time="false" time-shift="5" overlap-max="">4:30 PM</time>
<time title="seinfeld" type="series" strict-time="false" time-shift="5" overlap-max="">5:00 PM</time>
<time title="Futurama" type="series" strict-time="false" time-shift="5" overlap-max="">5:30 PM</time>
<time title="Saved by the Bell" type="series" strict-time="false" time-shift="5" overlap-max="">6:00 PM</time>
<time title="Saved by the Bell" type="series" strict-time="false" time-shift="5" overlap-max="">6:30 PM</time>
<time title="new girl" type="series" strict-time="false" time-shift="5" overlap-max="">7:00 PM</time>
<time title="new girl" type="series" strict-time="false" time-shift="5" overlap-max="">7:30 PM</time>
<time title="Wayne&apos;s World" type="movie" strict-time="true" time-shift="5" overlap-max="">7:00 PM</time>
<time title="the trip" type="series" strict-time="false" time-shift="5" overlap-max="">8:30 PM</time>
<time title="the trip" type="series" strict-time="false" time-shift="5" overlap-max="">9:00 PM</time>
<time title="the wire" type="series" strict-time="false" time-shift="5" overlap-max="">9:30 PM</time>
</weekdays>
</schedule>

36
src/Commercial.py Normal file
View File

@@ -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
)

BIN
src/Commercial.pyc Normal file

Binary file not shown.

46
src/Episode.py Normal file
View File

@@ -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

BIN
src/Episode.pyc Normal file

Binary file not shown.

43
src/Media.py Normal file
View File

@@ -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

BIN
src/Media.pyc Normal file

Binary file not shown.

36
src/Movie.py Normal file
View File

@@ -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
)

BIN
src/Movie.pyc Normal file

Binary file not shown.

36
src/Music.py Normal file
View File

@@ -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
)

BIN
src/Music.pyc Normal file

Binary file not shown.

View File

@@ -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

Binary file not shown.

BIN
src/PseudoDatabase.pyc Normal file

Binary file not shown.

36
src/Video.py Normal file
View File

@@ -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
)

BIN
src/Video.pyc Normal file

Binary file not shown.

7
src/__init__.py Normal file
View File

@@ -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

BIN
src/__init__.pyc Normal file

Binary file not shown.