diff --git a/both-dir/PseudoChannel.py b/both-dir/PseudoChannel.py index 69e04ea..690338f 100644 --- a/both-dir/PseudoChannel.py +++ b/both-dir/PseudoChannel.py @@ -1514,7 +1514,7 @@ if __name__ == '__main__': #dates_list = [datetime.datetime.strptime(''.join(str(date[8])), pseudo_channel.APP_TIME_FORMAT_STR) for date in daily_schedule] now = datetime.datetime.now() - now = now.replace(year=1900, month=1, day=1) + #now = now.replace(year=1900, month=1, day=1) #closest_media = nearest(dates_list, now) #print closest_media prevItem = None @@ -1559,7 +1559,7 @@ if __name__ == '__main__': print(str("NOTICE: Readying media: '{}'".format(item[3])).encode('UTF-8')) next_start_time = datetime.datetime.strptime(item[8], pseudo_channel.APP_TIME_FORMAT_STR) now = datetime.datetime.now() - now = now.replace(year=1900, month=1, day=1) + #now = now.replace(year=1900, month=1, day=1) time_diff = next_start_time - now nat_start = datetime.datetime.strptime(item[9], '%Y-%m-%d %H:%M:%S.%f') - datetime.timedelta(milliseconds=item[7]) schedule_offset = nat_start - datetime.datetime.strptime(item[8], pseudo_channel.APP_TIME_FORMAT_STR) @@ -1606,7 +1606,7 @@ if __name__ == '__main__': print("NOTICE: Generating Memory Schedule.") now = datetime.datetime.now() - now = now.replace(year=1900, month=1, day=1) + #now = now.replace(year=1900, month=1, day=1) pseudo_cache = pseudo_channel.get_daily_schedule_cache_as_json() prev_end_time_to_watch_for = None if pseudo_channel.USE_OVERRIDE_CACHE and isforupdate: diff --git a/both-dir/src/PseudoChannelCommercial.py b/both-dir/src/PseudoChannelCommercial.py index 52692cb..c6860f2 100644 --- a/both-dir/src/PseudoChannelCommercial.py +++ b/both-dir/src/PseudoChannelCommercial.py @@ -51,30 +51,34 @@ class PseudoChannelCommercial(): curr_item_start_time = datetime.strptime(now_ep.start_time, '%H:%M:%S') else: curr_item_start_time = reset_time - if(curr_item_start_time < prev_item_end_time): - curr_item_start_time = curr_item_start_time.replace(day=1) - else: - curr_item_start_time = curr_item_start_time.replace(day=2) + curr_item_start_time += timedelta(days=1) + #if(curr_item_start_time < reset_time): + #curr_item_start_time = curr_item_start_time.replace(day=1) + #else: + #curr_item_start_time = curr_item_start_time.replace(day=2) # mutto233 has added some logic at this point # - All dates are now changed to 1/1/90 so midnight doesn't cause issues # - Issues with day skips again being adressed now = datetime.now() - now = now.replace(year=1900, month=1, day=1) + #now = now.replace(year=1900, month=1, day=1) midnight = now.replace(hour=0,minute=0,second=0) if(curr_item_start_time < reset_time): - curr_item_start_time = curr_item_start_time.replace(day=2) + #curr_item_start_time = curr_item_start_time.replace(day=2) + curr_item_start_time += timedelta(days=1) if(prev_item_end_time < reset_time): - prev_item_end_time = prev_item_end_time.replace(day=2) - else: - prev_item_end_time = prev_item_end_time.replace(day=1) + #prev_item_end_time = prev_item_end_time.replace(day=2) + prev_item_end_time += timedelta(days=1) + #else: + #prev_item_end_time = prev_item_end_time.replace(day=1) time_diff = (curr_item_start_time - prev_item_end_time) if prev_item_end_time.replace(microsecond=0) > curr_item_start_time and strict_time == "false": # NOTE: This is just for the logic of this function, I have noticed that this # may cause other issues in other functions, since now the day is off. print("NOTICE: WE MUST BE SKIPPING A DAY, ADDING A DAY TO THE START TIME") - curr_item_start_time = curr_item_start_time.replace(day=2) + #curr_item_start_time = curr_item_start_time.replace(day=2) + curr_item_start_time += timedelta(days=1) print("INFO: Last Item End Time - %s" % prev_item_end_time.replace(microsecond=0)) diff --git a/both-dir/src/PseudoChannelDatabase.py b/both-dir/src/PseudoChannelDatabase.py index d65927c..f5d9e45 100644 --- a/both-dir/src/PseudoChannelDatabase.py +++ b/both-dir/src/PseudoChannelDatabase.py @@ -321,9 +321,13 @@ class PseudoChannelDatabase(): raise e def add_media_to_daily_schedule(self, media): - try: - print(str("{}: {} - {}".format(media.start_time, media.title, media.custom_section_name)).encode('UTF-8')) + mediaPrint = media.start_time + ": " + media.show_series_title + " - " + media.title + " | " + media.custom_section_name + except: + mediaPrint = media.start_time + ": " + media.title + " | " + media.custom_section_name + try: + print(mediaPrint) + #print(str("{}: {} - {}".format(media.start_time, media.title, media.custom_section_name)).encode('UTF-8')) except: print("ERROR: Not outputting media info due to ascii code issues.") diff --git a/both-dir/src/PseudoDailyScheduleController.py b/both-dir/src/PseudoDailyScheduleController.py index b661dea..29d3be3 100644 --- a/both-dir/src/PseudoDailyScheduleController.py +++ b/both-dir/src/PseudoDailyScheduleController.py @@ -294,7 +294,7 @@ class PseudoDailyScheduleController(): def get_html_from_daily_schedule(self, currentTime, bgImageURL, datalist, nowPlayingTitle): now = datetime.now() - now = now.replace(year=1900, month=1, day=1) + #now = now.replace(year=1900, month=1, day=1) midnight = now.replace(hour=23, minute=59, second=59) #mutto233 put this here, because to be honest, isn't the current time always now? if currentTime != None: @@ -399,19 +399,19 @@ class PseudoDailyScheduleController(): continue numberIncrease += 1 with tag('tbody'): - if currentTime != None: - currentTime = currentTime.replace(year=1900, month=1, day=1) + #if currentTime != None: + #currentTime = currentTime.replace(year=1900, month=1, day=1) try: timeBStart = datetime.strptime(row[8], '%I:%M:%S %p') except: timeBStart = datetime.strptime(row[8], '%H:%M:%S') - timeBStart = timeBStart.replace(year=1900, month=1, day=1) + #timeBStart = timeBStart.replace(year=1900, month=1, day=1) try: timeBEnd = datetime.strptime(row[9], '%Y-%m-%d %H:%M:%S.%f') - timeBEnd = timeBEnd.replace(day=1) + #timeBEnd = timeBEnd.replace(day=1) except: timeBEnd = datetime.strptime(row[9], '%Y-%m-%d %H:%M:%S') - timeBEnd = timeBEnd.replace(day=1) + #timeBEnd = timeBEnd.replace(day=1) if currentTime == None: with tag('tr'): with tag('th', scope='row'): @@ -799,7 +799,7 @@ class PseudoDailyScheduleController(): def manually_get_now_playing_bg_image(self, currentTime, datalist): now = datetime.now() - now = now.replace(year=1900, month=1, day=1) + #now = now.replace(year=1900, month=1, day=1) midnight = now.replace(hour=23, minute=59, second=59) increase_var = 0 @@ -812,13 +812,13 @@ class PseudoDailyScheduleController(): timeBStart = datetime.strptime(row[8], '%I:%M:%S %p') except: timeBStart = datetime.strptime(row[8], '%H:%M:%S') - timeBStart = timeBStart.replace(year=1900, month=1, day=1) + #timeBStart = timeBStart.replace(year=1900, month=1, day=1) try: timeBEnd = datetime.strptime(row[9], '%Y-%m-%d %H:%M:%S.%f') - timeBEnd = timeBEnd.replace(day=1) + #timeBEnd = timeBEnd.replace(day=1) except: timeBEnd = datetime.strptime(row[9], '%Y-%m-%d %H:%M:%S') - timeBEnd = timeBEnd.replace(day=1) + #timeBEnd = timeBEnd.replace(day=1) if ((currentTime - timeBStart).total_seconds() >= 0 and \ (timeBEnd - currentTime).total_seconds() >= 0) or \ ((timeBStart - timeBEnd).total_seconds() >= 0 and \ @@ -847,7 +847,7 @@ class PseudoDailyScheduleController(): def manually_get_now_playing_title(self, currentTime, datalist): now = datetime.now() - now = now.replace(year=1900, month=1, day=1) + #now = now.replace(year=1900, month=1, day=1) midnight = now.replace(hour=23, minute=59, second=59) increase_var = 0 @@ -858,7 +858,7 @@ class PseudoDailyScheduleController(): timeBStart = datetime.strptime(row[8], '%I:%M:%S %p') except: timeBStart = datetime.strptime(row[8], '%H:%M:%S') - timeBStart = timeBStart.replace(year=1900, month=1, day=1) + #timeBStart = timeBStart.replace(year=1900, month=1, day=1) try: timeBEnd = datetime.strptime(row[9], '%Y-%m-%d %H:%M:%S.%f') timeBEnd = timeBEnd.replace(day=1) @@ -892,7 +892,7 @@ class PseudoDailyScheduleController(): print("NOTICE: ", "Writing XML / HTML to file.") now = datetime.now() - now = now.replace(year=1900, month=1, day=1) + #now = now.replace(year=1900, month=1, day=1) bgImage = self.manually_get_now_playing_bg_image(now, datalist) diff --git a/main-dir/controls.py b/main-dir/controls.py index 6a775c9..23e013d 100644 --- a/main-dir/controls.py +++ b/main-dir/controls.py @@ -57,8 +57,8 @@ def get_last(): def start_channel(channel): #execute PseudoChannel.py -r in specified channel - last = get_last() try: + last = get_last() os.remove(os.path.abspath(os.path.dirname(__file__))+'/pseudo-channel_'+last+"/last.info") print("NOTICE: Previous last.info deleted") except: diff --git a/setup.py b/setup.py index 26a4a9d..46edd8d 100644 --- a/setup.py +++ b/setup.py @@ -106,10 +106,10 @@ def ps_install(): print("INVALID ENTRY") branchSelect = input('>: ') ps_branch = branchSelect - print("Enter Install Path (default: ./channels)") + print("Enter Install Path (default: "+os.getcwd()+"/channels)") pathInput = input('>: ') if pathInput == '': - path = "./channels" + path = os.getcwd()+"/channels" else: path = pathInput dirCheck = os.path.isdir(path) @@ -298,7 +298,16 @@ def ps_install(): os.remove('../pseudo_config.py') os.remove('../plex_token.py') web_setup() - copy_tv(clientList, clientNumbers, os.getcwd()) + add_client = 'y' + while 'y' in add_client.lower(): + print("Add another Plex client?") + add_client = input('Y/N >: ') + responses = ['yes','y','n','no'] + while add_client.lower() not in responses: + print("INVALID ENTRY") + add_client = input('Y/N >: ') + if 'y' in add_client.lower(): + copy_tv(clientList, path, os.getcwd()) def global_database_update(path): os.chdir(path) @@ -358,12 +367,12 @@ def copyconfig(channel="all"): chanDir = "pseudo-channel_"+str(chan)+'/' shutil.copy('./pseudo_config.py', chanDir) -def copy_tv(clientList, clientNumbers, path): +def copy_tv(clientList, installDir, path): print("Adding Additional Pseudo Channel Clients") #make symlinked copy of pseudo channel files to run on another client print("SELECT DESIRED CLIENT") - for i, client in enumerate(PLEX.clients()): - print(str(i + 1)+":", client.title) - clientList.append(client.title) + clientNumbers = [] + for i, client in enumerate(clientList): + print(str(i + 1)+":", client) clientNumbers.append(i + 1) selectedClient = input('>:') while int(selectedClient) not in clientNumbers: @@ -373,25 +382,170 @@ def copy_tv(clientList, clientNumbers, path): ps_client = ps_client.replace(" ","\ ") if path[-1] == '/': path[-1] = path[-1].replace('/','') - newChannelsDir = path+'_'+ps_client + newChannelsDir = installDir+'_'+ps_client print("Copying Files to "+newChannelsDir) + #os.mkdir(newChannelsDir) #copy all files and directories to a _CLIENT directory - files = glob.glob(path+'/*') + files = glob.glob(installDir+'/**', recursive=True) + for file in files: + isDirectory = os.path.isdir(file) + if isDirectory == True: + newDir = file.replace(installDir.split('/')[-1],installDir.split('/')[-1]+'_'+ps_client) + print("ACTION: Creating Directory "+newDir) + os.mkdir(newDir) for file in files: #copy files into new client directory - if "pseudo-channel.db" in file: #symlink the database files - filePathList = file.split('/') - if "pseudo-channel_" in filePathList[-2]: - symLinkPath = newChannelsDir+'/'+filePathList[-2]+'/'+filePathList[-1] + isFile = os.path.isfile(file) + newDir = file.replace(installDir.split('/')[-1],installDir.split('/')[-1]+'_'+ps_client) + if isFile == True: + if "pseudo-channel.db" in file: #symlink the database files + print("ACTION: Creating symlink to "+file) + filePathList = file.split('/') + if "pseudo-channel_" in filePathList[-2]: + symLinkPath = newChannelsDir+'/'+filePathList[-2]+'/'+filePathList[-1] + else: + symLinkPath = newChannelsDir+'/'+filePathList[-1] + print("Creating symlink to database file") + print(file+" --> "+symLinkPath) + os.symlink(file,symLinkPath) else: - symLinkPath = newChannelsDir+'/'+filePathList[-1] - print("Creating symlink to database file") - print(file+" --> "+symLinkPath) - os.symlink(file,symLinkPath) - else: - shutil.copy(file, newChannelsDir) + if isFile == True: + print("ACTION: Copying "+file) + shutil.copy(file, newDir) -def ps_update(branch='main'): - print("ps_update") #download and copy updates from git to all branches and boxes +def ps_update(): + print("Updating Pseudo Channel") #download and copy updates from git to all branches and boxes + branchList = ['master','develop','python3'] + b = 1 + print("Select Pseudo Channel Repository Branch (default: master)") + for branch in branchList: + print(str(b)+": "+branch) + b = b+1 + branchSelect = input('>: ') + if branchSelect == "": + ps_branch = 'master' + else: + try: + branchSelect = int(branchSelect) + while 0 > int(branchSelect) > b-1: + print("INVALID ENTRY") + branchSelect = input('>: ') + ps_branch = branchList[branchSelect-1] + except: + while branchSelect not in branchList: + print("INVALID ENTRY") + branchSelect = input('>: ') + ps_branch = branchSelect + os.mkdir('../temp') #create temp directory to download files into + try: + git.Repo.clone_from('https://github.com/FakeTV/pseudo-channel', '../temp', branch=ps_branch) + except Exception as e: + print("ERROR GETTING DOWNLOADING FROM GIT") + print("e") + mainFiles = glob.glob('../temp/main-dir/*') + bothFiles = glob.glob('../temp/both-dir/*') + srcFiles = glob.glob('../temp/both-dir/src/*') + chanFiles = glob.glob('../temp/channel-dir/*') + filesList = [mainFiles,bothFiles,srcFiles,chanFiles] + fL = 1 + for files in filesList: + for file in files: + fileName = file.split('/')[-1] + if fileName != 'pseudo_config.py' and fileName != 'src': + oldFiles = glob.glob('./**/'+fileName,recursive=True) + if len(oldFiles) == 0: + #Figure out where to copy new files + psDirs = glob.glob("./pseudo-channel_*") + if fL == 1: + try: + shutil.copyfile(file, os.getcwd()+'/'+fileName) + try: + clearLine = " " * len(printLine) + print(clearLine,end='\r') + except: + pass + printLine = "NOTICE: Copying " + fileName + " to " + os.getcwd() + print(printLine,end='\r') + except Exception as e: + print("\nERROR: Copy Failed - " + fileName + " to " + os.getcwd()) + print(e) + elif fL == 2: + try: + shutil.copyfile(file, os.getcwd()+'/'+fileName) + try: + clearLine = " " * len(printLine) + print(clearLine,end='\r') + except: + pass + printLine = "NOTICE: Copying " + fileName + " to " + os.getcwd()+'/'+fileName + print(printLine,end='\r') + except: + print("\nERROR: Copy Failed - " + fileName + " to " + os.getcwd()+'/'+fileName) + for psDir in psDirs: + try: + shutil.copyfile(file, psDir+'/'+fileName) + try: + clearLine = " " * len(printLine) + print(clearLine,end='\r') + except: + pass + printLine = "NOTICE: Copying " + fileName + " to " + psDir+'/'+fileName + print(printLine,end='\r') + except: + print("\nERROR: Copy Failed - " + fileName + " to " + psDir+'/'+fileName) + elif fL == 3: + try: + shutil.copyfile(file, os.getcwd()+'/src/'+fileName) + try: + clearLine = " " * len(printLine) + print(clearLine,end='\r') + except: + pass + printLine = "NOTICE: Copying " + fileName + " to " + os.getcwd()+'/src/'+fileName + print(printLine,end='\r') + except: + print("\nERROR: Copy Failed - " + fileName + " to " + os.getcwd()+'/src/'+fileName) + for psDir in psDirs: + try: + shutil.copyfile(file, psDir+'/src/'+fileName) + try: + clearLine = " " * len(printLine) + print(clearLine,end='\r') + except: + pass + printLine = "NOTICE: Copying " + fileName + " to " + psDir+'/src/'+fileName + print(printLine,end='\r') + except: + print("\nERROR: Copy Failed - " + fileName + " to " + psDir+'/src/'+fileName) + elif fL == 4: + for psDir in psDirs: + try: + shutil.copyfile(file, psDir+'/src/'+fileName) + try: + clearLine = " " * len(printLine) + print(clearLine,end='\r') + except: + pass + printLine = "NOTICE: Copying " + fileName + " to " + psDir+'/src/'+fileName + print(printLine,end='\r') + except: + print("\nERROR: Copy Failed - " + fileName + " to " + psDir+'/src/'+fileName) + else: + for old in oldFiles: + try: + shutil.copyfile(file, old) + try: + clearLine = " " * len(printLine) + print(clearLine,end='\r') + except: + pass + printLine = "NOTICE: Copying " + fileName + " to " + old + print(printLine,end='\r') + except: + print("\nERROR: Copy Failed - " + fileName + " to " + old) + + fL = fL + 1 + shutil.rmtree('../temp') + print("\nNOTICE: Temp Files Deleted") def web_setup(): print("Setting up the web interface and API...") #set up the web interface and api @@ -459,9 +613,12 @@ def web_setup(): #insert config details configFile = open(path+"/psConfig.php", 'r') configData = configFile.read() - configFile = open(path+"/psConfig.php", 'w') configData = configData.replace("$pseudochannel = '/home/pi/channels/';", "$pseudochannel = '"+os.path.abspath(os.path.dirname(__file__))+"';") - job.run() + configFile.close() + configFile = open(path+"/psConfig.php", 'w') + configFile.write(configData) + configFile.close() + #job.run() parser = argparse.ArgumentParser(description='Pseudo Channel Controls') try: @@ -475,10 +632,10 @@ parser.add_argument('-cc', '--copyconfig', choices = channelsList, help='Copy root config file to one or all channels') parser.add_argument('-tv', '--tv', - action = 'store', + action = 'store_true', help='Add another TV with linked database') parser.add_argument('-u', '--update', - choices = ['main','dev'], + action = 'store_true', help='Update Pseudo Channel to the Latest Version') parser.add_argument('-w', '--web', action = 'store', @@ -500,11 +657,20 @@ if args.copyconfig: print("COPYING CONFIG TO ALL CHANNELS") copyconfig() if args.tv: - print("SETTING UP PSUEDO CHANNEL FOR CLIENT "+str(args.tv)) - #copy_tv(args.tv) + print("SETTING UP PSUEDO CHANNEL FOR CLIENT") + import plex_token as plex_token + PLEX = PlexServer(plex_token.baseurl, plex_token.token) + clientList = [] + for i, client in enumerate(PLEX.clients()): + clientList.append(client.title) + installDir = os.getcwd() + print(installDir) + parentDir = os.path.abspath(os.path.join(installDir, os.pardir)) + print(parentDir) + copy_tv(clientList, installDir, parentDir) if args.update: - print("UPDATING PSEUDO CHANNEL FROM GIT BRANCH "+str(args.update)) - #ps_update(args.update) + print("UPDATING PSEUDO CHANNEL FROM GIT") + ps_update() if args.web: print("SETTING UP PSEUDO CHANNEL WEB INTERFACE AND API FROM GIT BRANCH "+str(args.web)) #web_setup(args.web)