Exemple #1
0
def main():
    slogging.setupLogging()

    if PY2:
        import codecs
        import locale
        import sys

        # see http://bugs.python.org/issue2128
        if os.name == "nt":
            for i, a in enumerate(sys.argv):
                sys.argv[i] = a.decode(locale.getpreferredencoding())

        # see https://github.com/wackou/guessit/issues/43
        # and http://stackoverflow.com/questions/4545661/unicodedecodeerror-when-redirecting-to-file
        # Wrap sys.stdout into a StreamWriter to allow writing unicode.
        sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)

    parser = OptionParser(usage="usage: %prog [options] file1 [file2...]")
    parser.add_option(
        "-v", "--verbose", action="store_true", dest="verbose", default=False, help="display debug output"
    )
    parser.add_option(
        "-p",
        "--properties",
        dest="properties",
        action="store_true",
        default=False,
        help="Display properties that can be guessed by the filename matcher.",
    )
    parser.add_option(
        "-i",
        "--info",
        dest="info",
        default="filename",
        help="the desired information type: filename, hash_mpc or a hash from python's "
        "hashlib module, such as hash_md5, hash_sha1, ...; or a list of any of "
        "them, comma-separated",
    )
    parser.add_option(
        "-t",
        "--type",
        dest="filetype",
        default="autodetect",
        help="the suggested file type: movie, episode or autodetect",
    )
    parser.add_option(
        "-a",
        "--advanced",
        dest="advanced",
        action="store_true",
        default=False,
        help="display advanced information for filename guesses, as json output",
    )
    parser.add_option(
        "-d",
        "--demo",
        action="store_true",
        dest="demo",
        default=False,
        help="run a few builtin tests instead of analyzing a file",
    )

    options, args = parser.parse_args()
    if options.verbose:
        logging.getLogger().setLevel(logging.DEBUG)

    transformers.load()

    if options.properties:
        display_properties()
    if options.demo:
        run_demo(episodes=True, movies=True, advanced=options.advanced)
    else:
        if args:
            for filename in args:
                detect_filename(
                    filename, filetype=options.filetype, info=options.info.split(","), advanced=options.advanced
                )

        else:
            parser.print_help()
Exemple #2
0

def currentPath():
    '''Returns the path in which the calling file is located.'''
    return dirname(join(os.getcwd(), sys._getframe(1).f_globals['__file__']))


def addImportPath(path):
    '''Function that adds the specified path to the import path. The path can be
    absolute or relative to the calling file.'''
    importPath = abspath(join(currentPath(), path))
    sys.path = [importPath] + sys.path


setupLogging()
transformers.load()
logging.getLogger().setLevel(MAIN_LOGGING_LEVEL)

log = logging.getLogger(__name__)

import guessit
from guessit import *
from guessit.matcher import *
from guessit.fileutils import *


def allTests(testClass):
    return TestLoader().loadTestsFromTestCase(testClass)


class TestGuessit(TestCase):