mirror of
https://github.com/FakeTV/pseudo-channel.git
synced 2025-12-11 05:43:33 +00:00
Global_DatabaseUpdate Quick Fix
At the request of some, I have modified the Global_DatabaseUpdate file to import the previous database's daily_schedule. NOTE: If you end up experiencing issues with your shows playing, this may be because your new database does not have the resources to play the listed shows. May be time to run -g at that point.
This commit is contained in:
@@ -1,107 +1,118 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
Created on Thu Jun 28 17:33:59 2018
|
Created on Thu Jun 28 17:33:59 2018
|
||||||
|
|
||||||
@author: Matt
|
@author: Matt
|
||||||
"""
|
"""
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import os
|
import os
|
||||||
from shutil import copy2
|
from shutil import copy2
|
||||||
from pseudo_config import plexLibraries as global_commercials
|
from pseudo_config import plexLibraries as global_commercials
|
||||||
|
|
||||||
channel_dir_increment_symbol = "_"
|
channel_dir_increment_symbol = "_"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Step ONE: Global database update
|
# Step ONE: Global database update
|
||||||
print("+++++ Doing global update from PLEX")
|
print("+++++ Doing global update from PLEX")
|
||||||
os.system('sudo python PseudoChannel.py -u')
|
os.system('sudo python PseudoChannel.py -u')
|
||||||
|
|
||||||
|
|
||||||
base_dirA = os.path.dirname(os.path.abspath(__file__))
|
base_dirA = os.path.dirname(os.path.abspath(__file__))
|
||||||
locations = "pseudo-channel"+channel_dir_increment_symbol
|
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 = [ 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))
|
channel_dirs = list(filter(lambda x: x.startswith(locations),channel_dirs))
|
||||||
|
|
||||||
for channel_dir in channel_dirs:
|
for channel_dir in channel_dirs:
|
||||||
# Step TWO: Go to each folder, export the following information
|
# Step TWO: Go to each folder, export the following information
|
||||||
# - Show title, lastEpisodeTitle
|
# - Show title, lastEpisodeTitle
|
||||||
# - Movie title, lastPlayedDate
|
# - Movie title, lastPlayedDate
|
||||||
os.chdir(channel_dir)
|
# - Daily schedule currently being executed
|
||||||
|
os.chdir(channel_dir)
|
||||||
channel_dirA = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
db_path = os.path.join(channel_dirA, "pseudo-channel.db")
|
channel_dirA = os.path.dirname(os.path.abspath(__file__))
|
||||||
print("+++++ Importing from " + db_path)
|
db_path = os.path.join(channel_dirA, "pseudo-channel.db")
|
||||||
try:
|
print("+++++ Importing from " + db_path)
|
||||||
conn = sqlite3.connect(db_path)
|
|
||||||
table = conn.cursor()
|
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()
|
lastEpisode_export = table.execute('SELECT lastEpisodeTitle,title FROM shows').fetchall()
|
||||||
lastMovie_export = list(lastMovie_export)
|
lastEpisode_export = list(lastEpisode_export)
|
||||||
|
lastMovie_export = table.execute('SELECT lastPlayedDate,title FROM movies').fetchall()
|
||||||
conn.commit()
|
lastMovie_export = list(lastMovie_export)
|
||||||
conn.close()
|
|
||||||
except:
|
daily_schedule = table.execute('SELECT * FROM daily_schedule').fetchall()
|
||||||
print("+++++ Database experiencing errors or hasn't been formed yet; creating fresh one")
|
|
||||||
lastEpisode_export = []
|
|
||||||
lastMovie_export = []
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
# Step THREE: Delete the previous database, replace with the recently created global one
|
except:
|
||||||
print("+++++ Copying global update to " + db_path)
|
print("+++++ Database experiencing errors or hasn't been formed yet; creating fresh one")
|
||||||
copy2('../pseudo-channel.db','.')
|
lastEpisode_export = []
|
||||||
|
lastMovie_export = []
|
||||||
|
|
||||||
# Step FOUR: Import the previous information we exported previously
|
|
||||||
print("+++++ Exporting to " + db_path)
|
# Step THREE: Delete the previous database, replace with the recently created global one
|
||||||
conn = sqlite3.connect(db_path)
|
print("+++++ Copying global update to " + db_path)
|
||||||
table = conn.cursor()
|
copy2('../pseudo-channel.db','.')
|
||||||
|
|
||||||
for i in range(0,len(lastEpisode_export)):
|
|
||||||
sql = "UPDATE shows SET lastEpisodeTitle=? WHERE title=?"
|
# Step FOUR: Import the previous information we exported previously
|
||||||
table.execute(sql,lastEpisode_export[i])
|
print("+++++ Exporting to " + db_path)
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
for i in range(0,len(lastMovie_export)):
|
table = conn.cursor()
|
||||||
sql = "UPDATE movies SET lastPlayedDate=? WHERE title=?"
|
|
||||||
table.execute(sql,lastMovie_export[i])
|
for i in range(0,len(lastEpisode_export)):
|
||||||
|
sql = "UPDATE shows SET lastEpisodeTitle=? WHERE title=?"
|
||||||
# Step FIVE: Remove any media not in the directories set of commerical archives
|
table.execute(sql,lastEpisode_export[i])
|
||||||
print("+++++ Trimming database at " + db_path)
|
|
||||||
os.system('sudo python report_MediaFolders.py')
|
for i in range(0,len(lastMovie_export)):
|
||||||
local_commercials = open('Commercial_Libraries.txt').read().splitlines()
|
sql = "UPDATE movies SET lastPlayedDate=? WHERE title=?"
|
||||||
local_movies = open('Movie_Libraries.txt').read().splitlines()
|
table.execute(sql,lastMovie_export[i])
|
||||||
local_tvs = open('TV_Libraries.txt').read().splitlines()
|
|
||||||
|
for i in range(0,len(daily_schedule)):
|
||||||
commercial_removal = [x for x in global_commercials["Commercials"] if x not in local_commercials]
|
sql = "INSERT INTO daily_schedule(id,unix,mediaID,title,episodeNumber,seasonNumber,showTitle,duration,startTime,endTime,dayOfWeek,sectionType,plexMediaID,customSectionName) \
|
||||||
movie_removal = [x for x in global_commercials["Movies"] if x not in local_movies]
|
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
||||||
tv_removal = [x for x in global_commercials["TV Shows"] if x not in local_tvs]
|
table.execute(sql,daily_schedule[i])
|
||||||
|
|
||||||
# print(db_path)
|
|
||||||
# print(local_commercials)
|
# Step FIVE: Remove any media not in the directories set of commerical archives
|
||||||
# print(global_commercials["Commercials"])
|
print("+++++ Trimming database at " + db_path)
|
||||||
# print(commercial_removal)
|
os.system('sudo python report_MediaFolders.py')
|
||||||
|
local_commercials = open('Commercial_Libraries.txt').read().splitlines()
|
||||||
for commercial in commercial_removal:
|
local_movies = open('Movie_Libraries.txt').read().splitlines()
|
||||||
sql = "DELETE FROM commercials WHERE customSectionName=?"
|
local_tvs = open('TV_Libraries.txt').read().splitlines()
|
||||||
table.execute(sql,(commercial,))
|
|
||||||
for movie in movie_removal:
|
commercial_removal = [x for x in global_commercials["Commercials"] if x not in local_commercials]
|
||||||
sql = "DELETE FROM movies WHERE customSectionName=?"
|
movie_removal = [x for x in global_commercials["Movies"] if x not in local_movies]
|
||||||
table.execute(sql,(movie,))
|
tv_removal = [x for x in global_commercials["TV Shows"] if x not in local_tvs]
|
||||||
for tv in tv_removal:
|
|
||||||
sql = "DELETE FROM shows WHERE customSectionName=?"
|
# print(db_path)
|
||||||
table.execute(sql,(tv,))
|
# print(local_commercials)
|
||||||
sql = "DELETE FROM episodes WHERE customSectionName=?"
|
# print(global_commercials["Commercials"])
|
||||||
table.execute(sql,(tv,))
|
# print(commercial_removal)
|
||||||
|
|
||||||
conn.commit()
|
for commercial in commercial_removal:
|
||||||
conn.close()
|
sql = "DELETE FROM commercials WHERE customSectionName=?"
|
||||||
|
table.execute(sql,(commercial,))
|
||||||
os.chdir('..')
|
for movie in movie_removal:
|
||||||
|
sql = "DELETE FROM movies WHERE customSectionName=?"
|
||||||
print("+++++ " + db_path + " complete! Going to next file")
|
table.execute(sql,(movie,))
|
||||||
|
for tv in tv_removal:
|
||||||
|
sql = "DELETE FROM shows WHERE customSectionName=?"
|
||||||
print("+++++ Global update COMPLETE")
|
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")
|
||||||
|
|||||||
Reference in New Issue
Block a user