mirror of
https://github.com/FakeTV/pseudo-channel.git
synced 2025-12-25 20:53:39 +00:00
Setup script and updates for python 3 migration
Most updates related to adding install script and schedule generator for first install
This commit is contained in:
@@ -666,11 +666,18 @@ class PseudoChannel():
|
|||||||
for key, val in weekday_dict.items():
|
for key, val in weekday_dict.items():
|
||||||
if str(entry[7]) in str(val) and int(weekno) == int(key):
|
if str(entry[7]) in str(val) and int(weekno) == int(key):
|
||||||
if section == "TV Shows":
|
if section == "TV Shows":
|
||||||
minmax = entry[4].split(",")
|
try:
|
||||||
min = int(minmax[0])
|
minmax = entry[4].split(",")
|
||||||
min = min * 60000
|
min = int(minmax[0])
|
||||||
max = int(minmax[1])
|
min = min * 60000
|
||||||
max = max * 60000
|
max = int(minmax[1])
|
||||||
|
max = max * 60000
|
||||||
|
except:
|
||||||
|
minmax = entry[4]
|
||||||
|
min = int(minmax)
|
||||||
|
min = min * 60000
|
||||||
|
max = int(minmax)
|
||||||
|
max = max * 60000
|
||||||
if str(entry[3]).lower() == "random":
|
if str(entry[3]).lower() == "random":
|
||||||
sections = self.PLEX.library.sections()
|
sections = self.PLEX.library.sections()
|
||||||
shows_list = []
|
shows_list = []
|
||||||
|
|||||||
@@ -11,8 +11,10 @@ import sqlite3
|
|||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
|
import math
|
||||||
from shutil import copy2
|
from shutil import copy2
|
||||||
from pseudo_config import plexLibraries as global_commercials
|
from pseudo_config import plexLibraries as global_commercials
|
||||||
|
from src import PseudoChannelDatabase
|
||||||
|
|
||||||
channel_dir_increment_symbol = "_"
|
channel_dir_increment_symbol = "_"
|
||||||
|
|
||||||
@@ -43,7 +45,7 @@ update_call = "python PseudoChannel.py %s" % update_flags
|
|||||||
|
|
||||||
|
|
||||||
# Step ONE: Global database update
|
# Step ONE: Global database update
|
||||||
print("NOTICE: Doing global update from PLEX: %s" % update_flags)
|
print("ACTION: Doing global update from PLEX: %s" % update_flags)
|
||||||
try:
|
try:
|
||||||
os.rename("pseudo-channel.db", "pseudo-channel.bak")
|
os.rename("pseudo-channel.db", "pseudo-channel.bak")
|
||||||
except OSError:
|
except OSError:
|
||||||
@@ -76,7 +78,7 @@ for channel_dir in channel_dirs:
|
|||||||
os.chdir(os.path.join(channel_dirA, channel_dir))
|
os.chdir(os.path.join(channel_dirA, channel_dir))
|
||||||
channel_dirA = os.getcwd()
|
channel_dirA = os.getcwd()
|
||||||
db_path = os.path.join(channel_dirA, "pseudo-channel.db")
|
db_path = os.path.join(channel_dirA, "pseudo-channel.db")
|
||||||
print("NOTICE: Importing from " + db_path)
|
print("ACTION: Importing from " + db_path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn = sqlite3.connect(db_path)
|
conn = sqlite3.connect(db_path)
|
||||||
@@ -103,12 +105,12 @@ for channel_dir in channel_dirs:
|
|||||||
|
|
||||||
|
|
||||||
# Step THREE: Delete the previous database, replace with the recently created global one
|
# Step THREE: Delete the previous database, replace with the recently created global one
|
||||||
print("NOTICE: Copying global update to " + db_path)
|
print("ACTION: Copying global update to " + db_path)
|
||||||
copy2('../pseudo-channel.db','.')
|
copy2('../pseudo-channel.db','.')
|
||||||
|
|
||||||
|
|
||||||
# Step FOUR: Import the previous information we exported previously
|
# Step FOUR: Import the previous information we exported previously
|
||||||
print("NOTICE: Exporting to " + db_path)
|
print("ACTION: Exporting to " + db_path)
|
||||||
conn = sqlite3.connect(db_path)
|
conn = sqlite3.connect(db_path)
|
||||||
table = conn.cursor()
|
table = conn.cursor()
|
||||||
|
|
||||||
@@ -120,40 +122,69 @@ for channel_dir in channel_dirs:
|
|||||||
sql = "UPDATE movies SET lastPlayedDate=? WHERE title=?"
|
sql = "UPDATE movies SET lastPlayedDate=? WHERE title=?"
|
||||||
table.execute(sql,lastMovie_export[i])
|
table.execute(sql,lastMovie_export[i])
|
||||||
if len(schedule) == 0:
|
if len(schedule) == 0:
|
||||||
|
#db = PseudoChannelDatabase("./pseudo-channel.db")
|
||||||
print("NOTICE: Schedule Not Found, Creating Default Schedule")
|
print("NOTICE: Schedule Not Found, Creating Default Schedule")
|
||||||
entryList = {}
|
entryList = {}
|
||||||
entryList['id'] = "1"
|
entryList['id'] = "1"
|
||||||
entryList['unix'] = str(time.time())
|
entryList['unix'] = str(time.time())
|
||||||
entryList['mediaID'] = "999"
|
entryList['mediaID'] = "0"
|
||||||
entryList['title'] = "random"
|
rndsql = "SELECT * FROM shows WHERE (customSectionName NOT LIKE 'playlist' AND duration BETWEEN 6000 and 999000) ORDER BY RANDOM() LIMIT 1"
|
||||||
entryList['duration'] = "10,90"
|
table.execute(rndsql)
|
||||||
|
the_show = table.fetchone()
|
||||||
|
entryList['duration'] = str("1,"+str(int(the_show[4]) / 60000))
|
||||||
|
entryList['title'] = the_show[3]
|
||||||
entryList['startTime'] = "00:00:00"
|
entryList['startTime'] = "00:00:00"
|
||||||
entryList['endTime'] = "0"
|
|
||||||
entryList['dayOfWeek'] = "everyday"
|
entryList['dayOfWeek'] = "everyday"
|
||||||
entryList['startTimeUnix'] = str(time.mktime(time.strptime("2000/01/01 00:00:00", "%Y/%m/%d %H:%M:%S")))
|
entryList['startTimeUnix'] = time.mktime(time.strptime("2000/01/01 00:00:00", "%Y/%m/%d %H:%M:%S"))
|
||||||
entryList['section'] = "TV Shows"
|
entryList['section'] = "TV Shows"
|
||||||
entryList['strictTime'] = "true"
|
if entryList['startTime'] == "00:00:00":
|
||||||
entryList['timeShift'] = "5"
|
entryList['strictTime'] = "true"
|
||||||
|
else:
|
||||||
|
entryList['strictTime'] = "secondary"
|
||||||
|
entryList['endTime'] = datetime.datetime.fromtimestamp(float(entryList['startTimeUnix']) + the_show[4]/1000).strftime("%H:%M:%S")
|
||||||
|
entryList['timeShift'] = 15
|
||||||
entryList['overlapMax'] = 15
|
entryList['overlapMax'] = 15
|
||||||
entryList['xtra'] = ""
|
entryList['xtra'] = ""
|
||||||
|
print("INFO: Adding "+entryList['startTime']+" - "+entryList['title']+"\033[K",end='\n')
|
||||||
sql = "INSERT INTO schedule(id,unix,mediaID,title,duration,startTime,endTime,dayOfWeek,startTimeUnix,section,strictTime,timeShift,overlapMax,xtra) \
|
sql = "INSERT INTO schedule(id,unix,mediaID,title,duration,startTime,endTime,dayOfWeek,startTimeUnix,section,strictTime,timeShift,overlapMax,xtra) \
|
||||||
VALUES(:id,:unix,:mediaID,:title,:duration,:startTime,:endTime,:dayOfWeek,:startTimeUnix,:section,:strictTime,:timeShift,:overlapMax,:xtra)"
|
VALUES(:id,:unix,:mediaID,:title,:duration,:startTime,:endTime,:dayOfWeek,:startTimeUnix,:section,:strictTime,:timeShift,:overlapMax,:xtra)"
|
||||||
table.execute(sql,entryList)
|
table.execute(sql,entryList)
|
||||||
while int(entryList['id']) < 96:
|
timediff = datetime.datetime.strptime("23:59:59", "%H:%M:%S") - datetime.datetime.strptime(entryList['startTime'], "%H:%M:%S")
|
||||||
|
print("INFO: "+str(timediff.seconds)+" to midnight\033[K",end='\n')
|
||||||
|
endloop = 0
|
||||||
|
while timediff.seconds > 900 and endloop == 0:
|
||||||
entryList['id'] = str(int(entryList['id']) + 1)
|
entryList['id'] = str(int(entryList['id']) + 1)
|
||||||
entryList['unix'] = str(time.time())
|
entryList['unix'] = str(time.time())
|
||||||
entryList['startTimeUnix'] = float(entryList['startTimeUnix']) + 900
|
prevEndTimeUnix = float(entryList['startTimeUnix']) + the_show[4]/1000
|
||||||
entryList['startTime'] = str(datetime.datetime.fromtimestamp(entryList['startTimeUnix']).strftime("%H:%M:%S"))
|
prevEndTime = datetime.datetime.fromtimestamp(prevEndTimeUnix)
|
||||||
|
entryList['startTime'] = prevEndTime + (datetime.datetime.min - prevEndTime) % datetime.timedelta(minutes=entryList['timeShift'])
|
||||||
|
entryList['startTime'] = entryList['startTime'].strftime("%H:%M:%S")
|
||||||
|
entryList['startTimeUnix'] = time.mktime(time.strptime("2000/01/01 "+entryList['startTime'], "%Y/%m/%d %H:%M:%S"))
|
||||||
|
print("INFO: "+str(entryList['startTimeUnix'])+" - New Unix Time Start\033[K",end='\n')
|
||||||
|
print("INFO: "+str(entryList['startTime'])+" - New Start Time\033[K",end='\n')
|
||||||
|
if entryList['startTime'] == "00:00:00":
|
||||||
|
entryList['strictTime'] = "true"
|
||||||
|
else:
|
||||||
|
entryList['strictTime'] = "secondary"
|
||||||
timediff = datetime.datetime.strptime("23:59:59", "%H:%M:%S") - datetime.datetime.strptime(entryList['startTime'], "%H:%M:%S")
|
timediff = datetime.datetime.strptime("23:59:59", "%H:%M:%S") - datetime.datetime.strptime(entryList['startTime'], "%H:%M:%S")
|
||||||
durationSplit = entryList['duration'].split(',')
|
maxMS = timediff.seconds * 1000
|
||||||
if timediff.seconds < 5399:
|
if 0 < int(entryList['endTime'].split(':')[1]) <= 15 or 30 < int(entryList['endTime'].split(':')[1]) <= 45:
|
||||||
maxTime = round(timediff.seconds / 60)
|
maxMS = 15*60*1000
|
||||||
minTime = int(durationSplit[0])
|
rndsql = "SELECT * FROM shows WHERE (customSectionName NOT LIKE 'playlist' AND duration BETWEEN ? and ?) ORDER BY RANDOM() LIMIT 1"
|
||||||
if minTime > maxTime:
|
table.execute(rndsql, ("60000", str(maxMS)))
|
||||||
minTime = maxTime - 1
|
the_show = table.fetchone()
|
||||||
entryList['duration'] = str(minTime)+','+str(maxTime)
|
entryList['duration'] = str("1,"+str(int(the_show[4]) / 60000))
|
||||||
entryList['overlapMax'] = round(int(durationSplit[0]) * 1.5)
|
entryList['endTime'] = datetime.datetime.fromtimestamp(float(entryList['startTimeUnix']) + the_show[4]/1000).strftime("%H:%M:%S")
|
||||||
table.execute(sql,entryList)
|
entryList['title'] = the_show[3]
|
||||||
|
entryList['overlapMax'] = round(int(entryList['duration'].split(',')[1]) * 0.5)
|
||||||
|
print("INFO: Adding "+entryList['startTime']+" - "+entryList['title']+"\033[K",end='\n')
|
||||||
|
sql = "INSERT INTO schedule(id,unix,mediaID,title,duration,startTime,endTime,dayOfWeek,startTimeUnix,section,strictTime,timeShift,overlapMax,xtra) \
|
||||||
|
VALUES(:id,:unix,:mediaID,:title,:duration,:startTime,:endTime,:dayOfWeek,:startTimeUnix,:section,:strictTime,:timeShift,:overlapMax,:xtra)"
|
||||||
|
if entryList['startTime'] != "00:00:00":
|
||||||
|
table.execute(sql,entryList)
|
||||||
|
print("INFO: "+str(timediff.seconds)+" to midnight\033[K",end='\n')
|
||||||
|
else:
|
||||||
|
endloop = 1
|
||||||
else:
|
else:
|
||||||
for i in range(0,len(schedule)):
|
for i in range(0,len(schedule)):
|
||||||
sql = "INSERT INTO schedule(id,unix,mediaID,title,duration,startTime,endTime,dayOfWeek,startTimeUnix,section,strictTime,timeShift,overlapMax,xtra) \
|
sql = "INSERT INTO schedule(id,unix,mediaID,title,duration,startTime,endTime,dayOfWeek,startTimeUnix,section,strictTime,timeShift,overlapMax,xtra) \
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ billiard
|
|||||||
certifi
|
certifi
|
||||||
chardet
|
chardet
|
||||||
httplib2
|
httplib2
|
||||||
|
GitPython
|
||||||
idna
|
idna
|
||||||
kombu
|
kombu
|
||||||
oauth2client
|
oauth2client
|
||||||
|
|||||||
33
setup.py
33
setup.py
@@ -41,6 +41,36 @@ def get_channels(channelsDir='.'):
|
|||||||
do = "nothing"
|
do = "nothing"
|
||||||
return channelsList
|
return channelsList
|
||||||
|
|
||||||
|
def generate_daily_schedules(channelsList):
|
||||||
|
#execute PseudoChannel.py -g in specified channel
|
||||||
|
for channel in channelsList:
|
||||||
|
os.chdir('./pseudo-channel_'+channel)
|
||||||
|
print("GENERATING SCHEDULE FOR CHANNEL "+channel)
|
||||||
|
process = subprocess.Popen(["python", "-u", "PseudoChannel.py", "-g"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
|
||||||
|
while True:
|
||||||
|
output = process.stdout.readline()
|
||||||
|
if process.poll() is not None:
|
||||||
|
break
|
||||||
|
if output:
|
||||||
|
print(output.strip())
|
||||||
|
rc = process.poll()
|
||||||
|
os.chdir('../')
|
||||||
|
|
||||||
|
def randomize_episodes(channelsList):
|
||||||
|
#execute PseudoChannel.py -ep in specified channel
|
||||||
|
for channel in channelsList:
|
||||||
|
os.chdir('./pseudo-channel_'+channel)
|
||||||
|
print("RANDOMIZING STARTING EPISODES FOR ALL SHOWS ON CHANNEL "+channel)
|
||||||
|
process = subprocess.Popen(["python", "-u", "PseudoChannel.py", "-ep"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
|
||||||
|
while True:
|
||||||
|
output = process.stdout.readline()
|
||||||
|
if process.poll() is not None:
|
||||||
|
break
|
||||||
|
if output:
|
||||||
|
print(output.strip())
|
||||||
|
rc = process.poll()
|
||||||
|
os.chdir('../')
|
||||||
|
|
||||||
def ps_install(ps_branch='python3', path='./channels'):
|
def ps_install(ps_branch='python3', path='./channels'):
|
||||||
dirCheck = os.path.isdir(path)
|
dirCheck = os.path.isdir(path)
|
||||||
if dirCheck == False:
|
if dirCheck == False:
|
||||||
@@ -209,6 +239,9 @@ def ps_install(ps_branch='python3', path='./channels'):
|
|||||||
shutil.copy('./pseudo_config.py', '../')
|
shutil.copy('./pseudo_config.py', '../')
|
||||||
shutil.copy('./plex_token.py', '../')
|
shutil.copy('./plex_token.py', '../')
|
||||||
global_database_update('./') #run database scan
|
global_database_update('./') #run database scan
|
||||||
|
channelsList = get_channels()
|
||||||
|
randomize_episodes(channelsList)
|
||||||
|
generate_daily_schedules(channelsList)
|
||||||
os.remove('../pseudo_config.py')
|
os.remove('../pseudo_config.py')
|
||||||
os.remove('../plex_token.py')
|
os.remove('../plex_token.py')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user