def dir_dl(sub_count=1): ''' Download subtitles for the movies in a directory. ''' # start_time = time.time() cwd = os.getcwd() for folders, movies in MOVIES_DIR.iteritems(): os.chdir(folders) print "Downloading Subtitles for [%s]" % folders logger.info("Downloading Subtitles for [%s]" % folders) for mov in movies: subdb_check = subdb.get_sub(hash=subdb.get_hash(mov), filename=mov, language='en') if subdb_check == 200: logger.info("Subtitle Downloaded for %s" % (mov)) print("Subtitle Downloaded for %s" % (mov)) elif subdb != 200: logger.info("Subtitles for [%s] not found on AllSubDB" % (mov)) logger.info("Searching for subtitles on subscene - now") sub_link = subscene.sel_title(os.path.splitext(mov)[0]) if sub_link: if subscene.sel_sub(page=sub_link, name=mov): for i in subscene.sel_sub(page=sub_link, sub_count=sub_count, name=mov): subscene.dl_sub(i) else: print "Subtitle not found for [%s]" % ( mov.capitalize()) logger.debug("Subtitle not found for [%s]" % (mov)) else: print "Subtitle not found for [%s]" % (mov.capitalize()) logger.debug("Subtitle not found for [%s]" % (mov)) os.chdir(cwd)
def dir_dl(sub_count=1): """ Download subtitles for the movies in a directory. """ # start_time = time.time() cwd = os.getcwd() for folders, movies in MOVIES_DIR.items(): os.chdir(folders) print("Downloading Subtitles for [{}]".format(folders)) logger.info("Downloading Subtitles for [{}]".format(folders)) for mov in movies: subdb_check = subdb.get_sub( file_hash=subdb.get_hash(mov), filename=mov, language="en" ) if subdb_check == 200: logger.info("Subtitle Downloaded for {}".format(mov)) print("Subtitle Downloaded for {}".format(mov)) elif subdb != 200: logger.info( "Subtitles for [{}] not found on AllSubDB".format(mov) ) logger.info("Searching for subtitles on subscene - now") sub_link = subscene.sel_title(os.path.splitext(mov)[0]) if sub_link: # Remove extension from mov argument selected_sub = subscene.sel_sub( page=sub_link, name=os.path.splitext(mov)[0] ) if selected_sub: for i in selected_sub: subscene.dl_sub(i) else: print( "Subtitle not found for [{}]".format( mov.capitalize() ) ) logger.debug("Subtitle not found for [{}]".format(mov)) else: print( "Subtitle not found for [{}]".format(mov.capitalize()) ) logger.debug("Subtitle not found for [{}]".format(mov)) os.chdir(cwd)
def main(): parser = argparse.ArgumentParser() parser.add_argument( "-d", "--dir", default=".", help="Specify directory to work in." ) parser.add_argument( "-m", "--media-name", nargs="+", help="Provide movie name." ) parser.add_argument( "-s", "--silent", action="store_true", help="Silent mode." ) parser.add_argument( "-c", "--count", type=int, default=1, help="Number of subtitles to be downloaded.", ) parser.add_argument("-l", "--lang", default="EN", help="Change language.") args = parser.parse_args() logger.debug("Input with flags: {}".format(sys.argv)) logger.info("Initialized SubGrab script") if args.silent: # If mode is silent logger.debug("Executing Silent Mode") subscene.MODE = "silent" if args.lang: # Select language - Enter first two letters of the language if len(args.lang) == 2: subscene.DEFAULT_LANG = subscene.LANGUAGE[args.lang.upper()] logger.info("Set Language: {}".format(args.lang)) else: sys.exit("Invalid language specified.") if args.dir != ".": # Searches for movies in specified directory. logger.debug("Running in directory: {}".format(args.dir)) try: os.chdir(args.dir) # Create folder for the files in the current directory.create_folder() # directory (which are not in a folder). directory.get_media_files() directory.dir_dl() except Exception as e: logger.debug("Invalid Directory Input - {}".format(e)) print("Invalid Directory Input - {}".format(e)) elif args.dir == "." and not args.media_name: # Searches for movies in current directory. directory.create_folder() directory.get_media_files() directory.dir_dl(sub_count=args.count) elif args.media_name: # Searches for the specified movie. args.media_name = " ".join(args.media_name) logger.info("Searching For: {}".format(args.media_name)) sub_link = subscene.sel_title(name=args.media_name.replace(" ", ".")) logger.info( "Subtitle Link for {} : {}".format(args.media_name, sub_link) ) if sub_link: for i in subscene.sel_sub( page=sub_link, sub_count=args.count, name=args.media_name ): logger.debug("Downloading Subtitle: {}\n".format(i)) subscene.dl_sub(i) else: print("Incorrect Arguments Specified.")