mirror of
https://github.com/FakeTV/pseudo-channel.git
synced 2025-12-15 15:53:50 +00:00
setup fixes
This commit is contained in:
154
setup.py
154
setup.py
@@ -27,16 +27,18 @@ def execfile(filename, globals=None, locals=None):
|
|||||||
|
|
||||||
def get_channels(channelsDir='.'):
|
def get_channels(channelsDir='.'):
|
||||||
#get list of available channels and arrange in numerical order
|
#get list of available channels and arrange in numerical order
|
||||||
dirList = sorted(next(os.walk('.'))[1])
|
dirList = sorted(os.listdir(channelsDir))
|
||||||
chanList = ['all',]
|
chanList = ['all',]
|
||||||
channelsList = []
|
channelsList = []
|
||||||
for dir in dirList:
|
for dir in dirList:
|
||||||
if "pseudo-channel_" in dir:
|
if "pseudo-channel_" in dir:
|
||||||
chanList.append(dir)
|
chanList.append(dir)
|
||||||
for chan in chanList:
|
for chan in chanList:
|
||||||
|
try:
|
||||||
channelNumber = chan.split('_')
|
channelNumber = chan.split('_')
|
||||||
channelNumber = channelNumber[1]
|
channelsList.append(channelNumber[1])
|
||||||
channelsList.append(channelNumber)
|
except:
|
||||||
|
do = "nothing"
|
||||||
return channelsList
|
return channelsList
|
||||||
|
|
||||||
def ps_install(ps_branch='python3', path='./channels'):
|
def ps_install(ps_branch='python3', path='./channels'):
|
||||||
@@ -44,16 +46,22 @@ def ps_install(ps_branch='python3', path='./channels'):
|
|||||||
if dirCheck == False:
|
if dirCheck == False:
|
||||||
os.mkdir('channels')
|
os.mkdir('channels')
|
||||||
dirList = os.listdir(path)
|
dirList = os.listdir(path)
|
||||||
if 'pseudo-channel_' in dirList:
|
installExists = False
|
||||||
|
for item in dirList:
|
||||||
|
if 'pseudo-channel_' in item:
|
||||||
|
installExists = True
|
||||||
|
else:
|
||||||
|
installExists = False
|
||||||
|
if installExists == True:
|
||||||
print("CHANNELS DETECTED! Running Update")
|
print("CHANNELS DETECTED! Running Update")
|
||||||
ps_update(branch)
|
ps_update(ps_branch)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
else:
|
else:
|
||||||
print("Directory "+path+" is empty. Setting up Pseudo Channel here...")
|
print("Directory "+path+" is empty. Setting up Pseudo Channel here...")
|
||||||
os.chdir(path)
|
os.chdir(path)
|
||||||
os.mkdir('temp') #create temp directory to download files into
|
os.mkdir('temp') #create temp directory to download files into
|
||||||
try:
|
try:
|
||||||
git.Repo.clone_from('https://github.com/FakeTV/pseudo-channel', './temp', branch=ps_branch, progress=CloneProgress())
|
git.Repo.clone_from('https://github.com/FakeTV/pseudo-channel', './temp', branch=ps_branch)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("ERROR GETTING DOWNLOADING FROM GIT")
|
print("ERROR GETTING DOWNLOADING FROM GIT")
|
||||||
print("e")
|
print("e")
|
||||||
@@ -61,17 +69,29 @@ def ps_install(ps_branch='python3', path='./channels'):
|
|||||||
mainFiles = glob.glob('./temp/main-dir/*')
|
mainFiles = glob.glob('./temp/main-dir/*')
|
||||||
bothFiles = glob.glob('./temp/both-dir/*')
|
bothFiles = glob.glob('./temp/both-dir/*')
|
||||||
srcFiles = glob.glob('./temp/both-dir/src/*')
|
srcFiles = glob.glob('./temp/both-dir/src/*')
|
||||||
os.mkdir('pseudo-channel_01') #create channel 1 directory
|
chanFiles = glob.glob('./temp/channel-dir/*')
|
||||||
|
chan1Dir = 'pseudo-channel_01'
|
||||||
|
os.mkdir(chan1Dir) #create channel 1 directory
|
||||||
os.mkdir('src')
|
os.mkdir('src')
|
||||||
os.mkdir('pseudo-channel_01/src')
|
os.mkdir(chan1Dir+'/src')
|
||||||
for file in mainFiles: #copy files from temp directory into ./ and channel 1
|
for file in mainFiles: #copy files from temp directory into ./ and channel 1
|
||||||
shutil.copy(file, './')
|
shutil.copy(file, './')
|
||||||
|
for file in chanFiles:
|
||||||
|
shutil.copy(file, './'+chan1Dir)
|
||||||
for file in bothFiles:
|
for file in bothFiles:
|
||||||
|
try:
|
||||||
shutil.copy(file, './')
|
shutil.copy(file, './')
|
||||||
shutil.copy(file, './pseudo-channel_01')
|
except:
|
||||||
|
do = "nothing"
|
||||||
|
try:
|
||||||
|
shutil.copy(file, './'+chan1Dir)
|
||||||
|
except:
|
||||||
|
do = "nothing"
|
||||||
for file in srcFiles:
|
for file in srcFiles:
|
||||||
shutil.copy(file, './src')
|
shutil.copy(file, './src')
|
||||||
shutil.copy(file, './pseudo-channel_01/src')
|
shutil.copy(file, './'+chan1Dir+'/src')
|
||||||
|
shutil.rmtree('./temp')
|
||||||
|
print("Temp Files Deleted")
|
||||||
#get number of desired channels
|
#get number of desired channels
|
||||||
print("Enter desired number of channels")
|
print("Enter desired number of channels")
|
||||||
numberofchannels = input(">:")
|
numberofchannels = input(">:")
|
||||||
@@ -82,30 +102,34 @@ def ps_install(ps_branch='python3', path='./channels'):
|
|||||||
newdirname = newdirname + "0"
|
newdirname = newdirname + "0"
|
||||||
n = n-1
|
n = n-1
|
||||||
newdirname = newdirname + "1"
|
newdirname = newdirname + "1"
|
||||||
os.rename('pseudo-channel_01',newdirname)
|
os.rename(chan1Dir,newdirname)
|
||||||
|
chan1Dir = newdirname
|
||||||
ch = 2
|
ch = 2
|
||||||
while ch <= int(numberofchannels): #copy channel 1 into remaining channels
|
while ch <= int(numberofchannels): #copy channel 1 into remaining channels
|
||||||
chNumber = str(ch).zfill(len(str(numberofchannels)))
|
chNumber = str(ch).zfill(len(str(numberofchannels)))
|
||||||
chPrefix = 'pseudo-channel_'
|
chPrefix = 'pseudo-channel_'
|
||||||
shutil.copytree('pseudo-channel_01', chPrefix+chNumber)
|
shutil.copytree(chan1Dir, chPrefix+chNumber)
|
||||||
ch = ch + 1
|
ch = ch + 1
|
||||||
print("ENTER THE PLEX SERVER URL") #get variable values and edit token and config files
|
print("ENTER THE PLEX SERVER URL") #get variable values and edit token and config files
|
||||||
baseurl = 'http://'+input('http://')
|
baseurl = input('http://')
|
||||||
|
print(baseurl)
|
||||||
try:
|
try:
|
||||||
baseSplit = baseurl.split(':')
|
baseSplit = baseurl.split(':')
|
||||||
|
baseport = baseSplit[1]
|
||||||
except:
|
except:
|
||||||
print("ENTER THE PORT NUMBER FOR THE PLEX SERVER (default: 32400")
|
print("ENTER THE PORT NUMBER FOR THE PLEX SERVER (default: 32400)")
|
||||||
baseport = input('>:')
|
baseport = input('>: ')
|
||||||
if baseport == '':
|
if baseport == '':
|
||||||
baseport = "32400"
|
baseport = "32400"
|
||||||
baseurl = baseurl + baseport
|
baseurl = baseurl + ":" + baseport
|
||||||
|
baseurl = 'http://'+baseurl
|
||||||
print("ENTER YOUR PLEX TOKEN")
|
print("ENTER YOUR PLEX TOKEN")
|
||||||
token = input('>:')
|
token = input('>:')
|
||||||
f = open('plex_token.py', 'w+')
|
f = open('plex_token.py', 'w+')
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
f.write("#PLEX TOKEN FILE GENERATED "+now.strftime("%Y.%m.%d %H:%M:%S"))
|
f.write("#PLEX TOKEN FILE GENERATED "+now.strftime("%Y.%m.%d %H:%M:%S"))
|
||||||
f.write("token = "+token)
|
f.write("\ntoken = '"+token+"'")
|
||||||
f.write("baseurl = "+baseurl)
|
f.write("\nbaseurl = '"+baseurl+"'")
|
||||||
f.close()
|
f.close()
|
||||||
PLEX = PlexServer(baseurl, token)
|
PLEX = PlexServer(baseurl, token)
|
||||||
print("SELECT CLIENT TO SEND PLAYBACK TO:")
|
print("SELECT CLIENT TO SEND PLAYBACK TO:")
|
||||||
@@ -116,7 +140,7 @@ def ps_install(ps_branch='python3', path='./channels'):
|
|||||||
clientList.append(client.title)
|
clientList.append(client.title)
|
||||||
clientNumbers.append(i + 1)
|
clientNumbers.append(i + 1)
|
||||||
selectedClient = input('>:')
|
selectedClient = input('>:')
|
||||||
while selectedClient not in clientNumbers:
|
while int(selectedClient) not in clientNumbers:
|
||||||
print("ERROR: INPUT OUTSIDE OF RANGE")
|
print("ERROR: INPUT OUTSIDE OF RANGE")
|
||||||
selectedClient = input('>:')
|
selectedClient = input('>:')
|
||||||
ps_client = clientList[int(selectedClient)-1]
|
ps_client = clientList[int(selectedClient)-1]
|
||||||
@@ -126,67 +150,90 @@ def ps_install(ps_branch='python3', path='./channels'):
|
|||||||
showsSections = []
|
showsSections = []
|
||||||
moviesSections = []
|
moviesSections = []
|
||||||
commercialsSections = []
|
commercialsSections = []
|
||||||
for section in sections:
|
sys.stdout.flush()
|
||||||
sys.stdout.write("\033[K")
|
sys.stdout.write("\033[K")
|
||||||
sys.stdout.write("Scanning Libraries... ["+section.title+"]")
|
sys.stdout.write("\rScanning Libraries...")
|
||||||
|
for section in sections:
|
||||||
|
sys.stdout.write(".")
|
||||||
if section.scanner == "Plex Series Scanner":
|
if section.scanner == "Plex Series Scanner":
|
||||||
showsSections.append(section.title)
|
showsSections.append(section.title)
|
||||||
elif section.scanner == "Plex Movie Scanner":
|
elif section.scanner == "Plex Movie Scanner":
|
||||||
moviesSections.append(section.title)
|
moviesSections.append(section.title)
|
||||||
elif section.scanner == "Plex Video Files Scanner":
|
elif section.scanner == "Plex Video Files Scanner":
|
||||||
commercialsSections.append(section.title)
|
commercialsSections.append(section.title)
|
||||||
sys.stdout.write("\033[K")
|
print("\nSelect TV Show Libraries (separate multiple entries with a comma or enter 'all')")
|
||||||
print("Select TV Show Libraries (separate multiple entries with a comma or enter 'all')")
|
|
||||||
ps_showslibraries = select_libs(showsSections)
|
ps_showslibraries = select_libs(showsSections)
|
||||||
print("Select Movies Libraries (separate multiple entries with a comma or enter 'all')")
|
print("Select Movies Libraries (separate multiple entries with a comma or enter 'all')")
|
||||||
ps_movieslibraries = select_libs(moviesSections)
|
ps_movieslibraries = select_libs(moviesSections)
|
||||||
print("Use Commercial Injection? (Y/N)")
|
print("Use Commercial Injection? (Y/N)")
|
||||||
use_commercials = input('Y/N >:')
|
use_commercials = input('Y/N >: ')
|
||||||
responses = ['yes','y','n','no']
|
responses = ['yes','y','n','no']
|
||||||
while use_commercials.lower() not in responses:
|
while use_commercials.lower() not in responses:
|
||||||
print("INVALID ENTRY")
|
print("INVALID ENTRY")
|
||||||
use_commercials = input('Y/N >:')
|
use_commercials = input('Y/N >: ')
|
||||||
if 'y' in use_commercials.lower():
|
if 'y' in use_commercials.lower():
|
||||||
print("Select Commercials Libraries (separate multiple entries with a comma or enter 'all')")
|
print("Select Commercials Libraries (separate multiple entries with a comma or enter 'all')")
|
||||||
ps_commercialslibraries = select_libs(commercialsSections)
|
ps_commercialslibraries = select_libs(commercialsSections)
|
||||||
print("Enter number of seconds to pad between commercials and other media")
|
print("Enter number of seconds to pad between commercials and other media")
|
||||||
commercialPadding = input('>:')
|
commercialPadding = input('>: ')
|
||||||
if commercialPadding == '':
|
if commercialPadding == '':
|
||||||
commercialPadding = 0
|
commercialPadding = 0
|
||||||
try:
|
try:
|
||||||
commercialPadding = int(commercialPadding)
|
commercialPadding = int(commercialPadding)
|
||||||
except:
|
except:
|
||||||
print("INVALID ENTRY")
|
print("INVALID ENTRY")
|
||||||
commercialPadding = input('>:')
|
commercialPadding = input('>: ')
|
||||||
print("Enter desired daily schedule reset time using H:MM time formatting (ideally this should be a time when someone would be least likely to be watching)")
|
print("Enter desired reset hour (between 0 and 23)")
|
||||||
dailyUpdateTime = input('>:')
|
print("Ideally this should be a time when someone would be least likely to be watching.")
|
||||||
|
dailyUpdateTime = input('>: ')
|
||||||
|
while int(dailyUpdateTime) > 23:
|
||||||
|
print("INVALID ENTRY: Enter a number between 0 and 23")
|
||||||
|
dailyUpdateTime = input('>: ')
|
||||||
|
dailyUpdateTime = dailyUpdateTime+':00'
|
||||||
# write to config file
|
# write to config file
|
||||||
configFile = open("pseudo_config.py", 'w+')
|
configFile = open("pseudo_config.py", 'r')
|
||||||
configData = configFile.read()
|
configData = configFile.read()
|
||||||
configData = configData.replace("plexClients = []", "plexClients = ["+ps_client+"]")
|
configFile = open("pseudo_config.py", 'w')
|
||||||
configData = configData.replace("\"TV Shows\" : []", "\"TV Shows\" : "+ps_showslibraries)
|
configData = configData.replace("plexClients = []", "plexClients = [\'"+ps_client+"\']")
|
||||||
configData = configData.replace("\"Movies\" : []", "\"Movies\" : "+ps_movieslibraries)
|
configData = configData.replace("\"TV Shows\" : []", "\"TV Shows\" : "+str(ps_showslibraries))
|
||||||
|
configData = configData.replace("\"Movies\" : []", "\"Movies\" : "+str(ps_movieslibraries))
|
||||||
if 'y' in use_commercials.lower():
|
if 'y' in use_commercials.lower():
|
||||||
configData = configData.replace("\"Commercials\" : []", "\"Commercials\" : "+ps_commercialslibraries)
|
configData = configData.replace("\"Commercials\" : []", "\"Commercials\" : "+str(ps_commercialslibraries))
|
||||||
configData = configData.replace("commercialPadding = 1", "commercialPadding = "+commercialPadding)
|
configData = configData.replace("commercialPadding = 1", "commercialPadding = "+str(commercialPadding))
|
||||||
else:
|
else:
|
||||||
configData = configData.replace("useCommercialInjection = True", "useCommercialInjection = False")
|
configData = configData.replace("useCommercialInjection = True", "useCommercialInjection = False")
|
||||||
configData = configData.replace("dailyUpdateTime = \"\"", "dailyUpdateTime = \""+dailyUpdateTime+"\"")
|
configData = configData.replace("dailyUpdateTime = \"\"", "dailyUpdateTime = \""+dailyUpdateTime+"\"")
|
||||||
configFile.write(configData)
|
configFile.write(configData)
|
||||||
configFile.close()
|
configFile.close()
|
||||||
copyconfig()
|
copyconfig()
|
||||||
|
global_database_update()
|
||||||
|
|
||||||
|
def global_database_update():
|
||||||
|
import Global_DatabaseUpdate
|
||||||
|
'''process = subprocess.Popen(["python", "-u", "Global_DatabaseUpdate.py", "-u"], 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()'''
|
||||||
|
|
||||||
def select_libs(sectionsList):
|
def select_libs(sectionsList):
|
||||||
x = 1
|
x = 1
|
||||||
for section in sectionsList:
|
for section in sectionsList:
|
||||||
print(str(x)+": "+section)
|
print(str(x)+": "+section)
|
||||||
x+1
|
x=x+1
|
||||||
libraries = input('>:')
|
libraries = input('>: ')
|
||||||
go = 0
|
go = 0
|
||||||
if libraries == "all":
|
|
||||||
ps_libraries = sectionsList
|
|
||||||
else:
|
|
||||||
ps_libraries = []
|
ps_libraries = []
|
||||||
|
if libraries.lower() == "all":
|
||||||
|
for lib in sectionsList:
|
||||||
|
ps_libraries.append(lib)
|
||||||
|
elif libraries == '':
|
||||||
|
for lib in sectionsList:
|
||||||
|
ps_libraries.append(lib)
|
||||||
|
else:
|
||||||
while go != 1:
|
while go != 1:
|
||||||
try:
|
try:
|
||||||
libList = libraries.split(',')
|
libList = libraries.split(',')
|
||||||
@@ -218,29 +265,23 @@ def copyconfig(channel="all"):
|
|||||||
channelsList = get_channels()
|
channelsList = get_channels()
|
||||||
try:
|
try:
|
||||||
channel = int(channel)
|
channel = int(channel)
|
||||||
sys.stdout.write("\033[K")
|
|
||||||
sys.stdout.write("Copying config to channel "+channelsList[channel])
|
|
||||||
chanDir = "pseudo-channel_"+channelsList[channel]
|
chanDir = "pseudo-channel_"+channelsList[channel]
|
||||||
shutil.copy('./pseudo_config.py', chanDir)
|
shutil.copy('./pseudo_config.py', chanDir)
|
||||||
except:
|
except:
|
||||||
for chan in channelsList:
|
for chan in channelsList:
|
||||||
if chan != "all":
|
if chan != "all":
|
||||||
sys.stdout.write("\033[K")
|
|
||||||
sys.stdout.write("Copying config to channel "+chan)
|
|
||||||
chanDir = "pseudo-channel_"+str(chan)+'/'
|
chanDir = "pseudo-channel_"+str(chan)+'/'
|
||||||
shutil.copy('./pseudo_config.py', chanDir)
|
shutil.copy('./pseudo_config.py', chanDir)
|
||||||
|
|
||||||
def copy_tv(client):
|
|
||||||
#make symlinked copy of pseudo channel files to run on another client
|
def copy_tv(client=None):
|
||||||
print("copy_tv")
|
print("copy_tv") #make symlinked copy of pseudo channel files to run on another client
|
||||||
|
|
||||||
def ps_update(branch='main'):
|
def ps_update(branch='main'):
|
||||||
#download and copy updates from git to all branches and boxes
|
print("ps_update") #download and copy updates from git to all branches and boxes
|
||||||
print("ps_update")
|
|
||||||
|
|
||||||
def web_setup(branch='main'):
|
def web_setup(branch='main'):
|
||||||
#set up the web interface and api
|
print("web_setup") #set up the web interface and api
|
||||||
print("web_setup")
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Pseudo Channel Controls')
|
parser = argparse.ArgumentParser(description='Pseudo Channel Controls')
|
||||||
try:
|
try:
|
||||||
@@ -262,6 +303,9 @@ parser.add_argument('-u', '--update',
|
|||||||
parser.add_argument('-w', '--web',
|
parser.add_argument('-w', '--web',
|
||||||
choices = ['main','dev'],
|
choices = ['main','dev'],
|
||||||
help='Install and Set Up Web Interface and API')
|
help='Install and Set Up Web Interface and API')
|
||||||
|
parser.add_argument('-ud', '--updatedatabase',
|
||||||
|
action='store_true',
|
||||||
|
help='Generate Pseudo Channel Database')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@@ -277,10 +321,12 @@ if args.copyconfig:
|
|||||||
copyconfig()
|
copyconfig()
|
||||||
if args.tv:
|
if args.tv:
|
||||||
print("SETTING UP PSUEDO CHANNEL FOR CLIENT "+str(args.tv))
|
print("SETTING UP PSUEDO CHANNEL FOR CLIENT "+str(args.tv))
|
||||||
copy_tv(args.tv)
|
#copy_tv(args.tv)
|
||||||
if args.update:
|
if args.update:
|
||||||
print("UPDATING PSEUDO CHANNEL FROM GIT BRANCH "+str(args.update))
|
print("UPDATING PSEUDO CHANNEL FROM GIT BRANCH "+str(args.update))
|
||||||
ps_update(args.update)
|
#ps_update(args.update)
|
||||||
if args.web:
|
if args.web:
|
||||||
print("SETTING UP PSEUDO CHANNEL WEB INTERFACE AND API FROM GIT BRANCH "+str(args.web))
|
print("SETTING UP PSEUDO CHANNEL WEB INTERFACE AND API FROM GIT BRANCH "+str(args.web))
|
||||||
web_setup(args.web)
|
#web_setup(args.web)
|
||||||
|
if args.updatedatabase:
|
||||||
|
global_database_update()
|
||||||
Reference in New Issue
Block a user