fixing for pylint and pep8 recommendatins

This commit is contained in:
2013-07-12 00:02:42 +10:00
parent ca4c95219a
commit 0e3e1a2b14
7 changed files with 317 additions and 184 deletions

View File

@@ -27,24 +27,15 @@ def showhelp():
print 'TVEncoder.py -e -l - list the files that would be encoded' print 'TVEncoder.py -e -l - list the files that would be encoded'
def print_shows_to_encode(shows): def print_shows(shows):
""" """
Prints he details of the shows that have been selected for encoding. Prints he details of the shows.
""" """
for showdata in shows: for showdata in shows:
print showdata print showdata
def print_shows_to_prepare(shows):
"""
Prints he details of the shows that have been selected for preparation.
"""
for showdata in shows:
showdata.Print()
def processarguments(options): def processarguments(options):
""" """
Determine the actions required from the input flags Determine the actions required from the input flags
@@ -90,12 +81,12 @@ def main(argv):
if inputoptions.doencode: if inputoptions.doencode:
#Generate the list of files that would be encoded #Generate the list of files that would be encoded
showdata = filemanager.getencodingfiles(inputoptions.readonly) showdata = filemanager.getencodingfiles(inputoptions.readonly)
print_shows_to_encode(showdata) print_shows(showdata)
else: else:
# Generate the list of files to process # Generate the list of files to process
shows = filemanager.getfilestoprepare(inputoptions.numfiles) shows = filemanager.getfilestoprepare(inputoptions.numfiles)
print "num results: {0}".format(len(shows)) print "num results: {0}".format(len(shows))
print_shows_to_prepare(shows) print_shows(shows)
else: else:
if inputoptions.doencode: if inputoptions.doencode:
#Encode the files and move them to their final destination #Encode the files and move them to their final destination
@@ -116,7 +107,7 @@ def main(argv):
# Process files for encoding # Process files for encoding
shows = filemanager.getfilestoprepare(inputoptions.numfiles) shows = filemanager.getfilestoprepare(inputoptions.numfiles)
tvdata = TVData(settings) tvdata = TVData(settings)
tvdata.PrepareEpisodes(shows) tvdata.prepareepisodes(shows)
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -35,7 +35,7 @@ class FileManager:
""" """
def __init__(self, settings): def __init__(self, settings):
self.settings = settings self.__settings = settings
def getencodingfiles(self, readonly=True): def getencodingfiles(self, readonly=True):
""" """
@@ -70,7 +70,7 @@ class FileManager:
return the details of the number available. return the details of the number available.
""" """
path = self.settings.TVRecordingDirectory() path = self.__settings.tvrecordingdirectory()
potentialfiles = glob.glob("{0}*.mpg".format(path)) potentialfiles = glob.glob("{0}*.mpg".format(path))
potentialfiles = sorted(potentialfiles, key=os.path.getctime) potentialfiles = sorted(potentialfiles, key=os.path.getctime)
potentialfiles = [potentialfile for potentialfile in potentialfiles potentialfiles = [potentialfile for potentialfile in potentialfiles
@@ -82,10 +82,10 @@ class FileManager:
i = 0 i = 0
print "Found {0} potential files".format(len(potentialfiles)) print "Found {0} potential files".format(len(potentialfiles))
tvdata = TVData(self.settings) tvdata = TVData(self.__settings)
for potentialfile in potentialfiles: for potentialfile in potentialfiles:
showdata = tvdata.RetrieveEpisodeData(potentialfile) showdata = tvdata.retrieveepisodedata(potentialfile)
if showdata: if showdata:
showstoprocess.append(showdata) showstoprocess.append(showdata)
i = i + 1 i = i + 1
@@ -110,9 +110,9 @@ class FileManager:
filelist = [] filelist = []
for show in self.settings.GetShowNames(): for show in self.__settings.getshownames():
for dirpath, dirnames, filenames in os.walk( for dirpath, dirnames, filenames in os.walk(
self.settings.GetShowInputDirectory(show)): self.__settings.getshowinputdirectory(show)):
for inputfile in filenames: for inputfile in filenames:
if inputfile.endswith(".mpg"): if inputfile.endswith(".mpg"):
data = EncodeData(show, os.path.join( data = EncodeData(show, os.path.join(
@@ -128,7 +128,7 @@ class FileManager:
infile = os.path.basename(inputfile) infile = os.path.basename(inputfile)
outfilename = infile[:-3]+"mkv" outfilename = infile[:-3]+"mkv"
outpath = findseason(self.settings.GetShowOutputDirectory( outpath = findseason(self.__settings.GetShowOutputDirectory(
showname), outfilename, readonly) showname), outfilename, readonly)
return os.path.join(outpath, outfilename) return os.path.join(outpath, outfilename)
@@ -139,7 +139,7 @@ class FileManager:
final directory in it's path. final directory in it's path.
""" """
return os.path.join(self.settings.TVRecordingDirectory(), return os.path.join(self.__settings.TVRecordingDirectory(),
os.path.dirname(filename).split("/")[-1] + ".mpg") os.path.dirname(filename).split("/")[-1] + ".mpg")

View File

@@ -15,16 +15,16 @@ class MythTV:
""" """
def __init__(self, settings): def __init__(self, settings):
self.settings = settings self.__settings = settings
def retrieveepisodedata(self, inputfile): def retrieveepisodedata(self, inputfile):
""" """
Retrieve the data that mythtv knows about the recorded file. Retrieve the data that mythtv knows about the recorded file.
""" """
con = mdb.connect(self.settings.MythTVAddress(), con = mdb.connect(self.__settings.mythtvaddress(),
self.settings.MythTVUser(), self.__settings.mythtvuser(),
self.settings.MythTVPassword(), self.__settings.mythtvpassword(),
self.settings.MythTVDatabase()) self.__settings.mythtvdatabase())
with con: with con:
cur = con.cursor(mdb.cursors.DictCursor) cur = con.cursor(mdb.cursors.DictCursor)
@@ -45,7 +45,7 @@ class MythTV:
prefixes are listed in the configuration file. prefixes are listed in the configuration file.
""" """
for prefix in self.settings.GetShowMythTVEpisodePrefix(showname): for prefix in self.__settings.getshowmythtvepisodeprefix(showname):
if episodetitle.lower().startswith(prefix.lower()): if episodetitle.lower().startswith(prefix.lower()):
return episodetitle[len(prefix):] return episodetitle[len(prefix):]

View File

@@ -27,39 +27,90 @@ class Settings:
""" """
def __init__(self, settingsfile): def __init__(self, settingsfile):
"""
Initialise settingsfile as a configobj
"""
self.__config = ConfigObj(settingsfile) self.__config = ConfigObj(settingsfile)
def tvrecordingdirectory(self): def tvrecordingdirectory(self):
"""
Get the TVRecordings setting
"""
return self.__config["TVRecordings"] return self.__config["TVRecordings"]
def handbrakecommand(self): def handbrakecommand(self):
"""
Get the HandbrakeCommand setting
"""
return self.__config["HandbrakeCommand"] return self.__config["HandbrakeCommand"]
def mythtvaddress(self): def mythtvaddress(self):
"""
Get the MythTV/address setting
"""
return self.__config["MythTV"]["address"] return self.__config["MythTV"]["address"]
def mythtvuser(self): def mythtvuser(self):
"""
Get the MythTV/user setting
"""
return self.__config["MythTV"]["user"] return self.__config["MythTV"]["user"]
def mythtvpassword(self): def mythtvpassword(self):
"""
Get the MythTV/password setting
"""
return self.__config["MythTV"]["password"] return self.__config["MythTV"]["password"]
def mythtvdatabase(self): def mythtvdatabase(self):
"""
Get the MythTV/database setting
"""
return self.__config["MythTV"]["database"] return self.__config["MythTV"]["database"]
def sickbeardaddress(self): def sickbeardaddress(self):
"""
Get the Sickbeard/address setting
"""
return self.__config["Sickbeard"]["address"] return self.__config["Sickbeard"]["address"]
def sickbeardport(self): def sickbeardport(self):
"""
Get the Sickbeard/port setting
"""
return int(self.__config["Sickbeard"]["port"]) return int(self.__config["Sickbeard"]["port"])
def sickbeardapikey(self): def sickbeardapikey(self):
"""
Get the Sickbeard/APIKey setting
"""
return self.__config["Sickbeard"]["APIKey"] return self.__config["Sickbeard"]["APIKey"]
def unknowndirectory(self): def unknowndirectory(self):
"""
Get the Shows/UnknownInput directory. It is the directory used for
episodes where nothing is known about it
"""
return self.__config["Shows"]["UnknownInput"] return self.__config["Shows"]["UnknownInput"]
def getshownames(self, includealias=False): def getshownames(self, includealias=False):
"""
Get a list of the names of the shows that are specified in the
settings file. If includealias is True, it will also include any
defined aliases in the list.
"""
shows = self.__config["Shows"].sections shows = self.__config["Shows"].sections
result = shows[:] result = shows[:]
if includealias: if includealias:
@@ -68,7 +119,30 @@ class Settings:
result.append(alias) result.append(alias)
return result return result
def findshownameforalias(self, aliasname):
"""
Find the name of the show. If the supplied aliasname is an alias, it
will return the show name. If aliasname is the name of a show, it will
return aliasname
"""
if aliasname in self.getshownames():
# aliasname is the name of an actual show
return aliasname
# search for the show that the alias belongs to
for showsettings in self.__config["Shows"]:
if aliasname in showsettings["alias"]:
return showsettings.name
# Could not find it anywhere
return None
def getshowinputdirectory(self, showname): def getshowinputdirectory(self, showname):
"""
Get the InputDirectory setting for the show, showname.
"""
show = self.__getshowsubsection(showname) show = self.__getshowsubsection(showname)
if show is None: if show is None:
return "" return ""
@@ -76,6 +150,11 @@ class Settings:
return show["InputDirectory"] return show["InputDirectory"]
def getshowunknowndirectory(self, showname): def getshowunknowndirectory(self, showname):
"""
Get the UnknownDirectory setting for the show, showname. It is used
when the show is known, but the season or episode are not.
"""
show = self.__getshowsubsection(showname) show = self.__getshowsubsection(showname)
if show is None: if show is None:
return "" return ""
@@ -83,6 +162,10 @@ class Settings:
return show["UnknownDirectory"] return show["UnknownDirectory"]
def getshowoutputdirectory(self, showname): def getshowoutputdirectory(self, showname):
"""
Get the OutputDirectory setting for the show, showname.
"""
show = self.__getshowsubsection(showname) show = self.__getshowsubsection(showname)
if show is None: if show is None:
return "" return ""
@@ -90,6 +173,11 @@ class Settings:
return show["OutputDirectory"] return show["OutputDirectory"]
def getshowalias(self, showname): def getshowalias(self, showname):
"""
Get the alias setting for the show, showname. It returns a list of
aliases.
"""
show = self.__getshowsubsection(showname) show = self.__getshowsubsection(showname)
if show is None: if show is None:
return "" return ""
@@ -97,6 +185,10 @@ class Settings:
return show["alias"] return show["alias"]
def getshowmythtvepisodeprefix(self, showname): def getshowmythtvepisodeprefix(self, showname):
"""
Get the MythTVEpisodePrefix setting for the show, showname.
"""
show = self.__getshowsubsection(showname) show = self.__getshowsubsection(showname)
if show is None: if show is None:
return "" return ""
@@ -104,13 +196,22 @@ class Settings:
return show["MythTvEpisodePrefix"] return show["MythTvEpisodePrefix"]
def getshowsickbearsepisodeprefix(self, showname): def getshowsickbearsepisodeprefix(self, showname):
"""
Get the SickbeardPrefix setting for the show, showname.
"""
show = self.__getshowsubsection(showname) show = self.__getshowsubsection(showname)
if show is None: if show is None:
return "" return ""
else: else:
return show["SickbeardPrefix"] return show["SickbeardPrefix"]
# TODO check if this is actually doing anything. it seems like it
# just returns what is input
def getshow(self, showname): def getshow(self, showname):
"""
Get the InputDirectory setting for the show, showname.
"""
showsection = self.__getshowsubsection(showname) showsection = self.__getshowsubsection(showname)
if showsection is None: if showsection is None:
return None return None
@@ -118,6 +219,10 @@ class Settings:
return showsection.name return showsection.name
def __getshowsubsection(self, showname): def __getshowsubsection(self, showname):
"""
Get the configuration options for the show, showname.
"""
if showname in self.getshownames(): if showname in self.getshownames():
return self.__config["Shows"][showname] return self.__config["Shows"][showname]
else: # check liases else: # check liases

View File

@@ -12,29 +12,29 @@ from operator import itemgetter
class Sickbeard: class Sickbeard:
"""
Contains operations used to interact with sickbeard
"""
def __init__(self, settings): def __init__(self, settings):
self.__settings = settings self.__settings = settings
self.__address = settings.SickbeardAddress() self.__address = settings.sickbeardaddress()
self.__port = settings.SickbeardPort() self.__port = settings.sickbeardport()
self.__apikey = settings.SickbeardAPIKey() self.__apikey = settings.sickbeardapikey()
def __GetApiURL(self): def findshowid(self, showname):
return "http://{0}:{1}/api/{2}/".format(self.__address, self.__port, """
self.__apikey) Get the tvdb show id for the show
"""
def FindShowId(self, showName): jsonurl = urlopen(self.__getapiurl()+"?cmd=shows")
jsonurl = urlopen(self.__GetApiURL()+"?cmd=shows")
result = json.loads(jsonurl.read()) result = json.loads(jsonurl.read())
# TODO find a better way to do this showname = self.__settings.findshownameforalias(showname)
if showName == "Thomas and Friends":
showName = "Thomas The Tank Engine & Friends"
elif showName == "The Octonauts":
showName = "Octonauts"
shows = [] shows = []
for show in result['data']: for show in result['data']:
shows.append((show, fuzz.partial_ratio(showName.lower(), shows.append((show, fuzz.partial_ratio(showname.lower(),
result['data'][show] result['data'][show]
['show_name'].lower()))) ['show_name'].lower())))
@@ -43,32 +43,30 @@ class Sickbeard:
if shows[0][1] > 85: if shows[0][1] > 85:
return shows[0][0] return shows[0][0]
def FindEpisodeByDescription(self, showId, season, episode, description): def findepisodename(self, showid, season, episode):
jsonepisodeurl = urlopen("{0}?cmd=episode&tvdbid={1}&season={2}" """
"&episode={3}".format(self.__GetApiURL(), Get the name of an episode, given it's season and episode numbers
showId, season, episode)) """
episoderesult = json.loads(jsonepisodeurl.read())
sickbearddescription = episoderesult['data']['description']
if fuzzystringcompare(sickbearddescription, description):
return (season, episode, episoderesult['data']['name'])
return None
def FindEpisodeName(self, showId, season, episode):
jsonurl = urlopen("{0}?cmd=episode&tvdbid={1}&season={2}" jsonurl = urlopen("{0}?cmd=episode&tvdbid={1}&season={2}"
"&episode={3}".format(self.__GetApiURL(), showId, "&episode={3}".format(self.__getapiurl(), showid,
int(season), int(episode))) int(season), int(episode)))
result = json.loads(jsonurl.read()) result = json.loads(jsonurl.read())
if result['result'] == 'error': if result['result'] == 'error':
return "" return ""
else: else:
return result['data']['name'] return result['data']['name']
def FindEpisode(self, showId, name=None, description=None): def findepisode(self, showid, name=None, description=None):
"""
Find an episode, either by it's name or it's description. This is used
when the season and episode numbers are not known
"""
jsonurl = urlopen("{0}?cmd=show.seasons&tvdbid={1}".format( jsonurl = urlopen("{0}?cmd=show.seasons&tvdbid={1}".format(
self.__GetApiURL(), showId)) self.__getapiurl(), showid))
result = json.loads(jsonurl.read()) result = json.loads(jsonurl.read())
for season in result['data']: for season in result['data']:
@@ -78,11 +76,11 @@ class Sickbeard:
episodename) > 90: episodename) > 90:
return (season, episode, episodename) return (season, episode, episodename)
elif description is not None: elif description is not None:
descriptionQueryResult = \ descriptionqueryresult = \
self.FindEpisodeByDescription(showId, season, self.__findepisodebydescription(showid, season,
episode, description) episode, description)
if descriptionQueryResult is not None: if descriptionqueryresult is not None:
return descriptionQueryResult return descriptionqueryresult
return (0, 0, '') return (0, 0, '')
@@ -94,16 +92,48 @@ class Sickbeard:
# return subtitle # return subtitle
#============================================================================== #==============================================================================
def FixEpisodeTitle(self, showName, episodeTitle): def fixepisodetitle(self, showname, episodetitle):
sickbeardPrefix = \ """
self.__settings.GetShowSickbeardEpisodePrefix(showName) Check to see if there is a prefix specified for the show. If there is,
add the prefix to the start of the episode title
"""
if sickbeardPrefix != "": sickbeardprefix = \
if not episodeTitle.lower.startswith(sickbeardPrefix.lower()): self.__settings.GetShowSickbeardEpisodePrefix(showname)
return "{0} {1}".format(sickbeardPrefix.rstrip(),
episodeTitle.lstrip())
return episodeTitle if sickbeardprefix != "":
if not episodetitle.lower.startswith(sickbeardprefix.lower()):
return "{0} {1}".format(sickbeardprefix.rstrip(),
episodetitle.lstrip())
return episodetitle
def __getapiurl(self):
"""
Get the url of the sickbeard api, substituting the values from the
settings
"""
return "http://{0}:{1}/api/{2}/".format(self.__address, self.__port,
self.__apikey)
def __findepisodebydescription(self, showid, season, episode, description):
"""
Find the details of an episode by searching for it's description
"""
jsonepisodeurl = urlopen("{0}?cmd=episode&tvdbid={1}&season={2}"
"&episode={3}".format(self.__getapiurl(),
showid, season,
episode))
episoderesult = json.loads(jsonepisodeurl.read())
sickbearddescription = episoderesult['data']['description']
if fuzzystringcompare(sickbearddescription, description):
return (season, episode, episoderesult['data']['name'])
return None
def fuzzystringcompare(string1, string2, matchvalue=85, casesensitive=False): def fuzzystringcompare(string1, string2, matchvalue=85, casesensitive=False):

View File

@@ -10,131 +10,131 @@ from libsickbeard import Sickbeard
import os import os
import shutil import shutil
# TODO Move these to settings
#PROCESSDIR="/srv/storage2/files/VideoProcessing/" def fixepisodeseasonnumber(number):
#THOMAS="Thomas" """
#CHUGGINGTON="Chuggington" If the number is single digit, return a string with 0 in front of it.
#MIKE="MikeTheKnight" """
#OCTONAUTS="Octonauts"
#NIGHTGARDEN="InTheNightGarden" if len(number) == 1:
#RAARAA="RaaRaa" return "0{0}".format(number)
#INPUTDIR="Input" else:
return number
class TVData: class TVData:
"""
Class contains logic for processing information about tv episodes
"""
def __init__(self, settings): def __init__(self, settings):
self.settings = settings self.__settings = settings
def FixEpisodeSeasonNumber(self, number): def getdirectory(self, title, seasonfolder, season, episode):
if len(number) == 1: """
return "0{0}".format(number) Get the directory where prepared episodes will be located.
else: """
return number
show = self.__settings.getshow(title)
def GetDirectory(self, title, seasonFolder, season, episode):
show = self.settings.GetShow(title)
if not show or show == "": if not show or show == "":
print "Couldn't find show for {0}".format(title) print "Couldn't find show for {0}".format(title)
return self.settings.UnknownDirectory() return self.__settings.unknowndirectory()
elif season == "S00" or episode == "E00": elif season == "S00" or episode == "E00":
return self.settings.GetShowUnknownDirectory(show) return self.__settings.getshowunknowndirectory(show)
else: else:
return os.path.join(self.settings.GetShowInputDirectory(show), seasonFolder) return os.path.join(self.__settings.getshowinputdirectory(show),
#============================================================================== seasonfolder)
# if title == "Thomas and Friends" or title == "Thomas the Tank Engine & Friends":
# directory = THOMAS def retrieveepisodedata(self, inputfile):
# elif title == "Chuggington": """
# directory = CHUGGINGTON Retrieve the details of an episode. It first looks up the details that
# elif title == "Mike the Knight": mythtv recorded about it, then looks up sickbeard to attempt to find
# directory = MIKE any missing details. Finally it determined the output file for it.
# elif title == "Octonauts" or title == "The Octonauts": """
# directory = OCTONAUTS
# elif title == "In the Night Garden": inputfilename = os.path.basename(inputfile)
# directory = NIGHTGARDEN
# elif title == "Raa Raa! The Noisy Lion": mythtv = MythTV(self.__settings)
# directory = RAARAA show = mythtv.retrieveepisodedata(inputfilename)
# else:
# print "Didn't match" showstoprocess = self.__settings.getshownames(True)
#==============================================================================
if show.title and show.title in showstoprocess:
# return os.path.join(PROCESSDIR, directory, INPUTDIR, season) show.title = self.__settings.getshow(show.title)
def RetrieveEpisodeData(self, inputFile):
file = os.path.basename(inputFile)
mythTv = MythTV(self.settings)
show = mythTv.RetrieveEpisodeData(file)
showsToProcess = self.settings.GetShowNames(True)
if show.title and show.title in showsToProcess:
show.title = self.settings.GetShow(show.title)
if (show.season == "0" or show.episode == "0"): if (show.season == "0" or show.episode == "0"):
sickbeard = Sickbeard(self.settings) sickbeard = Sickbeard(self.__settings)
showId = sickbeard.FindShowId(show.title) showid = sickbeard.findshowid(show.title)
if show.subtitle is not None and show.subtitle: if show.subtitle is not None and show.subtitle:
show.subtitle = mythTv.FixMythTVEpisodeName(show.title, show.subtitle) show.subtitle = mythtv.fixmythtvepisodename(show.title,
show.subtitle = sickbeard.FixEpisodeTitle(show.title, show.subtitle) show.subtitle)
show.subtitle = sickbeard.fixepisodetitle(show.title,
result = sickbeard.FindEpisode(showId, show.subtitle, show.description) show.subtitle)
result = sickbeard.findepisode(showid, show.subtitle,
show.description)
show.season = str(result[0]) show.season = str(result[0])
show.episode = str(result[1]) show.episode = str(result[1])
show.subtitle = result[2] show.subtitle = result[2]
if show.subtitle is None or show.subtitle == "": if show.subtitle is None or show.subtitle == "":
show.subtitle = sickbeard.FindEpisodeName(showId, show.season, show.episode) show.subtitle = sickbeard.findepisodename(showid, show.season,
show.episode)
#if show.season != "0" and show.episode != "0":
show.season = self.FixEpisodeSeasonNumber(show.season) show.season = fixepisodeseasonnumber(show.season)
show.episode = self.FixEpisodeSeasonNumber(show.episode) show.episode = fixepisodeseasonnumber(show.episode)
seasonFolder = "Season {0}".format(show.season) seasonfolder = "Season {0}".format(show.season)
season = "S{0}".format(show.season) season = "S{0}".format(show.season)
episode = "E{0}".format(show.episode) episode = "E{0}".format(show.episode)
renamedFile = "{0}{1} - {2} - SD TV_.mpg".format(season, episode, show.subtitle) renamedfile = "{0}{1} - {2} - SD TV_.mpg".format(season, episode,
show.subtitle)
directory = self.GetDirectory(show.title, seasonFolder, season, episode)
directory = self.getdirectory(show.title, seasonfolder,
show.outputFile = os.path.join(directory, file[:-4], renamedFile) season, episode)
show.inputFile = inputFile
show.outputfile = os.path.join(directory, inputfilename[:-4],
renamedfile)
show.inputfile = inputfile
return show return show
else: else:
return None return None
#============================================================================== #==============================================================================
# def CheckTitleIsInList(serverAddress, user, password, database, inputFile): # def __determinetargetfilename(directory, filename, inputfilename):
# """Check that inputFile is a recording of a show that is to be processed.""" # """
# file = os.path.basename(inputFile) # Determine the filename for the input file. If the path does not
# show = MythTV.RetrieveEpisodeData('localhost', 'script', 'script', 'mythconverg', file) # exist, it is created.
# # """
# # TODO get this from settings #
# if show.title in ["Thomas and Friends", "Thomas the Tank Engine & Friends", # inputdir = os.path.join(directory, inputfilename[:-4])
# "Chuggington", "Mike the Knight", "Octonauts", #
# "The Octonauts", "In the Night Garden", # if not os.path.exists(inputdir):
# "Raa Raa! The Noisy Lion"]: # os.makedirs(inputdir)
# return True #
# else: # return os.path.join(inputdir, filename)
# return False
#============================================================================== #==============================================================================
def DetermineTargetFilename(directory, filename, inputFilename): @staticmethod
dir = os.path.join(directory, inputFilename[:-4]) def processepisode(inputfile, outputfile):
"""
if not os.path.exists(dir): Copy inputfile to outputfile, creating the path for outputfile if
os.makedirs(dir) required.
"""
return os.path.join(dir, filename)
outputdir = os.path.dirname(outputfile)
def ProcessEpisode(self, inputFile, outputFile):
outputdir = os.path.dirname(outputFile)
if not os.path.exists(outputdir): if not os.path.exists(outputdir):
os.makedirs(outputdir) os.makedirs(outputdir)
shutil.copyfile(inputFile, outputFile) shutil.copyfile(inputfile, outputfile)
def PrepareEpisodes(self, showsData): def prepareepisodes(self, showsdata):
for showData in showsData: """
self.ProcessEpisode(showData.inputFile, showData.outputFile) Copy the files in showsdata from their input directory to their output
directory.
"""
for showdata in showsdata:
self.processepisode(showdata.inputfile, showdata.outputfile)

View File

@@ -5,15 +5,22 @@ Created on Sat Jul 6 20:26:22 2013
@author: shanef @author: shanef
""" """
class TVShow(object): class TVShow(object):
def __init__(self, episode, season, title, subtitle, description, inputFile='', outputFile=''): """
Describes the details of a tv episode
"""
def __init__(self, episode, season, title, subtitle, description,
inputfile='', outputfile=''):
self.episode = str(episode) self.episode = str(episode)
self.season = str(season) self.season = str(season)
self.title = title self.title = title
self.subtitle = subtitle self.subtitle = subtitle
self.description = description self.description = description
self.inputFile = inputFile self.inputfile = inputfile
self.outputFile = outputFile self.outputfile = outputfile
def Print(self): def __str__(self):
print "Input: {0} -> Output: {1}".format(self.inputFile, self.outputFile) return "Input: {0} -> Output: {1}".format(self.inputfile,
self.outputfile)