Added random functionality for Movies & TV Shows.

This commit is contained in:
Justin Emter
2017-07-20 17:40:16 -07:00
parent a2a3a40c93
commit 5b421574d9
4 changed files with 76 additions and 47 deletions

View File

@@ -77,14 +77,6 @@ class PseudoChannel():
sectionMedia = self.PLEX.library.section(section.title).all()
self.print_progress(
0,
len(sectionMedia),
prefix = 'Progress '+section.title+":",
suffix = 'Complete',
bar_length = 50
)
for i, media in enumerate(sectionMedia):
self.db.add_movies_to_db(1, media.title, media.duration)
@@ -92,9 +84,9 @@ class PseudoChannel():
self.print_progress(
i + 1,
len(sectionMedia),
prefix = 'Progress '+section.title+":",
prefix = 'Progress '+section.title+": ",
suffix = 'Complete',
bar_length = 50
bar_length = 40
)
@@ -102,14 +94,6 @@ class PseudoChannel():
sectionMedia = self.PLEX.library.section(section.title).all()
self.print_progress(
0,
len(sectionMedia),
prefix = 'Progress '+section.title+":",
suffix = 'Complete',
bar_length = 50
)
for i, media in enumerate(sectionMedia):
backgroundImagePath = self.PLEX.library.section(section.title).get(media.title)
@@ -125,9 +109,9 @@ class PseudoChannel():
self.print_progress(
i + 1,
len(sectionMedia),
prefix = 'Progress '+section.title+":",
prefix = 'Progress '+section.title+": ",
suffix = 'Complete',
bar_length = 50
bar_length = 40
)
#add all episodes of each tv show to episodes table
@@ -163,25 +147,19 @@ class PseudoChannel():
sectionMedia = self.PLEX.library.section(section.title).all()
self.print_progress(
0,
len(sectionMedia),
prefix = 'Progress '+section.title+":",
suffix = 'Complete',
bar_length = 50
)
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,
len(sectionMedia),
prefix = 'Progress '+section.title+":",
suffix = 'Complete',
bar_length = 50
)
i + 1,
media_length,
prefix = 'Progress '+section.title+":",
suffix = 'Complete',
bar_length = 40
)
def update_schedule(self):
@@ -431,7 +409,13 @@ class PseudoChannel():
if section == "TV Shows":
next_episode = self.db.get_next_episode(entry[3])
if entry[3] == "random":
next_episode = self.db.get_random_episode()
else:
next_episode = self.db.get_next_episode(entry[3])
if next_episode != None:
@@ -460,7 +444,14 @@ class PseudoChannel():
elif section == "Movies":
the_movie = self.db.get_movie(entry[3])
if entry[3] == "random":
the_movie = self.db.get_random_movie()
print("here")
else:
the_movie = self.db.get_movie(entry[3])
if the_movie != None:

View File

@@ -56,5 +56,7 @@
<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>
<time title="random" type="movie" strict-time="false" time-shift="5" overlap-max="">10:00 PM</time>
</weekdays>
</schedule>

View File

@@ -352,6 +352,22 @@ class PseudoChannelDatabase():
return episode_id
def get_random_episode(self):
sql = "SELECT * FROM episodes WHERE id IN (SELECT id FROM episodes ORDER BY RANDOM() LIMIT 1)"
self.cursor.execute(sql)
return self.cursor.fetchone()
def get_random_movie(self):
sql = "SELECT * FROM movies WHERE id IN (SELECT id FROM movies ORDER BY RANDOM() LIMIT 1)"
self.cursor.execute(sql)
return self.cursor.fetchone()
def get_next_episode(self, series):
#print(series)

View File

@@ -1,10 +1,31 @@
from plexapi.server import PlexServer
from datetime import datetime
import sqlite3
from yattag import Doc
import os, sys
import logging
import logging.handlers
from pseudo_config import *
class PseudoDailyScheduleController():
PLEX = PlexServer(baseurl, token)
BASE_URL = baseurl
TOKEN = token
def __init__(self):
pass
self.my_logger = logging.getLogger('MyLogger')
self.my_logger.setLevel(logging.DEBUG)
self.handler = logging.handlers.SysLogHandler(address = '/dev/log')
self.my_logger.addHandler(self.handler)
'''
*
@@ -13,16 +34,15 @@ class PseudoDailyScheduleController():
* @return string: full path of to the show image
*
'''
def get_show_photo(self, seriesTitle):
def get_show_photo(self, section, title):
c.execute("SELECT fullImageURL FROM shows WHERE title = ? COLLATE NOCASE", (seriesTitle, ))
datalist = list(c.fetchone())
backgroundImagePath = self.PLEX.library.section(section).get(title)
backgroundImgURL = ''
if len(datalist):
backgroundImgURL = datalist[0]
if isinstance(backgroundImagePath.art, str):
backgroundImgURL = self.BASE_URL+backgroundImagePath.art+"?X-Plex-Token="+self.TOKEN
return backgroundImgURL
@@ -226,7 +246,7 @@ class PseudoDailyScheduleController():
print("Ok end time found")
write_schedule_to_file(get_html_from_daily_schedule(None, None))
self.write_schedule_to_file(self.get_html_from_daily_schedule(None, None))
break
'''
@@ -259,11 +279,11 @@ class PseudoDailyScheduleController():
print("Starting Epsisode: " + row[3])
print(row)
play_media("TV Shows", row[6], row[3])
self.play_media("TV Shows", row[6], row[3])
write_schedule_to_file(get_html_from_daily_schedule(timeB, get_show_photo(row[6])))
self.write_schedule_to_file(self.get_html_from_daily_schedule(timeB, self.get_show_photo(row[11], row[6])))
my_logger.debug('Trying to play: ' + row[3])
self.my_logger.debug('Trying to play: ' + row[3])
break
@@ -271,4 +291,4 @@ class PseudoDailyScheduleController():
if datalistLengthMonitor >= len(datalist):
check_for_end_time()
self.check_for_end_time()