示例#1
0
def guess_filename(filename, options):
    """
    Guess a single filename using given options
    """
    if not options.yaml and not options.json and not options.show_property:
        print('For:', filename)

    cmd_options = vars(options)
    cmd_options['implicit'] = True  # Force implicit option in CLI

    guess = api.guessit(filename, vars(options))

    if options.show_property:
        print(guess.get(options.show_property, ''))
        return

    if options.json:
        print(json.dumps(guess, cls=GuessitEncoder, ensure_ascii=False))
    elif options.yaml:
        import yaml
        from guessit import yamlutils

        ystr = yaml.dump({filename: dict(guess)}, Dumper=yamlutils.CustomDumper, default_flow_style=False,
                         allow_unicode=True)
        i = 0
        for yline in ystr.splitlines():
            if i == 0:
                print("? " + yline[:-1])
            elif i == 1:
                print(":" + yline[1:])
            else:
                print(yline)
            i += 1
    else:
        print('GuessIt found:', json.dumps(guess, cls=GuessitEncoder, indent=4, ensure_ascii=False))
示例#2
0
def guess_filename(filename, options):
    """
    Guess a single filename using given options
    :param filename: filename to parse
    :type filename: str
    :param options:
    :type options: dict
    :return:
    :rtype:
    """
    if not options.get('yaml') and not options.get('json') and not options.get(
            'show_property'):
        print('For:', filename)

    guess = api.guessit(filename, options)

    if options.get('show_property'):
        print(guess.get(options.get('show_property'), ''))
        return

    if options.get('json'):
        print(json.dumps(guess, cls=GuessitEncoder, ensure_ascii=False))
    elif options.get('yaml'):
        # pylint:disable=import-outside-toplevel
        import yaml
        from guessit import yamlutils

        ystr = yaml.dump({filename: OrderedDict(guess)},
                         Dumper=yamlutils.CustomDumper,
                         default_flow_style=False,
                         allow_unicode=True)
        i = 0
        for yline in ystr.splitlines():
            if i == 0:
                print("? " + yline[:-1])
            elif i == 1:
                print(":" + yline[1:])
            else:
                print(yline)
            i += 1
    else:
        print(
            'GuessIt found:',
            json.dumps(guess, cls=GuessitEncoder, indent=4,
                       ensure_ascii=False))
示例#3
0
def guess_filename(filename, options):
    """
    Guess a single filename using given options
    """
    if not options.yaml and not options.json and not options.show_property:
        print('For:', filename)

    cmd_options = vars(options)
    cmd_options['implicit'] = True  # Force implicit option in CLI

    guess = api.guessit(filename, vars(options))

    if options.show_property:
        print(guess.get(options.show_property, ''))
        return

    if options.json:
        print(json.dumps(guess, cls=GuessitEncoder, ensure_ascii=False))
    elif options.yaml:
        import yaml
        from guessit import yamlutils

        ystr = yaml.dump({filename: dict(guess)},
                         Dumper=yamlutils.CustomDumper,
                         default_flow_style=False,
                         allow_unicode=True)
        i = 0
        for yline in ystr.splitlines():
            if i == 0:
                print("? " + yline[:-1])
            elif i == 1:
                print(":" + yline[1:])
            else:
                print(yline)
            i += 1
    else:
        print(
            'GuessIt found:',
            json.dumps(guess, cls=GuessitEncoder, indent=4,
                       ensure_ascii=False))
示例#4
0
def guess_filename(filename, options):
    """
    Guess a single filename using given options
    :param filename: filename to parse
    :type filename: str
    :param options:
    :type options: dict
    :return:
    :rtype:
    """
    if not options.get('yaml') and not options.get('json') and not options.get('show_property'):
        print('For:', filename)

    guess = api.guessit(filename, options)

    if options.get('show_property'):
        print(guess.get(options.get('show_property'), ''))
        return

    if options.get('json'):
        print(json.dumps(guess, cls=GuessitEncoder, ensure_ascii=False))
    elif options.get('yaml'):
        import yaml
        from guessit import yamlutils

        ystr = yaml.dump({filename: dict(guess)}, Dumper=yamlutils.CustomDumper, default_flow_style=False,
                         allow_unicode=True)
        i = 0
        for yline in ystr.splitlines():
            if i == 0:
                print("? " + yline[:-1])
            elif i == 1:
                print(":" + yline[1:])
            else:
                print(yline)
            i += 1
    else:
        print('GuessIt found:', json.dumps(guess, cls=GuessitEncoder, indent=4, ensure_ascii=False))