Added in XML output alongside HTML. Also should be generating XML/HTML upon the daily generation of the schedule.

This commit is contained in:
Justin Emter
2017-07-25 14:14:20 -07:00
parent e7169b7338
commit bc1dbbde35
9 changed files with 198 additions and 48 deletions

View File

@@ -100,7 +100,7 @@ class PseudoChannel():
for i, media in enumerate(sectionMedia):
self.db.add_movies_to_db(1, media.title, media.duration)
self.db.add_movies_to_db(1, media.title, media.duration, media.key)
self.print_progress(
i + 1,
@@ -125,7 +125,7 @@ class PseudoChannel():
backgroundImgURL = config.baseurl+backgroundImagePath.art+"?X-Plex-Token="+config.token
self.db.add_shows_to_db(2, media.title, media.duration, '', backgroundImgURL)
self.db.add_shows_to_db(2, media.title, media.duration, '', backgroundImgURL, media.key)
self.print_progress(
i + 1,
@@ -150,7 +150,8 @@ class PseudoChannel():
duration,
episode.index,
episode.parentIndex,
media.title
media.title,
episode.key
)
else:
@@ -161,7 +162,8 @@ class PseudoChannel():
0,
episode.index,
episode.parentIndex,
media.title
media.title,
episode.key
)
elif correct_lib_name == "Commercials":
@@ -172,7 +174,7 @@ class PseudoChannel():
for i, media in enumerate(sectionMedia):
self.db.add_commercials_to_db(3, media.title, media.duration)
self.db.add_commercials_to_db(3, media.title, media.duration, media.key)
self.print_progress(
i + 1,
@@ -589,6 +591,7 @@ class PseudoChannel():
entry[10], # is_strict_time
entry[11], # time_shift
entry[12], # overlap_max
next_episode[8], # plex id
entry[3], # show_series_title
next_episode[5], # episode_number
next_episode[6] # season_number
@@ -623,7 +626,8 @@ class PseudoChannel():
entry[7], # day_of_week
entry[10], # is_strict_time
entry[11], # time_shift
entry[12] # overlap_max
entry[12], # overlap_max
the_movie[6] # plex id
)
#print(movie.natural_end_time)
@@ -649,7 +653,8 @@ class PseudoChannel():
entry[7], # day_of_week
entry[10], # is_strict_time
entry[11], # time_shift
entry[12] # overlap_max
entry[12], # overlap_max
the_music[6], # plex id
)
#print(music.natural_end_time)
@@ -675,7 +680,8 @@ class PseudoChannel():
entry[7], # day_of_week
entry[10], # is_strict_time
entry[11], # time_shift
entry[12] # overlap_max
entry[12], # overlap_max
the_video[6] # plex id
)
#print(music.natural_end_time)
@@ -751,6 +757,10 @@ class PseudoChannel():
previous_episode = entry
def make_xml_schedule(self):
self.controller.make_xml_schedule(self.db.get_daily_schedule())
def get_daily_schedule_as_media_object_list(self):
for i, item in enumerate(self.db.get_daily_schedule(), start=0):
@@ -887,6 +897,15 @@ if __name__ == '__main__':
action='store_true',
help='Updates the schedule based on entries in the google calendar.')
'''
*
* Make XML / HTML Schedule: "python PseudoChannel.py -m"
*
'''
parser.add_argument('-m',
action='store_true',
help='Makes the XML / HTML schedule based on the daily_schedule table.')
globals().update(vars(parser.parse_args()))
args = parser.parse_args()
@@ -917,6 +936,10 @@ if __name__ == '__main__':
pseudo_channel.show_schedule()
if args.m:
pseudo_channel.make_xml_schedule()
if args.r:
try:
@@ -948,6 +971,8 @@ if __name__ == '__main__':
pseudo_channel.generate_daily_schedule()
pseudo_channel.make_xml_schedule()
pseudo_channel.controller.tv_controller(pseudo_channel.db.get_daily_schedule())
t = datetime.datetime.utcnow()

View File

@@ -26,7 +26,8 @@ class Commercial(Media):
day_of_week,
is_strict_time,
time_shift,
overlap_max
overlap_max,
plex_media_id
):
super(Commercial, self).__init__(
@@ -38,5 +39,6 @@ class Commercial(Media):
day_of_week,
is_strict_time,
time_shift,
overlap_max
overlap_max,
plex_media_id
)

View File

@@ -30,9 +30,10 @@ class Episode(Media):
is_strict_time,
time_shift,
overlap_max,
plex_media_id,
show_series_title,
episode_number,
season_number
season_number,
):
super(Episode, self).__init__(
@@ -44,7 +45,8 @@ class Episode(Media):
day_of_week,
is_strict_time,
time_shift,
overlap_max
overlap_max,
plex_media_id
)
self.show_series_title = show_series_title

View File

@@ -31,7 +31,8 @@ class Media(object):
day_of_week,
is_strict_time,
time_shift,
overlap_max
overlap_max,
plex_media_id
):
self.section_type = section_type
@@ -43,6 +44,7 @@ class Media(object):
self.is_strict_time = is_strict_time
self.time_shift = time_shift
self.overlap_max = overlap_max
self.plex_media_id = plex_media_id
self.start_time = natural_start_time
self.end_time = natural_end_time

View File

@@ -26,7 +26,8 @@ class Movie(Media):
day_of_week,
is_strict_time,
time_shift,
overlap_max
overlap_max,
plex_media_id
):
super(Movie, self).__init__(
@@ -38,5 +39,6 @@ class Movie(Media):
day_of_week,
is_strict_time,
time_shift,
overlap_max
overlap_max,
plex_media_id
)

View File

@@ -26,7 +26,8 @@ class Music(Media):
day_of_week,
is_strict_time,
time_shift,
overlap_max
overlap_max,
plex_media_id
):
super(Music, self).__init__(
@@ -38,5 +39,6 @@ class Music(Media):
day_of_week,
is_strict_time,
time_shift,
overlap_max
overlap_max,
plex_media_id
)

View File

@@ -23,29 +23,30 @@ class PseudoChannelDatabase():
self.cursor.execute('CREATE TABLE IF NOT EXISTS '
'movies(id INTEGER PRIMARY KEY AUTOINCREMENT, '
'unix INTEGER, mediaID INTEGER, title TEXT, duration INTEGER, lastPlayedDate TEXT)')
'unix INTEGER, mediaID INTEGER, title TEXT, duration INTEGER, '
'lastPlayedDate TEXT, plexMediaID TEXT)')
self.cursor.execute('CREATE TABLE IF NOT EXISTS '
'videos(id INTEGER PRIMARY KEY AUTOINCREMENT, '
'unix INTEGER, mediaID INTEGER, title TEXT, duration INTEGER)')
'unix INTEGER, mediaID INTEGER, title TEXT, duration INTEGER, plexMediaID TEXT)')
self.cursor.execute('CREATE TABLE IF NOT EXISTS '
'music(id INTEGER PRIMARY KEY AUTOINCREMENT, '
'unix INTEGER, mediaID INTEGER, title TEXT, duration INTEGER)')
'unix INTEGER, mediaID INTEGER, title TEXT, duration INTEGER, plexMediaID TEXT)')
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)')
'lastEpisodeTitle TEXT, fullImageURL TEXT, plexMediaID 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)')
'episodeNumber INTEGER, seasonNumber INTEGER, showTitle TEXT, plexMediaID TEXT)')
self.cursor.execute('CREATE TABLE IF NOT EXISTS '
'commercials(id INTEGER PRIMARY KEY AUTOINCREMENT, unix INTEGER, '
'mediaID INTEGER, title TEXT, duration INTEGER)')
'mediaID INTEGER, title TEXT, duration INTEGER, plexMediaID TEXT)')
self.cursor.execute('CREATE TABLE IF NOT EXISTS '
'schedule(id INTEGER PRIMARY KEY AUTOINCREMENT, unix INTEGER, '
@@ -57,7 +58,7 @@ class PseudoChannelDatabase():
'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, sectionType TEXT)')
'dayOfWeek TEXT, sectionType TEXT, plexMediaID TEXT)')
self.cursor.execute('CREATE TABLE IF NOT EXISTS '
'app_settings(id INTEGER PRIMARY KEY AUTOINCREMENT, version TEXT)')
@@ -119,12 +120,12 @@ class PseudoChannelDatabase():
Setters, etc.
"""
def add_movies_to_db(self, mediaID, title, duration):
def add_movies_to_db(self, mediaID, title, duration, plexMediaID):
unix = int(time.time())
try:
self.cursor.execute("INSERT OR REPLACE INTO movies "
"(unix, mediaID, title, duration) VALUES (?, ?, ?, ?)",
(unix, mediaID, title, duration))
"(unix, mediaID, title, duration, plexMediaID) VALUES (?, ?, ?, ?, ?)",
(unix, mediaID, title, duration, plexMediaID))
self.conn.commit()
# Catch the exception
@@ -133,12 +134,12 @@ class PseudoChannelDatabase():
self.conn.rollback()
raise e
def add_videos_to_db(self, mediaID, title, duration):
def add_videos_to_db(self, mediaID, title, duration, plexMediaID):
unix = int(time.time())
try:
self.cursor.execute("INSERT OR REPLACE INTO videos "
"(unix, mediaID, title, duration) VALUES (?, ?, ?, ?)",
(unix, mediaID, title, duration))
"(unix, mediaID, title, duration, plexMediaID) VALUES (?, ?, ?, ?, ?)",
(unix, mediaID, title, duration, plexMediaID))
self.conn.commit()
# Catch the exception
@@ -147,12 +148,12 @@ class PseudoChannelDatabase():
self.conn.rollback()
raise e
def add_shows_to_db(self, mediaID, title, duration, lastEpisodeTitle, fullImageURL):
def add_shows_to_db(self, mediaID, title, duration, lastEpisodeTitle, fullImageURL, plexMediaID):
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))
"(unix, mediaID, title, duration, lastEpisodeTitle, fullImageURL, plexMediaID) VALUES (?, ?, ?, ?, ?, ?, ?)",
(unix, mediaID, title, duration, lastEpisodeTitle, fullImageURL, plexMediaID))
self.conn.commit()
# Catch the exception
except Exception as e:
@@ -160,12 +161,12 @@ class PseudoChannelDatabase():
self.conn.rollback()
raise e
def add_episodes_to_db(self, mediaID, title, duration, episodeNumber, seasonNumber, showTitle):
def add_episodes_to_db(self, mediaID, title, duration, episodeNumber, seasonNumber, showTitle, plexMediaID):
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))
"(unix, mediaID, title, duration, episodeNumber, seasonNumber, showTitle, plexMediaID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
(unix, mediaID, title, duration, episodeNumber, seasonNumber, showTitle, plexMediaID))
self.conn.commit()
# Catch the exception
except Exception as e:
@@ -173,15 +174,16 @@ class PseudoChannelDatabase():
self.conn.rollback()
raise e
def add_commercials_to_db(self, mediaID, title, duration):
def add_commercials_to_db(self, mediaID, title, duration, plexMediaID):
unix = int(time.time())
try:
self.cursor.execute("INSERT OR REPLACE INTO commercials "
"(unix, mediaID, title, duration) VALUES (?, ?, ?, ?)",
(unix, mediaID, title, duration))
"(unix, mediaID, title, duration, plexMediaID) VALUES (?, ?, ?, ?, ?)",
(unix, mediaID, title, duration, plexMediaID))
self.conn.commit()
# Catch the exception
except Exception as e:
print plexMediaID
# Roll back any change if something goes wrong
self.conn.rollback()
raise e
@@ -211,7 +213,8 @@ class PseudoChannelDatabase():
startTime,
endTime,
dayOfWeek,
sectionType
sectionType,
plexMediaID
):
unix = int(time.time())
@@ -220,8 +223,8 @@ class PseudoChannelDatabase():
self.cursor.execute("INSERT OR REPLACE INTO daily_schedule "
"(unix, mediaID, title, episodeNumber, seasonNumber, "
"showTitle, duration, startTime, endTime, dayOfWeek, sectionType) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
"showTitle, duration, startTime, endTime, dayOfWeek, sectionType, plexMediaID) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
(
unix,
mediaID,
@@ -233,7 +236,8 @@ class PseudoChannelDatabase():
startTime,
endTime,
dayOfWeek,
sectionType
sectionType,
plexMediaID
))
self.conn.commit()
@@ -261,7 +265,8 @@ class PseudoChannelDatabase():
media.start_time,
media.end_time,
media.day_of_week,
media.section_type
media.section_type,
media.plex_media_id
)
"""Database functions.

View File

@@ -5,6 +5,7 @@ from datetime import datetime
import sqlite3
from yattag import Doc
from yattag import indent
import os, sys
import logging
@@ -56,6 +57,63 @@ class PseudoDailyScheduleController():
return backgroundImgURL
def get_xml_from_daily_schedule(self, currentTime, bgImageURL, datalist):
now = datetime.now()
time = now.strftime("%B %d, %Y")
doc, tag, text, line = Doc(
).ttl()
doc.asis('<?xml version="1.0" encoding="UTF-8"?>')
with tag('schedule', currently_playing_bg_image=bgImageURL if bgImageURL != None else ''):
for row in datalist:
timeB = datetime.strptime(row[8], '%I:%M %p')
if currentTime == None:
with tag('time',
('data-key', str(row[12])),
('data-current', 'false'),
('data-type', str(row[11])),
('data-title', str(row[3])),
('data-start-time', str(row[8])),
):
text(row[8])
elif currentTime.hour == timeB.hour and currentTime.minute == timeB.minute:
with tag('time',
('data-key', str(row[12])),
('data-current', 'true'),
('data-type', str(row[11])),
('data-title', str(row[3])),
('data-start-time', str(row[8])),
):
text(row[8])
else:
with tag('time',
('data-key', str(row[12])),
('data-current', 'false'),
('data-type', str(row[11])),
('data-title', str(row[3])),
('data-start-time', str(row[8])),
):
text(row[8])
return indent(doc.getvalue())
'''
*
* Get the generated html for the .html file that is the schedule.
@@ -176,7 +234,7 @@ class PseudoDailyScheduleController():
text(row[8])
return doc.getvalue()
return indent(doc.getvalue())
'''
*
@@ -207,6 +265,35 @@ class PseudoDailyScheduleController():
f.write(data)
'''
*
* Create 'schedules' dir & write the generated xml to .xml file.
* @param data: xml string
* @return null
*
'''
def write_xml_to_file(self, data):
now = datetime.now()
fileName = "pseudo_schedule.xml"
writepath = './schedules/'
if not os.path.exists(writepath):
os.makedirs(writepath)
if os.path.exists(writepath+fileName):
os.remove(writepath+fileName)
mode = 'a' if os.path.exists(writepath) else 'w'
with open(writepath+fileName, mode) as f:
f.write(data)
'''
*
* Trigger "playMedia()" on the Python Plex API for specified media.
@@ -283,6 +370,7 @@ class PseudoDailyScheduleController():
print("Ok end time found")
self.write_schedule_to_file(self.get_html_from_daily_schedule(None, None, datalist))
self.write_xml_to_file(self.get_xml_from_daily_schedule(None, None, datalist))
break
'''
@@ -328,6 +416,19 @@ class PseudoDailyScheduleController():
)
)
"""Generate / write XML to file
"""
self.write_xml_to_file(
self.get_xml_from_daily_schedule(
timeB,
self.get_show_photo(
row[11],
row[6] if row[11] == "TV Shows" else row[3]
),
datalist
)
)
self.my_logger.debug('Trying to play: ' + row[3])
break
@@ -337,3 +438,10 @@ class PseudoDailyScheduleController():
if datalistLengthMonitor >= len(datalist):
self.check_for_end_time(datalist)
def make_xml_schedule(self, datalist):
print "+++++ ", "Writing XML / HTML to file."
self.write_schedule_to_file(self.get_html_from_daily_schedule(None, None, datalist))
self.write_xml_to_file(self.get_xml_from_daily_schedule(None, None, datalist))

View File

@@ -26,7 +26,8 @@ class Video(Media):
day_of_week,
is_strict_time,
time_shift,
overlap_max
overlap_max,
plex_media_id
):
super(Video, self).__init__(
@@ -38,5 +39,6 @@ class Video(Media):
day_of_week,
is_strict_time,
time_shift,
overlap_max
overlap_max,
plex_media_id
)