diff --git a/PseudoChannel.py b/both-dir/PseudoChannel.py similarity index 100% rename from PseudoChannel.py rename to both-dir/PseudoChannel.py diff --git a/src/Commercial.py b/both-dir/src/Commercial.py similarity index 100% rename from src/Commercial.py rename to both-dir/src/Commercial.py diff --git a/src/Episode.py b/both-dir/src/Episode.py similarity index 100% rename from src/Episode.py rename to both-dir/src/Episode.py diff --git a/src/Helpers.py b/both-dir/src/Helpers.py similarity index 100% rename from src/Helpers.py rename to both-dir/src/Helpers.py diff --git a/src/Media.py b/both-dir/src/Media.py similarity index 100% rename from src/Media.py rename to both-dir/src/Media.py diff --git a/src/Movie.py b/both-dir/src/Movie.py similarity index 100% rename from src/Movie.py rename to both-dir/src/Movie.py diff --git a/src/Music.py b/both-dir/src/Music.py similarity index 100% rename from src/Music.py rename to both-dir/src/Music.py diff --git a/src/PseudoChannelCommercial.py b/both-dir/src/PseudoChannelCommercial.py similarity index 100% rename from src/PseudoChannelCommercial.py rename to both-dir/src/PseudoChannelCommercial.py diff --git a/src/PseudoChannelDatabase.py b/both-dir/src/PseudoChannelDatabase.py similarity index 100% rename from src/PseudoChannelDatabase.py rename to both-dir/src/PseudoChannelDatabase.py diff --git a/src/PseudoChannelRandomMovie.py b/both-dir/src/PseudoChannelRandomMovie.py similarity index 100% rename from src/PseudoChannelRandomMovie.py rename to both-dir/src/PseudoChannelRandomMovie.py diff --git a/src/PseudoDailyScheduleController.py b/both-dir/src/PseudoDailyScheduleController.py similarity index 100% rename from src/PseudoDailyScheduleController.py rename to both-dir/src/PseudoDailyScheduleController.py diff --git a/src/Video.py b/both-dir/src/Video.py similarity index 100% rename from src/Video.py rename to both-dir/src/Video.py diff --git a/src/__init__.py b/both-dir/src/__init__.py similarity index 100% rename from src/__init__.py rename to both-dir/src/__init__.py diff --git a/generate_daily_sched.sh b/channel-dir/generate_daily_sched.sh old mode 100755 new mode 100644 similarity index 100% rename from generate_daily_sched.sh rename to channel-dir/generate_daily_sched.sh diff --git a/report_MediaFolders.py b/channel-dir/report_MediaFolders.py similarity index 95% rename from report_MediaFolders.py rename to channel-dir/report_MediaFolders.py index b945452..c4a90cd 100644 --- a/report_MediaFolders.py +++ b/channel-dir/report_MediaFolders.py @@ -1,29 +1,29 @@ -# -*- coding: utf-8 -*- -""" -Created on Thu Jun 28 22:59:57 2018 - -@author: Matt -""" - -from pseudo_config import plexLibraries as local_commercials - -commercials = local_commercials["Commercials"] -movies = local_commercials["Movies"] -tvs = local_commercials["TV Shows"] - -commercials_file = open('Commercial_Libraries.txt','w') -movies_file = open('Movie_Libraries.txt','w') -tvs_file = open('TV_Libraries.txt','w') -for commercial in commercials: - commercials_file.write(commercial + '\n') -for movie in movies: - movies_file.write(movie + '\n') -for tv in tvs: - tvs_file.write(tv + '\n') - -commercials_file.close() -movies_file.close() -tvs_file.close() - - - +# -*- coding: utf-8 -*- +""" +Created on Thu Jun 28 22:59:57 2018 + +@author: Matt +""" + +from pseudo_config import plexLibraries as local_commercials + +commercials = local_commercials["Commercials"] +movies = local_commercials["Movies"] +tvs = local_commercials["TV Shows"] + +commercials_file = open('Commercial_Libraries.txt','w') +movies_file = open('Movie_Libraries.txt','w') +tvs_file = open('TV_Libraries.txt','w') +for commercial in commercials: + commercials_file.write(commercial + '\n') +for movie in movies: + movies_file.write(movie + '\n') +for tv in tvs: + tvs_file.write(tv + '\n') + +commercials_file.close() +movies_file.close() +tvs_file.close() + + + diff --git a/startstop.sh b/channel-dir/startstop.sh old mode 100755 new mode 100644 similarity index 100% rename from startstop.sh rename to channel-dir/startstop.sh diff --git a/tests/__init__.py b/development_scripts/__init__.py similarity index 100% rename from tests/__init__.py rename to development_scripts/__init__.py diff --git a/tests/test_commercial_injection.py b/development_scripts/test_commercial_injection.py similarity index 100% rename from tests/test_commercial_injection.py rename to development_scripts/test_commercial_injection.py diff --git a/tests/test_update_daily_schedule.py b/development_scripts/test_update_daily_schedule.py similarity index 100% rename from tests/test_update_daily_schedule.py rename to development_scripts/test_update_daily_schedule.py diff --git a/Channel_Sorter.py b/main-dir/Channel_Sorter.py similarity index 94% rename from Channel_Sorter.py rename to main-dir/Channel_Sorter.py index d9cf76e..4040468 100644 --- a/Channel_Sorter.py +++ b/main-dir/Channel_Sorter.py @@ -1,26 +1,26 @@ -# -*- coding: utf-8 -*- -""" -Created on Tue Jun 26 23:31:00 2018 - -@author: Matt -""" -import re -import sys - -def atoi(text): - return int(text) if text.isdigit() else text - -def natural_keys(text): - ''' - alist.sort(key=natural_keys) sorts in human order - http://nedbatchelder.com/blog/200712/human_sorting.html - (See Toothy's implementation in the comments) - ''' - return [ atoi(c) for c in re.split('(\d+)', text) ] - -temp_hold = list(sys.argv[1:]) -temp_hold.sort(key=natural_keys) -file = open('Channels_Sorted.txt','w') -for item in temp_hold: - file.write(item + '\n') +# -*- coding: utf-8 -*- +""" +Created on Tue Jun 26 23:31:00 2018 + +@author: Matt +""" +import re +import sys + +def atoi(text): + return int(text) if text.isdigit() else text + +def natural_keys(text): + ''' + alist.sort(key=natural_keys) sorts in human order + http://nedbatchelder.com/blog/200712/human_sorting.html + (See Toothy's implementation in the comments) + ''' + return [ atoi(c) for c in re.split('(\d+)', text) ] + +temp_hold = list(sys.argv[1:]) +temp_hold.sort(key=natural_keys) +file = open('Channels_Sorted.txt','w') +for item in temp_hold: + file.write(item + '\n') file.close() \ No newline at end of file diff --git a/Global_DatabaseUpdate.py b/main-dir/Global_DatabaseUpdate.py similarity index 97% rename from Global_DatabaseUpdate.py rename to main-dir/Global_DatabaseUpdate.py index eefcbab..355d4aa 100644 --- a/Global_DatabaseUpdate.py +++ b/main-dir/Global_DatabaseUpdate.py @@ -1,107 +1,107 @@ -# -*- coding: utf-8 -*- -""" -Created on Thu Jun 28 17:33:59 2018 - -@author: Matt -""" -import sqlite3 -import os -from shutil import copy2 -from pseudo_config import plexLibraries as global_commercials - -channel_dir_increment_symbol = "_" - - - -# Step ONE: Global database update -print("+++++ Doing global update from PLEX") -os.system('sudo python PseudoChannel.py -u') - - -base_dirA = os.path.dirname(os.path.abspath(__file__)) -locations = "pseudo-channel"+channel_dir_increment_symbol -channel_dirs = [ item for item in os.listdir('.') if os.path.isdir(os.path.join('.', item)) ] -channel_dirs = list(filter(lambda x: x.startswith(locations),channel_dirs)) - -for channel_dir in channel_dirs: - # Step TWO: Go to each folder, export the following information - # - Show title, lastEpisodeTitle - # - Movie title, lastPlayedDate - os.chdir(channel_dir) - - channel_dirA = os.path.dirname(os.path.abspath(__file__)) - db_path = os.path.join(channel_dirA, "pseudo-channel.db") - print("+++++ Importing from " + db_path) - try: - conn = sqlite3.connect(db_path) - table = conn.cursor() - - - lastEpisode_export = table.execute('SELECT lastEpisodeTitle,title FROM shows').fetchall() - lastEpisode_export = list(lastEpisode_export) - lastMovie_export = table.execute('SELECT lastPlayedDate,title FROM movies').fetchall() - lastMovie_export = list(lastMovie_export) - - conn.commit() - conn.close() - except: - print("+++++ Database experiencing errors or hasn't been formed yet; creating fresh one") - lastEpisode_export = [] - lastMovie_export = [] - - - # Step THREE: Delete the previous database, replace with the recently created global one - print("+++++ Copying global update to " + db_path) - copy2('../pseudo-channel.db','.') - - - # Step FOUR: Import the previous information we exported previously - print("+++++ Exporting to " + db_path) - conn = sqlite3.connect(db_path) - table = conn.cursor() - - for i in range(0,len(lastEpisode_export)): - sql = "UPDATE shows SET lastEpisodeTitle=? WHERE title=?" - table.execute(sql,lastEpisode_export[i]) - - for i in range(0,len(lastMovie_export)): - sql = "UPDATE movies SET lastPlayedDate=? WHERE title=?" - table.execute(sql,lastMovie_export[i]) - - # Step FIVE: Remove any media not in the directories set of commerical archives - print("+++++ Trimming database at " + db_path) - os.system('sudo python report_MediaFolders.py') - local_commercials = open('Commercial_Libraries.txt').read().splitlines() - local_movies = open('Movie_Libraries.txt').read().splitlines() - local_tvs = open('TV_Libraries.txt').read().splitlines() - - commercial_removal = [x for x in global_commercials["Commercials"] if x not in local_commercials] - movie_removal = [x for x in global_commercials["Movies"] if x not in local_movies] - tv_removal = [x for x in global_commercials["TV Shows"] if x not in local_tvs] - -# print(db_path) -# print(local_commercials) -# print(global_commercials["Commercials"]) -# print(commercial_removal) - - for commercial in commercial_removal: - sql = "DELETE FROM commercials WHERE customSectionName=?" - table.execute(sql,(commercial,)) - for movie in movie_removal: - sql = "DELETE FROM movies WHERE customSectionName=?" - table.execute(sql,(movie,)) - for tv in tv_removal: - sql = "DELETE FROM shows WHERE customSectionName=?" - table.execute(sql,(tv,)) - sql = "DELETE FROM episodes WHERE customSectionName=?" - table.execute(sql,(tv,)) - - conn.commit() - conn.close() - - os.chdir('..') - - print("+++++ " + db_path + " complete! Going to next file") - - -print("+++++ Global update COMPLETE") +# -*- coding: utf-8 -*- +""" +Created on Thu Jun 28 17:33:59 2018 + +@author: Matt +""" +import sqlite3 +import os +from shutil import copy2 +from pseudo_config import plexLibraries as global_commercials + +channel_dir_increment_symbol = "_" + + + +# Step ONE: Global database update +print("+++++ Doing global update from PLEX") +os.system('sudo python PseudoChannel.py -u') + + +base_dirA = os.path.dirname(os.path.abspath(__file__)) +locations = "pseudo-channel"+channel_dir_increment_symbol +channel_dirs = [ item for item in os.listdir('.') if os.path.isdir(os.path.join('.', item)) ] +channel_dirs = list(filter(lambda x: x.startswith(locations),channel_dirs)) + +for channel_dir in channel_dirs: + # Step TWO: Go to each folder, export the following information + # - Show title, lastEpisodeTitle + # - Movie title, lastPlayedDate + os.chdir(channel_dir) + + channel_dirA = os.path.dirname(os.path.abspath(__file__)) + db_path = os.path.join(channel_dirA, "pseudo-channel.db") + print("+++++ Importing from " + db_path) + try: + conn = sqlite3.connect(db_path) + table = conn.cursor() + + + lastEpisode_export = table.execute('SELECT lastEpisodeTitle,title FROM shows').fetchall() + lastEpisode_export = list(lastEpisode_export) + lastMovie_export = table.execute('SELECT lastPlayedDate,title FROM movies').fetchall() + lastMovie_export = list(lastMovie_export) + + conn.commit() + conn.close() + except: + print("+++++ Database experiencing errors or hasn't been formed yet; creating fresh one") + lastEpisode_export = [] + lastMovie_export = [] + + + # Step THREE: Delete the previous database, replace with the recently created global one + print("+++++ Copying global update to " + db_path) + copy2('../pseudo-channel.db','.') + + + # Step FOUR: Import the previous information we exported previously + print("+++++ Exporting to " + db_path) + conn = sqlite3.connect(db_path) + table = conn.cursor() + + for i in range(0,len(lastEpisode_export)): + sql = "UPDATE shows SET lastEpisodeTitle=? WHERE title=?" + table.execute(sql,lastEpisode_export[i]) + + for i in range(0,len(lastMovie_export)): + sql = "UPDATE movies SET lastPlayedDate=? WHERE title=?" + table.execute(sql,lastMovie_export[i]) + + # Step FIVE: Remove any media not in the directories set of commerical archives + print("+++++ Trimming database at " + db_path) + os.system('sudo python report_MediaFolders.py') + local_commercials = open('Commercial_Libraries.txt').read().splitlines() + local_movies = open('Movie_Libraries.txt').read().splitlines() + local_tvs = open('TV_Libraries.txt').read().splitlines() + + commercial_removal = [x for x in global_commercials["Commercials"] if x not in local_commercials] + movie_removal = [x for x in global_commercials["Movies"] if x not in local_movies] + tv_removal = [x for x in global_commercials["TV Shows"] if x not in local_tvs] + +# print(db_path) +# print(local_commercials) +# print(global_commercials["Commercials"]) +# print(commercial_removal) + + for commercial in commercial_removal: + sql = "DELETE FROM commercials WHERE customSectionName=?" + table.execute(sql,(commercial,)) + for movie in movie_removal: + sql = "DELETE FROM movies WHERE customSectionName=?" + table.execute(sql,(movie,)) + for tv in tv_removal: + sql = "DELETE FROM shows WHERE customSectionName=?" + table.execute(sql,(tv,)) + sql = "DELETE FROM episodes WHERE customSectionName=?" + table.execute(sql,(tv,)) + + conn.commit() + conn.close() + + os.chdir('..') + + print("+++++ " + db_path + " complete! Going to next file") + + +print("+++++ Global update COMPLETE") diff --git a/multi-channel-bash-scripts/README.md b/main-dir/README.md similarity index 100% rename from multi-channel-bash-scripts/README.md rename to main-dir/README.md diff --git a/multi-channel-bash-scripts/channeldown.sh b/main-dir/channeldown.sh old mode 100755 new mode 100644 similarity index 100% rename from multi-channel-bash-scripts/channeldown.sh rename to main-dir/channeldown.sh diff --git a/multi-channel-bash-scripts/channelup.sh b/main-dir/channelup.sh old mode 100755 new mode 100644 similarity index 100% rename from multi-channel-bash-scripts/channelup.sh rename to main-dir/channelup.sh diff --git a/multi-channel-bash-scripts/generate-channels-daily-schedules.sh b/main-dir/generate-channels-daily-schedules.sh old mode 100755 new mode 100644 similarity index 100% rename from multi-channel-bash-scripts/generate-channels-daily-schedules.sh rename to main-dir/generate-channels-daily-schedules.sh diff --git a/multi-channel-bash-scripts/manual.sh b/main-dir/manual.sh old mode 100755 new mode 100644 similarity index 100% rename from multi-channel-bash-scripts/manual.sh rename to main-dir/manual.sh diff --git a/plex_token-example.py b/main-dir/plex_token-example.py similarity index 100% rename from plex_token-example.py rename to main-dir/plex_token-example.py diff --git a/multi-channel-bash-scripts/stop-all-channels.sh b/main-dir/stop-all-channels.sh old mode 100755 new mode 100644 similarity index 100% rename from multi-channel-bash-scripts/stop-all-channels.sh rename to main-dir/stop-all-channels.sh diff --git a/multi-channel-bash-scripts/updatechannels.sh b/main-dir/updatechannels.sh old mode 100755 new mode 100644 similarity index 100% rename from multi-channel-bash-scripts/updatechannels.sh rename to main-dir/updatechannels.sh diff --git a/pseudo_config.py b/pseudo_config.py deleted file mode 100644 index 9f357d5..0000000 --- a/pseudo_config.py +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env python - -""" - 1) Create a file outside of this proj dir called "plex_token.py": - - touch ../plex_token.py - - 2) add these lines to the newly created file: - - baseurl = 'the url to your server' - token = 'your plex token' - - 3) Edit the "basurl" variable below to point to your Plex server - - 4) Edit the "plexClients" variable to include the name of your plex client(s) this app will control. - - 5) Edit the "plexLibraries" variable to remap your specific library names to the app specific names. - ...for instance, if your Plex "Movies" are located in your Plex library as "Films", update that - line so it looks like: - - "Movies" : ["Films"], - - 6) *Skip this feature for now* - - For Google Calendar integration add your "gkey" to the "plex_token.py" file - ...(https://docs.simplecalendar.io/find-google-calendar-id/): - - gkey = "the key" - - 7) If using the Google Calendar integration exclusively, set this to true below: - - useGoogleCalendar - -""" - -''' -* -* List of plex clients to use (add multiple clients to control multiple TV's) -* -''' -plexClients = ['RasPlex'] - -plexLibraries = { - "TV Shows" : ["TV"], - "Movies" : ["Films"], - "Commercials" : ["Commercials", "Smashing Pumpkins - Videos"], -} - -useCommercialInjection = True - -"""How many seconds to pad commercials between each other / other media""" -commercialPadding = 5 - -""" -Specify the path to this controller on the network (i.e. 'http://192.168.1.28' - no trailing slash). -Also specify the desired port to run the simple http webserver. The daily generated -schedule will be served at "http://:/" (i.e. "http://192.168.1.28:8000/"). - -You can also leave the below controllerServerPath empty if you'd like to run your own webserver. -""" -controllerServerPath = "http://192.168.1.28" -controllerServerPort = "8000" - -""" -This variable sets the title for the PseudoChannel.py html page. -""" -htmlPseudoTitle = "Daily PseudoChannel" - -""" -When the schedule updates every 24 hours, it's possible that it will interrupt any shows / movies that were -playing from the previous day. To fix this, the app saves a "cached" schedule from the previous day to -override any media that is trying to play while the previous day is finishing. -""" -useDailyOverlapCache = False - -dailyUpdateTime = "12:01 AM" - -"""When to delete / remake the pseudo-channel.log - right at midnight, (i.e. 'friday') """ -rotateLog = "friday" - -"""Debug mode will give you more output in your terminal to help problem solve issues.""" -debug_mode = True - -"""This squeezes in one last commercial to fill up the empty gaps even if the last commercial gets cutoff -Set this to false if you don't want your commercials to get cutoff/don't mind the gap. -""" -useDirtyGapFix = False - -""" -##### Do not edit below this line--------------------------------------------------------------- - -Below is logic to grab your Plex 'token' & Plex 'baseurl'. If you are following along and have created a 'plex_token.py' -file as instructed, you do not need to edit below this line. - -""" - -import os, sys -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -# import ../plex_token.py - -try: - import plex_token as plex_token -except ImportError as e: - print "+++++ Cannot find plex_token file. Make sure you create a plex_token.py file with the appropriate data." - raise e - -baseurl = plex_token.baseurl -token = plex_token.token -gkey = '' #plex_token.gkey \ No newline at end of file diff --git a/pseudo_schedule.xml b/pseudo_schedule.xml deleted file mode 100644 index b4145f5..0000000 --- a/pseudo_schedule.xml +++ /dev/null @@ -1,528 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/multi-channel-bash-scripts/update-channels-from-git.sh b/update-channels-from-git.sh old mode 100755 new mode 100644 similarity index 100% rename from multi-channel-bash-scripts/update-channels-from-git.sh rename to update-channels-from-git.sh