@@ -0,0 +1,3105 @@
+#!/usr/bin/env python3%0A# -*- coding: utf-8 -*-%0A%0Aimport utilities%0Aimport seriesMatch%0Aimport findTitle%0Aimport logging%0Aimport logging.config%0Aimport argparse%0Aimport os%0A%0Alogging.config.fileConfig(%22logging.ini%22,disable_existing_loggers=False)%0Alogger = logging.getLogger('root')%0A%0A%0Adef main():%0A    parser = argparse.ArgumentParser(description='Will automatically sort and rename anime files in a folder based off information gathered from anidb.net')%0A    subparsers = parser.add_subparsers(help='subcommand help', dest='command')%0A    sortParser = subparsers.add_parser('sort', help='Will sort anime based on anidb info')%0A    sortParser.add_argument(%22fromDir%22, help=%22The directory with the files you want to sort%22)%0A    sortParser.add_argument(%22toDir%22, help=%22The directory where files will go once sorted%22)%0A    sortParser.add_argument(%22-s%22, %22--silent%22, action=%22store_true%22,%0A                    help=%22Turn off output to console (will still log to file)%22)%0A%0A    undoParser =  subparsers.add_parser('undo', help='undo file sorting based of of a history csv file')%0A    undoParser.add_argument(%22startLine%22, type=int, help=%22the line of the csv file to start rename undo (enter 0 0 to undo entire file)%22)%0A    undoParser.add_argument(%22endLine%22, type=int, help=%22the line of the csv file to end rename undo (enter 0 to only undo the line of startLine)%22)%0A    undoParser.add_argument(%22-f%22, %22--file%22, help=%22history csv file containing the original path then the current path%22)%0A    args = parser.parse_args()%0A%0A%0A%0A    if args.command == 'undo':%0A        logger.info('start moving file back to their original locations')%0A        try:%0A            if args.file is None:%0A                utilities.undoRename(args.startLine, args.endLine)%0A            else:%0A                utilities.undoRename(args.startLine, args.endLine, args.file)%0A        except ValueError:%0A            logger.error(%22Could not undo specified line please check history csv file and ensure that line isn't blank%22)%0A            exit(1)%0A        logger.info('files have finished moving back to their original locations')%0A    elif args.command == 'sort':%0A        #%22/home/jeremy/.gvfs/torrents on jeremy-htpc/complete/%22%0A        #fromDir = %22test%22%0A        #toDir = %22final%22%0A        fromDir = args.fromDir%0A        toDir = args.toDir%0A        silent = args.silent%0A        cacheDir='cache'%0A%0A        #TODO add support for command line arguments%0A        version = 1%0A%0A        logger.info(%22Starting to group files%22)%0A        try:%0A            allShows = seriesMatch.groupAnimeFiles(fromDir, silentMode=silent)%0A        except IOError as e:%0A            logger.error(%22Program exited with an error%22)%0A            exit(1)%0A        logger.info(%22Finished grouping files%22)%0A%0A        logger.info(%22Starting to generate filenames%22)%0A        allNewFilenames = findTitle.generateFilenames(version, allShows, toDir, cacheDir)%0A        logger.info(%22Finished generating filenames%22)%0A%0A        logger.info(%22Starting to rename files%22)%0A        utilities.renameFiles(allNewFilenames, storeHistory=True)%0A        logger.info(%22Files have been renamed%22)%0A    else:%0A        exit(1)%0A%0Aif __name__ == '__main__':%0A    main()%0A

rename file