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.episodenumbers, curtest['episodenumbers']) if not isinstance(theep, (DatedEpisodeInfo, NoSeasonEpisodeInfo)): assertEquals(theep.seasonnumber, curtest['seasonnumber'])
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 get_content_in_directory(self, directory): if not os.path.exists(directory): return content = {} keys = ['title', 'season', 'episode'] for item in os.listdir(directory): parsed = PTN.parse(item) # get rid of the useless stuff for key in list(parsed): if key not in keys: del parsed[key] if len(parsed) > 0: if 'title' in parsed: fetched_title = None try: if 'episode' in parsed: parsed['title'] = parsed['title'].lower() fetched_title = FileParser( parsed['title'] + '.S' + str(parsed['season']) + 'E' + str(parsed['episode'])).parse( ).generateFilename() else: fetched_title = FileParser( parsed['title']).parse().generateFilename() except InvalidFilename: fetched_title = parsed['title'] if fetched_title != None: if '].' in fetched_title: index = fetched_title.index('].') fetched_title = fetched_title[:index] + ']' if 'episode' in parsed: self.fetched_titles[ parsed['title'] + '.S' + str(parsed['season']) + 'E' + str(parsed['episode'])] = fetched_title else: self.fetched_titles[ parsed['title']] = fetched_title content[item] = parsed return content
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'])
def main(): parser = argparse.ArgumentParser() parser.add_argument('path', type=str, help="file or directory to retrieve subtitles") parser.add_argument('--quiet', '-q', action='store_true') parser.add_argument('--skip', '-s', type=int, default=0, help="skip from head") parser.add_argument('--force', '-f', action='store_true', default=False, help="override existing file") args = parser.parse_args() lib.setup_logger(lib.LOGGER_LEVEL) if not args.quiet: console = logging.StreamHandler() console.setFormatter(lib.LOGGER_FORMATTER) lib.logger.addHandler(console) cursor = FileFinder(args.path, with_extension=_extensions) for filepath in cursor.findFiles(): # skip if a subtitle for this file exists sub_file = os.path.splitext(filepath)[0] + '.srt' if os.path.exists(sub_file): if args.force: os.remove(sub_file) else: continue filename = os.path.basename(filepath) try: info = FileParser(filename).parse() series_name = info.seriesname series_id = 's%02de%s' % (info.seasonnumber, '-'.join( ['%02d' % e for e in info.episodenumbers])) metadata = extract_meta_data(filename) url = lib.get_subtitle_url(series_name, series_id, metadata, args.skip) except lib.NoResultsError as e: lib.logger.error(e.message) raise with subtitle_renamer(filepath): lib.get_subtitle(url, 'temp__' + filename)
def cur_test(): for seas in xrange(1, 11): for ep in xrange(1, 11): name_data = cdata['name_data'] name_data['seasno'] = seas name_data['epno'] = ep names = [x % name_data for x in name_formats] for cur in names: p = FileParser(cur).parse() assertEquals(p.episodenumbers, [name_data['epno']]) assertEquals(p.seriesname, name_data['seriesname']) # Only EpisodeInfo has seasonnumber if not isinstance(p, (DatedEpisodeInfo, NoSeasonEpisodeInfo)): assertEquals(p.seasonnumber, name_data['seasno'])
def tvnamer(filename): try: episode = FileParser(filename).parse() except Exception, e: return(False,null)
def test_noseasonepisodeinfo_naming(): """Parsing a e23 episode should return NoSeasonEpisodeInfo class """ p = FileParser("scrubs - e23.avi").parse() assertType(p, NoSeasonEpisodeInfo) assertEquals(p.generateFilename(), "scrubs - [23].avi")
def test_datedepisodeinfo_naming(): """Parsing a 2009.06.05 episode should return DatedEpisodeInfo class """ p = FileParser("scrubs.2009.06.05.avi").parse() assertType(p, DatedEpisodeInfo) assertEquals(p.generateFilename(), "scrubs - [2009-06-05].avi")
def test_episodeinfo_naming(): """Parsing a s01e01 episode should return EpisodeInfo class """ p = FileParser("scrubs.s01e01.avi").parse() assertType(p, EpisodeInfo) assertEquals(p.generateFilename(), "scrubs - [01x01].avi")
def test_noseasonepisodeinfo(): """Parsing a e23 episode should return NoSeasonEpisodeInfo class """ p = FileParser("scrubs - e23.avi").parse() assertType(p, NoSeasonEpisodeInfo)
def test_datedepisodeinfo(): """Parsing a 2009.06.05 episode should return DatedEpisodeInfo class """ p = FileParser("scrubs.2009.06.05.avi").parse() assertType(p, DatedEpisodeInfo)
def test_episodeinfo(): """Parsing a s01e01 episode should return EpisodeInfo class """ p = FileParser("scrubs.s01e01.avi").parse() assertType(p, EpisodeInfo)
def tvnamer(filename,show): try: episode = FileParser(filename).parse() except Exception, e: syslog.syslog(syslog.LOG_ERR,"tvnamer sur " + filename) exit(0)
_todir = "/media/Gargant/Film/TV-Serier/" 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...')