def tvnamer(paths): """Main tvnamer function, takes an array of paths, does stuff. """ p("#" * 20) p("# Starting tvnamer") episodes_found = [] for cfile in findFiles(paths): parser = FileParser(cfile) try: episode = parser.parse() except InvalidFilename as e: warn("Invalid filename: %s" % e) else: if episode.seriesname is None and Config['force_name'] is None and Config['series_id'] is None: warn("Parsed filename did not contain series name (and --name or --series-id not specified), skipping: %s" % cfile) else: episodes_found.append(episode) if len(episodes_found) == 0: raise NoValidFilesFoundError() p("# Found %d episode" % len(episodes_found) + ("s" * (len(episodes_found) > 1))) # Sort episodes by series name, season and episode number episodes_found.sort(key = lambda x: x.sortable_info()) # episode sort order if Config['order'] == 'dvd': dvdorder = True else: dvdorder = False if not PY2 and os.getenv("TRAVIS", "false") == "true": # Disable caching on Travis-CI because in Python 3 it errors with: # # Can't pickle <class 'http.cookiejar.DefaultCookiePolicy'>: it's not the same object as http.cookiejar.DefaultCookiePolicy cache = False else: cache = True tvdb_instance = Tvdb( interactive = not Config['select_first'], search_all_languages = Config['search_all_languages'], language = Config['language'], dvdorder = dvdorder, cache=cache, apikey=TVNAMER_API_KEY, ) for episode in episodes_found: processFile(tvdb_instance, episode) p('') p("#" * 20) p("# Done")
def tvnamer(paths): """Main tvnamer function, takes an array of paths, does stuff. """ p("#" * 20) p("# Starting tvnamer") episodes_found = [] for cfile in findFiles(paths): parser = FileParser(cfile) try: episode = parser.parse() except InvalidFilename as e: warn("Invalid filename: %s" % e) else: if episode.seriesname is None and Config['force_name'] is None and Config['series_id'] is None: warn("Parsed filename did not contain series name (and --name or --series-id not specified), skipping: %s" % cfile) else: episodes_found.append(episode) if len(episodes_found) == 0: raise NoValidFilesFoundError() p("# Found %d episode" % len(episodes_found) + ("s" * (len(episodes_found) > 1))) # Sort episodes by series name, season and episode number episodes_found.sort(key = lambda x: x.sortable_info()) # episode sort order if Config['order'] == 'dvd': dvdorder = True else: dvdorder = False if not PY2 and os.getenv("TRAVIS", "false") == "true": # Disable caching on Travis-CI because in Python 3 it errors with: # # Can't pickle <class 'http.cookiejar.DefaultCookiePolicy'>: it's not the same object as http.cookiejar.DefaultCookiePolicy cache = False else: cache = True tvdb_instance = Tvdb( interactive = not Config['select_first'], search_all_languages = Config['search_all_languages'], language = Config['language'], dvdorder = dvdorder, cache=cache, ) for episode in episodes_found: processFile(tvdb_instance, episode) p('') p("#" * 20) p("# Done")
def check_case(curtest): """Runs test case, used by test_generator """ parser = FileParser(curtest['input']) theep = parser.parse() assert theep.seriesname.lower() == curtest['parsedseriesname'].lower(), "%s == %s" % ( theep.seriesname.lower(), curtest['parsedseriesname'].lower()) assertEquals(theep.seasonnumber, curtest['seasonnumber']) assertEquals(theep.episodenumbers, curtest['episodenumbers'])
def check_case(curtest): """Runs test case, used by test_generator """ parser = FileParser(curtest['input']) theep = parser.parse() assert theep.seriesname.lower() == curtest['parsedseriesname'].lower( ), "%s == %s" % (theep.seriesname.lower(), curtest['parsedseriesname'].lower()) assertEquals(theep.episodenumbers, curtest['episodenumbers']) if not isinstance(theep, (DatedEpisodeInfo, NoSeasonEpisodeInfo)): assertEquals(theep.seasonnumber, curtest['seasonnumber'])
def check_case(curtest): """Runs test case, used by test_parsing_generator """ parser = FileParser(curtest['input']) theep = parser.parse() if theep.seriesname is None and curtest['parsedseriesname'] is None: pass # allow for None seriesname else: assert theep.seriesname.lower() == curtest['parsedseriesname'].lower(), "%s == %s" % ( theep.seriesname.lower(), curtest['parsedseriesname'].lower()) assertEquals(theep.episodenumbers, curtest['episodenumbers']) if not isinstance(theep, (DatedEpisodeInfo, NoSeasonEpisodeInfo)): assertEquals(theep.seasonnumber, curtest['seasonnumber'])
def check_case(curtest): """Runs test case, used by test_parsing_generator """ parser = FileParser(curtest['input']) theep = parser.parse() if theep.seriesname is None and curtest['parsedseriesname'] is None: pass # allow for None seriesname else: assert theep.seriesname.lower() == curtest['parsedseriesname'].lower(), "%s == %s" % ( theep.seriesname.lower(), curtest['parsedseriesname'].lower()) assertEquals(theep.episodenumbers, curtest['episodenumbers']) if hasattr(curtest, 'seasonnumber'): assertEquals(int(theep.seasonnumber), curtest['seasonnumber'])
if __name__ == '__main__': if len(sys.argv) < 2: paths = [_fromdir] else: paths = sys.argv[1:] print('Moving files from {} to {}'.format(paths, _todir)) episodes_found = [] #Look for video files for validfile in findFiles(paths): #Parse the filename parser = FileParser(validfile) try: episode = parser.parse() except InvalidFilename as e: print("\nInvalid filename: {}".format(e)) continue else: #Need show name if episode.seriesname is None: print("\nSeries name not found: {}".format(validfile)) continue else: episodes_found.append(episode) if not episodes_found: exit('\nNo episodes found...') # Sort episodes by series, season and episode