Esempio n. 1
0
    def launch(self):
        use_multidownload = bool(get_current_user()) and \
            len(self.args.file) > 1

        if use_multidownload:
            echo('Using multi-download')
            Version.multidownload(*zip(*self.iter_files()))

        else:
            for (version, output_file) in self.iter_files():
                version.download(output_file)
Esempio n. 2
0
    def launch(self):
        use_multidownload = bool(get_current_user()) and \
            len(self.args.file) > 1

        files = list(self.iter_files())

        if not files:
            echo('Nothing to download')

        elif use_multidownload:
            echo('Using multi-download')
            Version.multidownload(files)

        else:
            for (version, output_file) in files:
                version.download(output_file)
Esempio n. 3
0
    def launch(self):
        use_multidownload = bool(get_current_user()) and \
            len(self.args.file) > 1

        files = list(self.iter_files())

        if not files:
            echo('Nothing to download')

        elif use_multidownload:
            echo('Using multi-download')
            Version.multidownload(files)

        else:
            for (version, output_file) in files:
                version.download(output_file)
Esempio n. 4
0
def main():

    import textwrap
    import pkg_resources
    import sys

    version = pkg_resources.require('addic7ed-cli')[0].version

    epilog = '''
    Authentification:

      You can login with your addic7ed.com identifiers to increase your daily
      download quota:

      * Anonymous users are limited to 15 downloads per 24 hours on their IP
        address

      * Registered users are limited to 40

      * VIPs get 80 downloads (please consider donating)

    Configuration file:

      You can store frequently used options in a configuration file. Create a
      file at ~/.config/addic7ed (Linux, OSX) or %APPDATA%/config (Windows),
      and it will be parsed using the Python ConfigParser (see example below).
      It can contain three sections:

      * [flags], to set a flag (verbose, hearing-impaired, overwrite, ignore,
        batch or brute-batch, see :code:`addic7ed search --help` for
        informations about those flags)

      * [languages], to list prefered languages

      * [session], the session to use for authentification (this is automatically
        populated when using :code:`addic7ed login`)

      Example:

        [flags]
        hearing-impaired = no
        batch

        [languages]
        french
        english

        [session]
        abcdef

    Video organizer:
      video-organizer format is supported. If a "filelist" file is next to an
      episode, it will use it to extract its real name and forge the good
      query. See https://github.com/JoelSjogren/video-organizer for further
      informations.
    '''

    namespace = Arguments()
    namespace.read_defaults()

    parser = ArgumentParser(
        description='Downloads SRT files from addic7ed.com.',
        epilog=textwrap.dedent(epilog),
        formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument('-V',
                        '--version',
                        action='version',
                        version='%%(prog)s version %s' % version)

    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        help='Print some debugging informations.')

    parser.configure_subparser(help='Command to run. If no command is given, '
                               'the default is "search".',
                               dest='command')

    parser.add_subparser('search',
                         help='Search for a subtitle and download it')

    parser.add_argument('file',
                        nargs='+',
                        help='Subtitle file name. The extension will be '
                        'replaced by .srt, so an existing video file name '
                        'can be given.')

    parser.add_argument('-q',
                        '--query',
                        help='Custom query. (default: based on the filename)')

    parser.add_argument('-r',
                        '--release',
                        help='Custom release. (default: based on the '
                        'filename)')

    parser.add_argument('-l',
                        '--language',
                        action='append',
                        default=[],
                        help='Prefer a language. (could be specified more '
                        'than one time for fallbacks)')

    parser.add_argument('-H',
                        '--hearing-impaired',
                        action='store_true',
                        help='Prefer hearing impaired version.',
                        default=namespace.hearing_impaired)

    parser.add_argument('--no-hearing-impaired',
                        dest='hearing_impaired',
                        action='store_false')

    parser.add_argument('-o',
                        '--overwrite',
                        action='store_true',
                        help='Always overwrite the SRT if it exists.',
                        default=namespace.overwrite)

    parser.add_argument('--no-overwrite',
                        dest='overwrite',
                        action='store_false')

    parser.add_argument('-i',
                        '--ignore',
                        action='store_true',
                        help='Never overwrite the SRT if it exists.',
                        default=namespace.ignore)

    parser.add_argument('--no-ignore', dest='ignore', action='store_false')

    parser.add_argument('-b',
                        '--batch',
                        action='store_true',
                        help='Do not ask anything, get the best matching '
                        'subtitle. Cancel if the search returns more than one '
                        'result.',
                        default=namespace.batch)

    parser.add_argument('--no-batch', dest='batch', action='store_false')

    parser.add_argument('-bb',
                        '--brute-batch',
                        action='store_true',
                        help='Do not ask anything, get the best matching '
                        'subtitle. Use the first result of the search.',
                        default=namespace.brute_batch)

    parser.add_argument('--no-brute-batch',
                        dest='brute_batch',
                        action='store_false')

    parser.add_argument('--lang-suffix',
                        action='store_true',
                        help='Append the lang to the output subtitle '
                        'filename.',
                        default=namespace.lang_suffix)

    parser.add_argument('--no-lang-suffix',
                        dest='lang_suffix',
                        action='store_false')

    parser.add_subparser('login',
                         help='Login on addic7ed.com. This is not required.')

    parser.add_subparser('logout', help='Logout from addic7ed.com.')
    args = sys.argv[1:]

    if args and args[0] not in parser.first_candidates:
        args[0:0] = ('search', )

    parser.parse_args(args=args, namespace=namespace)

    if not namespace.command:
        parser.print_usage()
        exit(1)

    if namespace.verbose:
        echo('Using configuration file {}'.format(
            namespace.configuration_path))

    if namespace.session:
        set_session(namespace.session)
        user = get_current_user()
        if user:
            echo('Logged as {}'.format(user))

    try:
        globals()[namespace.command](namespace)

    except Error as e:
        echo('Error: {}'.format(e))
        exit(1)

    except FatalError as e:
        echo('Fatal error: {}'.format(e))
        exit(1)

    except KeyboardInterrupt:
        echo('Aborted by user')
        exit(1)
Esempio n. 5
0
def main():

    import textwrap
    import pkg_resources
    import sys

    version = pkg_resources.require('addic7ed-cli')[0].version

    epilog = '''
    Authentification:

      You can login with your addic7ed.com identifiers to increase your daily
      download quota:

      * Anonymous users are limited to 15 downloads per 24 hours on their IP
        address

      * Registered users are limited to 40

      * VIPs get 80 downloads (please consider donating)

    Configuration file:

      You can store frequently used options in a configuration file. Create a
      file at ~/.config/addic7ed (Linux, OSX) or %APPDATA%/config (Windows),
      and it will be parsed using the Python ConfigParser (see example below).
      It can contain three sections:

      * [flags], to set a flag (verbose, hearing-impaired, overwrite, ignore,
        batch or brute-batch)

      * [languages], to list prefered languages

      * [session], the session to use for authentification

      Example:

        [flags]
        hearing-impaired = no
        batch

        [languages]
        french
        english

        [session]
        abcdef

    Video organizer:
      video-organizer format is supported. If a "filelist" file is next to an
      episode, it will use it to extract its real name and forge the good
      query. See https://github.com/JoelSjogren/video-organizer for further
      informations.
    '''

    parser = ArgumentParser(
        description='Downloads SRT files from addic7ed.com.',
        epilog=textwrap.dedent(epilog),
        formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument('-V', '--version', action='version',
                        version='%%(prog)s version %s' % version)

    parser.add_argument('-v', '--verbose', action='store_true',
                        help='Print some debugging informations.')

    parser.configure_subparser(help='Command to run. If no command is given, '
                               'the default is "search".',
                               dest='command')

    parser.add_subparser('search',
                         help='Search for a subtitle and download it')

    parser.add_argument('file', nargs='+',
                        help='Subtitle file name. The extension will be '
                        'replaced by .srt, so an existing video file name '
                        'can be given.')

    parser.add_argument('-q', '--query',
                        help='Custom query. (default: based on the filename)')

    parser.add_argument('-r', '--release',
                        help='Custom release. (default: based on the '
                        'filename)')

    parser.add_argument('-l', '--language', action='append', default=[],
                        help='Prefer a language. (could be specified more '
                        'than one time for fallbacks)')

    parser.add_argument('-H', '--hearing-impaired', action='store_true',
                        help='Prefer hearing impaired version.')

    parser.add_argument('--no-hearing-impaired', dest='hearing_impaired',
                        action='store_false')

    parser.add_argument('-o', '--overwrite', action='store_true',
                        help='Always overwrite the SRT if it exists.')

    parser.add_argument('-i', '--ignore', action='store_true',
                        help='Never overwrite the SRT if it exists.')

    parser.add_argument('-b', '--batch', action='store_true',
                        help='Do not ask anything, get the best matching '
                        'subtitle. Cancel if the search returns more than one '
                        'result.')

    parser.add_argument('-bb', '--brute-batch', action='store_true',
                        help='Do not ask anything, get the best matching '
                        'subtitle. Use the first result of the search.')

    parser.add_subparser('login',
                         help='Login on addic7ed.com. This is not required.')

    parser.add_subparser('logout',
                         help='Logout from addic7ed.com.')
    args = sys.argv[1:]

    if args and args[0] not in parser.first_candidates:
        args[0:0] = ('search',)

    namespace = Arguments()
    namespace.read_defaults()

    parser.parse_args(args=args, namespace=namespace)

    if not namespace.command:
        parser.print_usage()
        exit(1)

    if namespace.session:
        set_session(namespace.session)
        user = get_current_user()
        if user:
            echo('Logged as', user)

    try:
        globals()[namespace.command](namespace)

    except Error as e:
        echo('Error:', e)
        exit(1)

    except FatalError as e:
        echo('Fatal error:', e)
        exit(1)

    except KeyboardInterrupt:
        echo('Aborted by user')
        exit(1)