Example #1
0
def main(args=None, setup_logging=True):
    if setup_logging:
        from guessit import slogging
        slogging.setup_logging()

    if PY2:  # pragma: no cover
        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)

    # Needed for guessit.plugins.transformers.reload() to be called.
    from guessit.plugins import transformers

    if args:
        options = get_opts().parse_args(args)
    else:  # pragma: no cover
        options = get_opts().parse_args()
    if options.verbose:
        logging.getLogger().setLevel(logging.DEBUG)

    help_required = True
    if options.properties or options.values:
        display_properties(options)
        help_required = False
    elif options.transformers:
        display_transformers()
        help_required = False

    if options.demo:
        run_demo(episodes=True, movies=True, options=vars(options))
        help_required = False

    if options.version:
        print('+-------------------------------------------------------+')
        print('+                   GuessIt ' + __version__ +
              (28 - len(__version__)) * ' ' + '+')
        print('+-------------------------------------------------------+')
        print('|      Please report any bug or feature request at      |')
        print('|       https://github.com/wackou/guessit/issues.       |')
        print('+-------------------------------------------------------+')
        help_required = False

    if options.yaml:
        try:
            import yaml, babelfish

            def default_representer(dumper, data):
                return dumper.represent_str(str(data))

            yaml.SafeDumper.add_representer(babelfish.Language,
                                            default_representer)
            yaml.SafeDumper.add_representer(babelfish.Country,
                                            default_representer)
        except ImportError:  # pragma: no cover
            print('PyYAML not found. Using default output.')

    filenames = []
    if options.filename:
        filenames.extend(options.filename)
    if options.input_file:
        input_file = open(options.input_file, 'r')
        try:
            filenames.extend([line.strip() for line in input_file.readlines()])
        finally:
            input_file.close()

    filenames = filter(lambda f: f, filenames)

    if filenames:
        if options.submit_bug:
            for filename in filenames:
                help_required = False
                submit_bug(filename, options)
        else:
            for filename in filenames:
                help_required = False
                guess_file(filename,
                           info=options.info.split(','),
                           options=vars(options))

    if help_required:  # pragma: no cover
        get_opts().print_help()
Example #2
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# GuessIt - A library for guessing information from filenames
# Copyright (c) 2013 Nicolas Wack <*****@*****.**>
#
# GuessIt is free software; you can redistribute it and/or modify it under
# the terms of the Lesser GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# GuessIt is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# Lesser GNU General Public License for more details.
#
# You should have received a copy of the Lesser GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

from __future__ import absolute_import, division, print_function, unicode_literals

import logging
from guessit.slogging import setup_logging
setup_logging()
logging.disable(logging.INFO)
Example #3
0
def main(args=None, setup_logging=True):
    if setup_logging:
        from guessit import slogging
        slogging.setup_logging()

    if PY2:  # pragma: no cover
        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)

    # Needed for guessit.plugins.transformers.reload() to be called.
    from guessit.plugins import transformers

    if args:
        options = get_opts().parse_args(args)
    else:  # pragma: no cover
        options = get_opts().parse_args()
    if options.verbose:
        logging.getLogger().setLevel(logging.DEBUG)

    help_required = True
    if options.properties or options.values:
        display_properties(options)
        help_required = False
    elif options.transformers:
        display_transformers()
        help_required = False

    if options.demo:
        run_demo(episodes=True, movies=True, options=vars(options))
        help_required = False

    if options.version:
        print('+-------------------------------------------------------+')
        print('+                   GuessIt ' + __version__ + (28-len(__version__)) * ' ' + '+')
        print('+-------------------------------------------------------+')
        print('|      Please report any bug or feature request at      |')
        print('|       https://github.com/wackou/guessit/issues.       |')
        print('+-------------------------------------------------------+')
        help_required = False

    if options.yaml:
        try:
            import yaml, babelfish
            def default_representer(dumper, data):
                return dumper.represent_str(str(data))
            yaml.SafeDumper.add_representer(babelfish.Language, default_representer)
            yaml.SafeDumper.add_representer(babelfish.Country, default_representer)
        except ImportError:  # pragma: no cover
            print('PyYAML not found. Using default output.')

    filenames = []
    if options.filename:
        filenames.extend(options.filename)
    if options.input_file:
        input_file = open(options.input_file, 'r')
        try:
            filenames.extend([line.strip() for line in input_file.readlines()])
        finally:
            input_file.close()

    filenames = filter(lambda f: f, filenames)

    if filenames:
        if options.submit_bug:
            for filename in filenames:
                help_required = False
                submit_bug(filename, options)
        else:
            for filename in filenames:
                help_required = False
                guess_file(filename,
                           info=options.info.split(','),
                           options=vars(options))

    if help_required:  # pragma: no cover
        get_opts().print_help()