I forgot what i did. Been awhile
This commit is contained in:
parent
092d48bca2
commit
b1c43da994
@ -42,8 +42,8 @@ class TMDBService:
|
||||
self.report(2, "isConnected")
|
||||
return self.connected
|
||||
|
||||
def connectToTMDB(self):
|
||||
self.report(2, "connectToTMDB")
|
||||
def connectToService(self):
|
||||
self.report(2, "connectToService")
|
||||
if not self.connected:
|
||||
try:
|
||||
self.report(2, "Attempting to Login")
|
||||
@ -58,8 +58,8 @@ class TMDBService:
|
||||
else:
|
||||
self.report(2, "Already connected")
|
||||
|
||||
def searchMovies(self, name):
|
||||
self.report(2, "searchMovies")
|
||||
def searchMovie(self, name):
|
||||
self.report(2, "searchMovie")
|
||||
tmp_search = self.tmdb.Search()
|
||||
tmp_response = tmp_search.movie(query=name)
|
||||
tmp_list = []
|
||||
@ -68,17 +68,17 @@ class TMDBService:
|
||||
try:
|
||||
tmp_releasedate = movie['release_date']
|
||||
except:
|
||||
tmp_releasedate = "9999"
|
||||
tmp_releasedate = 9999
|
||||
if not tmp_runtime or tmp_runtime is None:
|
||||
tmp_runtime = "0"
|
||||
tmp_runtime = 0
|
||||
if not tmp_releasedate or tmp_releasedate is None:
|
||||
tmp_releasedate = "9999"
|
||||
tmp_releasedate = 9999
|
||||
tmp_list.append([movie['title'], int(tmp_runtime), int(tmp_releasedate[:4])])
|
||||
return tmp_list
|
||||
|
||||
def getBestMovie(self, name, length=None, year=None):
|
||||
self.report(2, "getBestMovie")
|
||||
tmp_movies = self.searchMovies(name)
|
||||
tmp_movies = self.searchMovie(name)
|
||||
if not year and not length:
|
||||
self.report(0, "Does not know year or runtime... Selecting first response.")
|
||||
return tmp_movies[0]
|
||||
|
112
Video/Services/tvdbservice.py
Normal file
112
Video/Services/tvdbservice.py
Normal file
@ -0,0 +1,112 @@
|
||||
from Universal import ioservice
|
||||
|
||||
class TMDBService:
|
||||
def __init__(self, loggingservice):
|
||||
self.logger = loggingservice
|
||||
self.report(2, "Initializing")
|
||||
try:
|
||||
import tvdb_api
|
||||
from tvdb_api import tvdb_seasonnotfound, tvdb_episodenotfound, tvdb_error
|
||||
from tvdb_api import tvdb_notauthorized, tvdb_shownotfound
|
||||
self.tvdb = tvdb_api
|
||||
self.report(2, "API Found")
|
||||
self.enabled = True
|
||||
self.tvdb_key = None
|
||||
self.addDefaultConfiguration()
|
||||
except ImportError:
|
||||
self.report(3, "Module 'tvdb_api' was not found")
|
||||
self.report(3, "Disabling TVDB API")
|
||||
self.enabled = False
|
||||
self.connected = False
|
||||
|
||||
def addDefaultConfiguration(self):
|
||||
ioservice.addConfiguration("TVDB Service", "TVDB API Key", "NONE")
|
||||
|
||||
def updateConfiguration(self):
|
||||
if self.tvdb_key == None:
|
||||
self.tvdb_key = ioservice.getConfigurationStr("TVDB Service", "TVDB API Key")
|
||||
|
||||
def report(self, level, message):
|
||||
match level:
|
||||
case 0:
|
||||
self.logger.infoReport("[TVDB] " + message)
|
||||
case 1:
|
||||
self.logger.warningReport("[TVDB] " + message)
|
||||
case 2:
|
||||
self.logger.debugReport("[TVDB] " + message)
|
||||
case 3:
|
||||
self.logger.errorReport("[TVDB] " + message)
|
||||
|
||||
def isEnabled(self):
|
||||
return self.enabled
|
||||
|
||||
def isConnected(self):
|
||||
self.report(2, "isConnected")
|
||||
return self.connected
|
||||
|
||||
def connectToService(self):
|
||||
self.report(2, "connectToService")
|
||||
if not self.connected:
|
||||
try:
|
||||
self.report(2, "Attempting to Login")
|
||||
self.updateConfiguration()
|
||||
self.tvdb = tvdb_api.Tvdb(apikey=self.tvdb_key)
|
||||
self.connected = True
|
||||
self.report(2, "Connected")
|
||||
except self.tmdb.APIKeyError:
|
||||
self.report(3, "API Key is incorrect")
|
||||
self.report(3, "Disabling TMDB API")
|
||||
self.enabled = False
|
||||
else:
|
||||
self.report(2, "Already connected")
|
||||
|
||||
def searchMovie(self, name):
|
||||
self.report(2, "searchMovie")
|
||||
tmp_search = self.tmdb.Search()
|
||||
tmp_response = tmp_search.movie(query=name)
|
||||
tmp_list = []
|
||||
for movie in tmp_search.results:
|
||||
tmp_runtime = self.tmdb.Movies(movie['id']).info()['runtime']
|
||||
try:
|
||||
tmp_releasedate = movie['release_date']
|
||||
except:
|
||||
tmp_releasedate = 9999
|
||||
if not tmp_runtime or tmp_runtime is None:
|
||||
tmp_runtime = 0
|
||||
if not tmp_releasedate or tmp_releasedate is None:
|
||||
tmp_releasedate = 9999
|
||||
tmp_list.append([movie['title'], int(tmp_runtime), int(tmp_releasedate[:4])])
|
||||
return tmp_list
|
||||
|
||||
def getBestMovie(self, name, length=None, year=None):
|
||||
self.report(2, "getBestMovie")
|
||||
tmp_movies = self.searchMovie(name)
|
||||
if not year and not length:
|
||||
self.report(0, "Does not know year or runtime... Selecting first response.")
|
||||
return tmp_movies[0]
|
||||
elif not year:
|
||||
self.report(0, "Got runtime but no year. Selecting closest match based on runtime.")
|
||||
tmp_time = []
|
||||
for movies in tmp_movies:
|
||||
if movies[1] == None:
|
||||
movies[1] = 0
|
||||
tmp_time.append(movies[1])
|
||||
return tmp_movies[min(enumerate(tmp_time), key=lambda x:abs(x[1]-length))[0]]
|
||||
else:
|
||||
tmp_year = []
|
||||
for movies in tmp_movies:
|
||||
if movies[2] == None:
|
||||
movies[2] = 9999
|
||||
tmp_year.append(movies[2])
|
||||
return tmp_movies[min(enumerate(tmp_year), key=lambda x:abs(x[1]-year))[0]]
|
||||
|
||||
def getShowName(self, name):
|
||||
self.report(2, "getShowName")
|
||||
tmp_search = self.tmdb.Search()
|
||||
tmp_response = tmp_search.tv(query=name)
|
||||
return tmp_search.results[0]
|
||||
|
||||
def getEpisodeName(self, name, season, episode):
|
||||
self.report(2, "getEpisodeName")
|
||||
self.tmdb.Search().tv(query=name)
|
||||
return self.tmdb.TV_Episodes(self.tmdb.results[0]['id'], season, episode).info()['name']
|
@ -11,7 +11,7 @@ from Universal.network import sftpservice
|
||||
|
||||
class VideoService:
|
||||
def __init__(self):
|
||||
self.logger = loggingservice.Output(True, False)
|
||||
self.logger = loggingservice.Output(True, True)
|
||||
self.video_settings = default.VideoSettings()
|
||||
# Movie/TV Show Database
|
||||
self.tmdbservice = tmdbservice.TMDBService(self.logger)
|
||||
@ -230,6 +230,7 @@ class VideoService:
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user