diff --git a/TVEncoder.py b/TVEncoder.py index 13c5548..607dc0b 100644 --- a/TVEncoder.py +++ b/TVEncoder.py @@ -12,8 +12,8 @@ from libsettings import Settings from libhandbrake import Encoder import libtvdatasource -#TVRECORDINGSDIR = "/Volumes/TV Recordings/" -TVRECORDINGSDIR = "/srv/storage2/videos/TVRecordings/" # TODO move this to settings +TVRECORDINGSDIR = "/Volumes/TV Recordings/" +#TVRECORDINGSDIR = "/srv/storage2/videos/TVRecordings/" # TODO move this to settings def ShowHelp(): print 'TVEncoder.py -p -n - prepare n recordings' diff --git a/libsickbeard.py b/libsickbeard.py index f3d4feb..6fe27b0 100644 --- a/libsickbeard.py +++ b/libsickbeard.py @@ -24,6 +24,12 @@ class Sickbeard: jsonurl = urlopen(self.__GetApiURL()+"?cmd=shows") result = json.loads(jsonurl.read()) + # TODO find a better way to do this + if showName == "Thomas and Friends": + showName = "Thomas The Tank Engine & Friends" + elif showName == "The Octonauts": + showName = "Octonauts" + shows = [] for show in result['data']: shows.append((show, fuzz.partial_ratio(showName.lower(), result['data'][show]['show_name'].lower()))) @@ -38,7 +44,7 @@ class Sickbeard: episodeResult = json.loads(jsonEpisodeUrl.read()) if fuzz.ratio(episodeResult['data']['description'].lower(), description.lower()) > 85: - return (season, episode) + return (season, episode, episodeResult['data']['name']) return None @@ -49,13 +55,13 @@ class Sickbeard: for season in result['data']: for episode in result['data'][season]: if name is not None and name.lower() == result['data'][season][episode]['name'].lower(): - return (season, episode) + return (season, episode, name) elif description is not None: - result = self.FindEpisodeByDescription(showId, season, episode, description) - if result is not None: - return result + descriptionQueryResult = self.FindEpisodeByDescription(showId, season, episode, description) + if descriptionQueryResult is not None: + return descriptionQueryResult - return (0, 0) + return (0, 0, '') def GetEpisodeName(subtitle, showName): if subtitle[:len(showName)].lower() == showName.lower(): diff --git a/libtvdatasource.py b/libtvdatasource.py index 4fb545d..b964852 100644 --- a/libtvdatasource.py +++ b/libtvdatasource.py @@ -21,10 +21,10 @@ RAARAA="RaaRaa" INPUTDIR="Input" def FixEpisodeSeasonNumber(number): - if number < 10: + if len(number) == 1: return "0{0}".format(number) else: - return str(number) + return number def GetDirectory(title, season): directory = "" @@ -47,35 +47,34 @@ def GetDirectory(title, season): def RetrieveEpisodeData(serverAddress, user, password, database, inputFile, showsToProcess, sickbeardAddress, sickbeardPort, sickbeardAPIKey): file = os.path.basename(inputFile) - #print file show = MythTV.RetrieveEpisodeData(serverAddress, user, password, database, file) - #print "file: {0} mythtv returned show name {1}".format(file, show.title) if show.title and show.title in showsToProcess: if show.subtitle: show.subtitle = GetEpisodeName(show.subtitle, show.title) - if (show.season == '0' or show.episode == '0'): + if (show.season == "0" or show.episode == "0"): sickbeard = Sickbeard(sickbeardAddress, sickbeardPort, sickbeardAPIKey) showId = sickbeard.FindShowId(show.title) result = sickbeard.FindEpisode(showId, show.subtitle, show.description) - show.season = result[0] - show.episode = result[1] + show.season = str(result[0]) + show.episode = str(result[1]) + show.subtitle = result[2] if show.season != "0" and show.episode != "0": show.season = FixEpisodeSeasonNumber(show.season) show.episode = FixEpisodeSeasonNumber(show.episode) - seasonFolder = "Season {0}".format(show.season) - season = "S{0}".format(show.season) - episode = "E{0}".format(show.episode) - renamedFile = "{0}{1} - {2} - SD TV_.mpg".format(season, episode, show.subtitle) + seasonFolder = "Season {0}".format(show.season) + season = "S{0}".format(show.season) + episode = "E{0}".format(show.episode) + renamedFile = "{0}{1} - {2} - SD TV_.mpg".format(season, episode, show.subtitle) - directory = GetDirectory(show.title, seasonFolder) + directory = GetDirectory(show.title, seasonFolder) - show.outputFile = os.path.join(directory, inputFile[:-4], renamedFile) - show.inputFile = inputFile + show.outputFile = os.path.join(directory, file[:-4], renamedFile) + show.inputFile = inputFile return show else: diff --git a/libtvshow.py b/libtvshow.py index 8d261d8..1fbb8a1 100644 --- a/libtvshow.py +++ b/libtvshow.py @@ -5,15 +5,15 @@ Created on Sat Jul 6 20:26:22 2013 @author: shanef """ -class TVShow: +class TVShow(object): def __init__(self, episode, season, title, subtitle, description, inputFile='', outputFile=''): - self.episode = episode - self.season = season + self.episode = str(episode) + self.season = str(season) self.title = title self.subtitle = subtitle self.description = description self.inputFile = inputFile self.outputFile = outputFile - + def Print(self): print "Input: {0} -> Output: {1}".format(self.inputFile, self.outputFile) \ No newline at end of file