More progress on VideoService.py
This commit is contained in:
parent
be4aee2b27
commit
3a77d7c348
@ -14,6 +14,12 @@ def normalizePath(path):
|
|||||||
def doesFileExist(path):
|
def doesFileExist(path):
|
||||||
return os.path.isfile(path)
|
return os.path.isfile(path)
|
||||||
|
|
||||||
|
def getPathSeperator():
|
||||||
|
if platform.system() == 'Windows':
|
||||||
|
return "\\"
|
||||||
|
else:
|
||||||
|
return "/"
|
||||||
|
|
||||||
def doesFolderExist(path):
|
def doesFolderExist(path):
|
||||||
path = normalizePath(path)
|
path = normalizePath(path)
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
|
from Universal import ioservice
|
||||||
|
|
||||||
class TMDBService:
|
class TMDBService:
|
||||||
def __init__(self, loggingservice, ioservice):
|
def __init__(self, loggingservice):
|
||||||
self.report(2, "Initializing")
|
self.report(2, "Initializing")
|
||||||
try:
|
try:
|
||||||
import tmdbsimple
|
import tmdbsimple
|
||||||
self.tmdb = tmdbsimple
|
self.tmdb = tmdbsimple
|
||||||
self.report(2, "API Found")
|
self.report(2, "API Found")
|
||||||
self.logger = loggingservice
|
self.logger = loggingservice
|
||||||
self.ioservice = ioservice
|
|
||||||
self.enabled = True
|
self.enabled = True
|
||||||
self.tmdb_key = None
|
self.tmdb_key = None
|
||||||
self.addDefaultConfiguration()
|
self.addDefaultConfiguration()
|
||||||
@ -17,11 +18,11 @@ class TMDBService:
|
|||||||
self.connected = False
|
self.connected = False
|
||||||
|
|
||||||
def addDefaultConfiguration(self):
|
def addDefaultConfiguration(self):
|
||||||
self.ioservice.addConfiguration("TMDB Service", "TMDB API Key", "NONE")
|
ioservice.addConfiguration("TMDB Service", "TMDB API Key", "NONE")
|
||||||
|
|
||||||
def updateConfiguration(self):
|
def updateConfiguration(self):
|
||||||
if self.tmdb_key == None:
|
if self.tmdb_key == None:
|
||||||
self.tmdb_key = self.ioservice.getConfigurationStr("TMDB Service", "TMDB API Key")
|
self.tmdb_key = ioservice.getConfigurationStr("TMDB Service", "TMDB API Key")
|
||||||
|
|
||||||
def report(self, level, message):
|
def report(self, level, message):
|
||||||
match level:
|
match level:
|
||||||
@ -34,6 +35,13 @@ class TMDBService:
|
|||||||
case 3:
|
case 3:
|
||||||
self.logger.errorReport("[TMDB] " + message)
|
self.logger.errorReport("[TMDB] " + message)
|
||||||
|
|
||||||
|
def isEnabled(self):
|
||||||
|
return self.enabled
|
||||||
|
|
||||||
|
def isConnected(self):
|
||||||
|
self.report(2, "isConnected")
|
||||||
|
return self.connected
|
||||||
|
|
||||||
def connectToTMDB(self):
|
def connectToTMDB(self):
|
||||||
self.report(2, "connectToTMDB")
|
self.report(2, "connectToTMDB")
|
||||||
if not self.connected:
|
if not self.connected:
|
||||||
@ -50,10 +58,6 @@ class TMDBService:
|
|||||||
else:
|
else:
|
||||||
self.report(2, "Already connected")
|
self.report(2, "Already connected")
|
||||||
|
|
||||||
def isConnected(self):
|
|
||||||
self.report(2, "isConnected")
|
|
||||||
return self.connected
|
|
||||||
|
|
||||||
def searchMovies(self, name):
|
def searchMovies(self, name):
|
||||||
self.report(2, "searchMovies")
|
self.report(2, "searchMovies")
|
||||||
tmp_search = self.tmdb.Search()
|
tmp_search = self.tmdb.Search()
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
|
import os
|
||||||
|
import re
|
||||||
import time
|
import time
|
||||||
import default
|
import default
|
||||||
|
import subprocess
|
||||||
from Universal import ioservice
|
from Universal import ioservice
|
||||||
from Universal import loggingservice
|
from Universal import loggingservice
|
||||||
|
from Video.Services import tmdbservice
|
||||||
|
|
||||||
class VideoService:
|
class VideoService:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.logger = loggingservice.Output(True, False)
|
self.logger = loggingservice.Output(True, False)
|
||||||
self.video_settings = default.VideoSettings()
|
self.video_settings = default.VideoSettings()
|
||||||
|
self.tmdbservice = tmdbservice(self.logger)
|
||||||
self.video_settings.updateSettings()
|
self.video_settings.updateSettings()
|
||||||
|
|
||||||
def startNewProcess(self, num=1):
|
def startNewProcess(self, num=1):
|
||||||
@ -59,3 +63,130 @@ class VideoService:
|
|||||||
def processVideo(self):
|
def processVideo(self):
|
||||||
self.logger.debugReport("[Video] processVideo")
|
self.logger.debugReport("[Video] processVideo")
|
||||||
self.logger.infoReport("[Video] Current File: " + self.current_file)
|
self.logger.infoReport("[Video] Current File: " + self.current_file)
|
||||||
|
tmp_isDeleted = False
|
||||||
|
if not ioservice.checkSizeChange(self.current_file):
|
||||||
|
if ioservice.getFileSize(self.current_file) == 0:
|
||||||
|
self.logger.infoReport("[Video] Assuming file has been deleted or moved... Skipping...")
|
||||||
|
tmp_isDeleted = True
|
||||||
|
else:
|
||||||
|
self.logger.infoReport("[Video] File size has changed")
|
||||||
|
self.processVideo()
|
||||||
|
else:
|
||||||
|
tmp_success = True
|
||||||
|
if not tmp_isDeleted:
|
||||||
|
tmp_current_file_info = self.extractVideoInformation(self.current_file)
|
||||||
|
self.constructOutputPath()
|
||||||
|
|
||||||
|
def extractVideoInformation(self, file):
|
||||||
|
self.logger.debugReport("[Video] extractVideoInformation")
|
||||||
|
file = file.replace(self.video_settings.library["Input"], "").lstrip().replace("_", "")
|
||||||
|
for blacklist_item in self.video_settings.settings["Blacklist"].split(", "):
|
||||||
|
file = file.replace(blacklist_item, "")
|
||||||
|
tmp_input_format = file.rsplit(".", 1)[-1]
|
||||||
|
tmp_name = None
|
||||||
|
tmp_season = None
|
||||||
|
tmp_episode = None
|
||||||
|
tmp_episode_title = None
|
||||||
|
tmp_year = None
|
||||||
|
tmp_episode_year = None
|
||||||
|
tmp_length = self.getVideoLength()
|
||||||
|
tmp_folders, tmp_file = os.path.split(file)
|
||||||
|
for possible_years in re.findall(r'\d+', file):
|
||||||
|
if len(possible_years) == 4:
|
||||||
|
tmp_year = int(possible_years)
|
||||||
|
match len(tmp_folders.split(ioservice.getPathSeperator())):
|
||||||
|
case 1:
|
||||||
|
tmp_name = tmp_folders.split(ioservice.getPathSeperator())[0]
|
||||||
|
if not tmp_name:
|
||||||
|
tmp_name = tmp_file.replace(str(tmp_year), "").replace("." + tmp_input_format, "").strip()
|
||||||
|
case 2:
|
||||||
|
tmp_name = tmp_folders.split(ioservice.getPathSeperator())[0]
|
||||||
|
case 3:
|
||||||
|
tmp_name = tmp_folders.split(ioservice.getPathSeperator())[0]
|
||||||
|
case _:
|
||||||
|
tmp_name = tmp_file.replace("." + tmp_input_format, "")
|
||||||
|
if self.video_settings.library["Type"].lower().find("show") != -1:
|
||||||
|
if tmp_season is None or tmp_episode is None:
|
||||||
|
match len(tmp_folders.split(ioservice.getPathSeperator())):
|
||||||
|
case 2:
|
||||||
|
tmp_season = re.findall(r'\d+', tmp_folders.replace(tmp_name, ""))[0]
|
||||||
|
tmp_episode = re.findall(r'([0-9]*[0-9])', tmp_file.replace("." + tmp_input_format, "").replace(tmp_name, ""))[-1]
|
||||||
|
if tmp_file.lower().find(tmp_episode + "a") != -1:
|
||||||
|
tmp_episode = tmp_episode + " - Part 1"
|
||||||
|
elif tmp_file.lower().find(tmp_episode + "b") != -1:
|
||||||
|
tmp_episode = tmp_episode + " - Part 2"
|
||||||
|
case 3:
|
||||||
|
tmp_season = re.findall(r'\d+', tmp_folders.replace(tmp_name, ""))[0]
|
||||||
|
tmp_episode = re.findall(r'([0-9]*[0-9])', tmp_folders.replace("." + tmp_input_format, "").replace(tmp_name, ""))[-1]
|
||||||
|
if tmp_file.lower().find(tmp_episode + "a") != -1:
|
||||||
|
tmp_episode = tmp_episode + " - Part 1"
|
||||||
|
elif tmp_file.lower().find(tmp_episode + "b") != -1:
|
||||||
|
tmp_episode = tmp_episode + " - Part 2"
|
||||||
|
case _:
|
||||||
|
tmp_episode = re.findall(r'\d+', tmp_file.replace("." + tmp_input_format, "").replace(tmp_name, ""))[-1]
|
||||||
|
try:
|
||||||
|
tmp_season = re.findall(r'\d+', tmp_file.replace("." + tmp_input_format, "").replace(tmp_name, ""))[0]
|
||||||
|
except:
|
||||||
|
tmp_episode = re.findall(r'\d+', tmp_file.replace("." + tmp_input_format, ""))[-1]
|
||||||
|
if tmp_season != "0" and tmp_season:
|
||||||
|
tmp_season = tmp_season.lstrip("0")
|
||||||
|
if tmp_episode != "0" and tmp_episode:
|
||||||
|
tmp_episode = tmp_episode.lstrip("0")
|
||||||
|
match self.video_settings.library["Database"].lower():
|
||||||
|
case "tmdb":
|
||||||
|
if self.tmdbservice.isEnabled():
|
||||||
|
self.tmdbservice.connectToTMDB()
|
||||||
|
if self.video_settings.library["Type"].lower().find("movie") != -1:
|
||||||
|
tmp_name = tmp_name.replace(str(tmp_year), "").replace("(", "").replace(")", "")
|
||||||
|
if tmp_length is not None or tmp_year is not None:
|
||||||
|
tmp_data = self.tmdbservice.getBestMovie(tmp_name, tmp_length, tmp_year)
|
||||||
|
if tmp_data:
|
||||||
|
tmp_name = tmp_data[0]
|
||||||
|
tmp_year = tmp_data[2]
|
||||||
|
else:
|
||||||
|
tmp_data = self.tmdbservice.searchMovies(tmp_name)
|
||||||
|
tmp_name = tmp_data[0][0]
|
||||||
|
tmp_year = tmp_data[0][1]
|
||||||
|
elif self.video_settings.library["Type"].lower().find("show") != -1:
|
||||||
|
tmp_data = self.tmdbservice.getShowName(tmp_name)
|
||||||
|
tmp_name = tmp_data["name"]
|
||||||
|
tmp_year = tmp_data["first_air_date"][:4]
|
||||||
|
case "tvdb":
|
||||||
|
#NotImplemented
|
||||||
|
pass
|
||||||
|
case _:
|
||||||
|
pass
|
||||||
|
tmp_name = tmp_name.replace(":", "")
|
||||||
|
if tmp_episode_title:
|
||||||
|
tmp_episode_title = tmp_episode_title.replace(":", "")
|
||||||
|
return {"Name": tmp_name, "Season": tmp_season, "Episode": tmp_episode, "Episode Title": tmp_episode_title, "Episode Year": tmp_episode_year, "Input Format": tmp_input_format}
|
||||||
|
|
||||||
|
def constructOutputPath(self, subtitles=False, num=0):
|
||||||
|
self.logger.debugReport("[Video] constructOutputPath")
|
||||||
|
### TODO: Implement this next
|
||||||
|
|
||||||
|
def getVideoLength(self):
|
||||||
|
self.logger.debugReport("[Video] getVideoLength")
|
||||||
|
tmp_time = None
|
||||||
|
try:
|
||||||
|
tmp_time = subprocess.check_output([self.video_settings.settings["FFProbe"], '-i', self.current_file, '-show_entries', 'format=duration', '-v', 'quiet', '-of', 'csv=%s' % ("p=0")])
|
||||||
|
tmp_time = str(tmp_time)
|
||||||
|
if not tmp_time.find("N/A") != -1:
|
||||||
|
tmp_hours = time.strftime("%H", time.gmtime(round(float(re.findall('\d+', tmp_time)[0])))).lstrip("0")
|
||||||
|
tmp_minutes = time.strftime("%M", time.gmtime(round(float(re.findall('\d+', tmp_time)[0])))).lstrip("0")
|
||||||
|
try:
|
||||||
|
tmp_hours = int(tmp_hours) * 60
|
||||||
|
except:
|
||||||
|
tmp_hours = 0
|
||||||
|
try:
|
||||||
|
tmp_length = tmp_hours + int(tmp_minutes)
|
||||||
|
except:
|
||||||
|
tmp_length = tmp_hours
|
||||||
|
else:
|
||||||
|
self.logger.errorReport("[Video] FFProbe could not get video content length")
|
||||||
|
tmp_length = None
|
||||||
|
return tmp_length
|
||||||
|
except:
|
||||||
|
self.logger.errorReport("[Video] There was a problem getting the length of video content")
|
||||||
|
return None
|
||||||
|
|
Loading…
Reference in New Issue
Block a user