def setUp(self): self.cache = SceneFileMetadataCache() self.cache.clear() self.meta1 = SceneFileMetadata( show="Bob's Burgers", season=9, episode=7, title='I Bob Your Pardon' ) self.meta2 = SceneFileMetadata( show="bobs burgers", season=9, episode=9, title="UFO No You Didn't" )
def fetchEpisodes(showName): # Make sure to fetch from TVMaze only once per application run if cache.hasShow(showName): return try: url = buildUrl(showName) response = six.moves.urllib.request.urlopen( url) # nosec The URL is guaranteed to be safe by buildUrl data = json.loads(response.read()) # If the server decided to return no episode data, mark the show as unknown if '_embedded' not in data: cache.markAsUnknown(showName) else: for episode in data['_embedded']['episodes']: meta = SceneFileMetadata(show=showName, season=episode['season'], episode=episode['number'], title=episode['name']) cache.add(meta) except BaseException: logging.warning("Couldn't find show %s", showName) cache.markAsUnknown(showName)
def setUp(self): self.testFile = SceneFile('test.mkv', '/dl') self.testFile.meta = SceneFileMetadata( show='Black Mirror', season=1, episode=3, title='The Entire History of You') self.pattern = '%a/Season %s/%s.%n - %t'
def test_generate_filename_unknown_episode_title(self): testFile = SceneFile('test2.avi', '/dl') testFile.meta = SceneFileMetadata(show='Cold Feet', season=2, episode=4) targetFilename = generateFilename(testFile, self.pattern) self.assertEqual(targetFilename, 'Cold Feet/Season 2/2.4 - Episode 4.avi')
def extractMetadata(fileName): # Normalise to whitespace-separated words fileName = re.sub("[._]", " ", fileName) # Look for relevant parts parts = re.split(REGEX_SPLITTER, fileName) # If we can't split into SHOWNAME - SEASON+EPISODE move on. if len(parts) < 2: return None # Additionally clean the show name (remove special characters, capitalise) show = re.sub(REGEX_CLEANER, "", parts[0]).title() # TODO: Apply substitutions on the show name # Get season and episode numbers subparts = re.split(REGEX_EPISODE_SPLITTER, parts[1]) season = int(subparts[1]) episode = int(subparts[2]) meta = SceneFileMetadata(show=show, season=season, episode=episode) return meta
def test_complete_meta(self): meta = SceneFileMetadata(show='3rd Rock from the Sun', season=1, episode=15, title='I Enjoy Being a Dick') self.assertTrue(meta.isComplete())
def test_incomplete_meta(self): meta = SceneFileMetadata(show='Dark', season=1, episode=4) self.assertFalse(meta.isComplete())
def test_titles_can_be_fetched_from_cache(self): meta = SceneFileMetadata(show="Bob's Burgers", season=3, episode=12) self.assertEquals(getTitle(meta), 'Broadcast Wagstaff School News')