def getShowDetails ( self, showandseasonsdict ) : ''' Download a list of Show object's episodes. :param showandcontentlist: dictionary { Show : content( raw html from web page ) } :type showandcontentlist: :mod:`dict` :returns: Database with api.dbapi.Show objects :rtype: :class:`api.dbapi.Database` ''' updateDB = Database() #TODO: Test for changes in code. for Show, seasons in showandseasonsdict.items() : for season, episodes in seasons.items() : for episode in episodes : assert season == episode["season"] #print episode["episode"] episodenr = episode["episode"].findAll('meta', { "itemprop" : "episodeNumber" })[0]["content"] #print episodenr episodename = episode["episode"].findAll('a', { "itemprop" : "name" })[0]["title"] #print episodename episodeairdate = episode["episode"].findAll('div', { "class" : "airdate" })[0].string.strip() #print episodeairdate Show.addEpisode( Episode( episodenr, episodename, episodeairdate ), Season( season ) ) updateDB.addShow( Show ) # seasons = BeautifulSoup.SoupStrainer('div', { "class" : re.compile("season-filter-all filter-season-[0-9]+") }) # # all = [ tag for tag in BeautifulSoup.BeautifulSoup( content, parseOnlyThese=seasons)] # # for i in xrange( 0, len(all)) : # ## Remove rubbish from the content. # [ tag.extract() for tag in all[i].findAll('hr') ] # [ tag.parent.extract() for tag in all[i].findAll('a', { "name" : re.compile("season-[0-9]+")} )] # # regexp = Regexes() # # for x in all : # for item in x.findAll('div', { "class" : re.compile("filter-all filter-year-[0-9]+")} ) : # ## Extract info in every episode/item, and add to one tuple # merge = regexp.extractEpSeTitle( str(item.find('h3')) ) + regexp.extractAirDate( str( item.find('strong') ) ) # if ( len(merge) == 4 ) : ## If merge is proper # Show.addEpisode( Episode( merge[1], regexp.removeEntities(merge[2]), merge[3] ), Season( merge[0] ) ) # updateDB.addShow( Show ) return updateDB
def setUp(self) : self.Tools = Tools() self.Tools.createRootDir() self.Tools.createTempFiles() self.Tools.createDatabaseFiles() self.Tools.createFilesystemXML() self.database = Database(self.Tools.databaseDir) self.database.loadDB() smallville = Show('Smallville', '60', 'dummy', 'dummy') smallville.addAlias(Alias('smallville')) smallville.addEpisode( Episode('10', 'Bizarro', 'dummy'), Season('7') ) self.database.addShow( smallville ) self.files = [ 'blackbooks.s01e02.avi', 'spaced.2x03.avi', 'csi.s02E13.avi', 'black books - 03x02 - Six of One.avi', 'Smallville.S07E10.HDTV.XviD-XOR.avi' ] self.filenames = [ FileName( files, self.database ) for files in self.files ]
def testGenerateFileName(self): #FIXME: More than one Style, different file suffixes, arcs. # generateFileName(Style=None) correctShow1 = Show('Black Books', '30', 'imdbtvbackend', 'tt0262150') correctShow1.addEpisode( Episode('2', "A test's test' & a test / # a test", '6 October 2000', 'none'), Season('1')) correctShow2 = Show('Spaced', '60', 'imdbtvbackend', 'tt0187664') correctShow2.addEpisode( Episode('3', "A test's test' & a test / # a test", '9 March 2001', 'none'), Season('2')) correctShow3 = Show('C.S.I', '60', 'imdbtvbackend', 'tt0247082') correctShow3.addEpisode( Episode('13', "Identity Crisis / # 4587", '17 January 2002', 'none'), Season('2')) self.FN = FileName('', self.database) self.FN.fileSuffix = '.avi' fileName1 = self.FN.generateFileName( correctShow1, self.Tools.filetypesXML, 'ext3', '%show.S%seasonE%episode.%title.%arc.%airdate') fileName2 = self.FN.generateFileName( correctShow2, self.Tools.filetypesXML, 'ntfs', '%show.S%seasonE%episode.%title.%arc.%airdate') fileName3 = self.FN.generateFileName( correctShow3, self.Tools.filetypesXML, 'ext3', '%show.S%seasonE%episode.%title.%arc.%airdate') assert fileName1 == "Black Books.S01E02.A test's test' & a test or # a test.none.6 October 2000.avi" assert fileName2 == "Spaced.S02E03.A tests test and a test or No. a test.none.9 March 2001.avi" assert fileName3 == "C.S.I.S02E13.Identity Crisis or # 4587.none.17 January 2002.avi"
def testGetShowDetails(self): testShows = [ fn.getShowDetails( self.Tools.filetypesXML, fn.getMatchingShows() ) for fn in self.filenames ] assert [ len(ts.seasons) for ts in testShows ] == [1, 1, 1, 1, 1] assert [ len(ts.seasons[0].episodes) for ts in testShows ] == [1, 1, 1, 1, 1] correctShow1 = Show( 'Black Books', '30', 'imdbtvbackend', 'tt0262150' ) correctShow1.addEpisode( Episode( '2', "Manny's First Day", '6 October 2000', 'none'), Season('1') ) correctShow2 = Show( 'Spaced', '60', 'imdbtvbackend', 'tt0187664' ) correctShow2.addEpisode( Episode( '3', 'Mettle', '9 March 2001', 'none'), Season('2') ) correctShow3 = Show( 'C.S.I', '60', 'imdbtvbackend', 'tt0247082' ) correctShow3.addEpisode( Episode( '13', 'Identity Crisis', '17 January 2002', 'none'), Season('2') ) def compareShows(show, other) : if show.name != other.name or show.duration != other.duration or show.backend != other.backend or show.url != other.url : assert False elif show.seasons[0].name != other.seasons[0].name : assert False elif show.seasons[0].episodes[0].name != other.seasons[0].episodes[0].name or show.seasons[0].episodes[0].title != other.seasons[0].episodes[0].title or show.seasons[0].episodes[0].airdate != other.seasons[0].episodes[0].airdate or show.seasons[0].episodes[0].arc != other.seasons[0].episodes[0].arc : assert False else : return True assert compareShows( testShows[0], correctShow1 ) assert compareShows( testShows[1], correctShow2 ) assert compareShows( testShows[2], correctShow3 )
def setUp(self): self.Tools = Tools() self.Tools.createRootDir() self.Tools.createTempFiles() self.Tools.createDatabaseFiles() self.Tools.createFilesystemXML() self.database = Database(self.Tools.databaseDir) self.database.loadDB() smallville = Show('Smallville', '60', 'dummy', 'dummy') smallville.addAlias(Alias('smallville')) smallville.addEpisode(Episode('10', 'Bizarro', 'dummy'), Season('7')) self.database.addShow(smallville) self.files = [ 'blackbooks.s01e02.avi', 'spaced.2x03.avi', 'csi.s02E13.avi', 'black books - 03x02 - Six of One.avi', 'Smallville.S07E10.HDTV.XviD-XOR.avi' ] self.filenames = [ FileName(files, self.database) for files in self.files ]
def testGetShowDetails(self): testShows = [ fn.getShowDetails(self.Tools.filetypesXML, fn.getMatchingShows()) for fn in self.filenames ] assert [len(ts.seasons) for ts in testShows] == [1, 1, 1, 1, 1] assert [len(ts.seasons[0].episodes) for ts in testShows] == [1, 1, 1, 1, 1] correctShow1 = Show('Black Books', '30', 'imdbtvbackend', 'tt0262150') correctShow1.addEpisode( Episode('2', "Manny's First Day", '6 October 2000', 'none'), Season('1')) correctShow2 = Show('Spaced', '60', 'imdbtvbackend', 'tt0187664') correctShow2.addEpisode(Episode('3', 'Mettle', '9 March 2001', 'none'), Season('2')) correctShow3 = Show('C.S.I', '60', 'imdbtvbackend', 'tt0247082') correctShow3.addEpisode( Episode('13', 'Identity Crisis', '17 January 2002', 'none'), Season('2')) def compareShows(show, other): if show.name != other.name or show.duration != other.duration or show.backend != other.backend or show.url != other.url: assert False elif show.seasons[0].name != other.seasons[0].name: assert False elif show.seasons[0].episodes[0].name != other.seasons[0].episodes[ 0].name or show.seasons[0].episodes[ 0].title != other.seasons[0].episodes[ 0].title or show.seasons[0].episodes[ 0].airdate != other.seasons[0].episodes[ 0].airdate or show.seasons[0].episodes[ 0].arc != other.seasons[0].episodes[ 0].arc: assert False else: return True assert compareShows(testShows[0], correctShow1) assert compareShows(testShows[1], correctShow2) assert compareShows(testShows[2], correctShow3)
def testGenerateFileName(self): #FIXME: More than one Style, different file suffixes, arcs. # generateFileName(Style=None) correctShow1 = Show( 'Black Books', '30', 'imdbtvbackend', 'tt0262150' ) correctShow1.addEpisode( Episode( '2', "A test's test' & a test / # a test", '6 October 2000', 'none'), Season('1') ) correctShow2 = Show( 'Spaced', '60', 'imdbtvbackend', 'tt0187664' ) correctShow2.addEpisode( Episode( '3', "A test's test' & a test / # a test", '9 March 2001', 'none'), Season('2') ) correctShow3 = Show( 'C.S.I', '60', 'imdbtvbackend', 'tt0247082' ) correctShow3.addEpisode( Episode( '13', "Identity Crisis / # 4587", '17 January 2002', 'none'), Season('2') ) self.FN = FileName('', self.database) self.FN.fileSuffix = '.avi' fileName1 = self.FN.generateFileName( correctShow1, self.Tools.filetypesXML, 'ext3', '%show.S%seasonE%episode.%title.%arc.%airdate' ) fileName2 = self.FN.generateFileName( correctShow2, self.Tools.filetypesXML, 'ntfs', '%show.S%seasonE%episode.%title.%arc.%airdate' ) fileName3 = self.FN.generateFileName( correctShow3, self.Tools.filetypesXML, 'ext3', '%show.S%seasonE%episode.%title.%arc.%airdate' ) assert fileName1 == "Black Books.S01E02.A test's test' & a test or # a test.none.6 October 2000.avi" assert fileName2 == "Spaced.S02E03.A tests test and a test or No. a test.none.9 March 2001.avi" assert fileName3 == "C.S.I.S02E13.Identity Crisis or # 4587.none.17 January 2002.avi"
class testShow : """ Test Show Class """ def setUp(self) : self.show = Show( "Test Show", "60", "dummybackend", "dummyurl" ) def testAddAlias(self) : Alias1 = Alias("firstalias") Alias2 = Alias("secondalias") Alias3 = Alias("thirdalias") assert self.show.addAlias( Alias1 ) == Alias1 assert self.show.addAlias( Alias1 ) == None assert self.show.addAlias( Alias2 ) == Alias2 assert self.show.addAlias( Alias("secondalias")) == None assert self.show.addAlias( Alias3 ) == Alias3 def testGetAlias(self) : Alias1 = Alias("firstalias") Alias2 = Alias("secondalias") Alias3 = Alias("thirdalias") self.show.addAlias( Alias1 ) self.show.addAlias( Alias2 ) assert self.show.getAlias( Alias1 ) == Alias1 assert self.show.getAlias( Alias3 ) == None assert self.show.getAlias( Alias("secondalias") ) == Alias2 assert self.show.getAlias( Alias("thirdalias") ) == None def testRemoveAlias(self) : Alias1 = Alias("firstalias") Alias2 = Alias("secondalias") Alias3 = Alias("thirdalias") self.show.addAlias( Alias1 ) self.show.addAlias( Alias2 ) assert self.show.removeAlias( Alias1 ) == Alias1 assert self.show.removeAlias( Alias1 ) == None assert self.show.removeAlias( Alias("thirdalias") ) == None assert self.show.removeAlias( Alias("secondalias") ) == Alias2 def testAddSeason(self) : Season1 = Season("1") Season2 = Season("2") Season3 = Season("3") assert self.show.addSeason( Season1 ) == Season1 assert self.show.addSeason( Season1 ) == None assert self.show.addSeason( Season2 ) == Season2 assert self.show.addSeason( Season("2") ) == None assert self.show.addSeason( Season3 ) == Season3 def testGetSeason(self) : Season1 = Season("1") Season2 = Season("2") Season3 = Season("3") self.show.addSeason( Season1 ) self.show.addSeason( Season2 ) assert self.show.getSeason( Season1 ) == Season1 assert self.show.getSeason( Season3 ) == None assert self.show.getSeason( Season("2") ) == Season2 assert self.show.getSeason( Season("3") ) == None def testRemoveSeason(self) : Season1 = Season("1") Season2 = Season("2") Season3 = Season("3") self.show.addSeason( Season1 ) self.show.addSeason( Season2 ) assert self.show.removeSeason( Season1 ) == Season1 assert self.show.removeSeason( Season1 ) == None assert self.show.removeSeason( Season("3") ) == None assert self.show.removeSeason( Season("2") ) == Season2 def testAddEpisode(self) : Episode1 = Episode( "2", "What A Title", "6 November, 2008" ) Episode2 = Episode( "333", "For A TV Show", "18 November, 2008" ) Episode3 = Episode( "4", "What A Title", "6 November, 2008") Season1 = Season("1") Season2 = Season("2") self.show.addSeason( Season1 ) assert self.show.addEpisode( Episode1, Season1 ) == Episode1 assert self.show.addEpisode( Episode2, Season("1") ) == Episode2 assert self.show.addEpisode( Episode1, Season("1") ) == None assert self.show.addEpisode( Episode1, Season2 ) == Season2 assert self.show.addEpisode( Episode2, Season("2") ) == Episode2 assert self.show.addEpisode( Episode2, Season2 ) == None assert self.show.addEpisode( Episode3, Season2 ) == Episode3