Example #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('path',
                        type=str,
                        help="file or directory to retrieve subtitles")
    parser.add_argument('--quiet', '-q', action='store_true')
    parser.add_argument('--skip',
                        '-s',
                        type=int,
                        default=0,
                        help="skip from head")
    parser.add_argument('--force',
                        '-f',
                        action='store_true',
                        default=False,
                        help="override existing file")
    args = parser.parse_args()
    lib.setup_logger(lib.LOGGER_LEVEL)

    if not args.quiet:
        console = logging.StreamHandler()
        console.setFormatter(lib.LOGGER_FORMATTER)
        lib.logger.addHandler(console)

    cursor = FileFinder(args.path, with_extension=_extensions)

    for filepath in cursor.findFiles():
        # skip if a subtitle for this file exists
        sub_file = os.path.splitext(filepath)[0] + '.srt'
        if os.path.exists(sub_file):
            if args.force:
                os.remove(sub_file)
            else:
                continue

        filename = os.path.basename(filepath)

        try:
            info = FileParser(filename).parse()
            series_name = info.seriesname
            series_id = 's%02de%s' % (info.seasonnumber, '-'.join(
                ['%02d' % e for e in info.episodenumbers]))
            metadata = extract_meta_data(filename)
            url = lib.get_subtitle_url(series_name, series_id, metadata,
                                       args.skip)
        except lib.NoResultsError as e:
            lib.logger.error(e.message)
            raise

        with subtitle_renamer(filepath):
            lib.get_subtitle(url, 'temp__' + filename)
Example #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('path', type=str,
                        help="file or directory to retrieve subtitles")
    parser.add_argument('--quiet', '-q', action='store_true')
    parser.add_argument('--skip', '-s', type=int,
                        default=0, help="skip from head")
    parser.add_argument('--force', '-f', action='store_true',
                        default=False, help="override existing file")
    args = parser.parse_args()
    lib.setup_logger(lib.LOGGER_LEVEL)

    if not args.quiet:
        console = logging.StreamHandler()
        console.setFormatter(lib.LOGGER_FORMATTER)
        lib.logger.addHandler(console)

    cursor = FileFinder(args.path, with_extension=['avi','mkv','mp4',
                                                   'mpg','m4v','ogv',
                                                   'vob', '3gp',
                                                   'part', 'temp', 'tmp'
                                                   ])

    for filepath in cursor.findFiles():
        # skip if a subtitle for this file exists
        sub_file = os.path.splitext(filepath)[0] + '.srt'
        if os.path.exists(sub_file):
            if args.force:
              os.remove(sub_file)
            else:
              continue

        filename = os.path.basename(filepath)

        try:
            info = FileParser(filename).parse()
            series_name = info.seriesname
            series_id = 's%02de%s' % (info.seasonnumber, '-'.join(['%02d' % e for e in info.episodenumbers]))
            quality, group, codec = extract_meta_data(filename)
            url = lib.get_subtitle_url(series_name, series_id,
                                       group or quality or codec,
                                       args.skip)
        except lib.NoResultsError, e:
            lib.logger.error(e.message)
            raise

        with subtitle_renamer(filepath):
            lib.get_subtitle(url, 'temp__' + filename )
Example #3
0
def findFiles(paths):
    """Takes an array of paths, returns all files found
    """
    valid_files = []

    for cfile in paths:
        cur = FileFinder(cfile,
                         with_extension=Config['valid_extensions'],
                         filename_blacklist=Config["filename_blacklist"],
                         recursive=Config['recursive'])

        try:
            valid_files.extend(cur.findFiles())
        except InvalidPath:
            warn("Invalid path: %s" % cfile)

    if len(valid_files) == 0:
        raise NoValidFilesFoundError()

    # Remove duplicate files (all paths from FileFinder are absolute)
    valid_files = list(set(valid_files))

    return valid_files
Example #4
0
def findFiles(paths):
    """Takes an array of paths, returns all files found
    """
    valid_files = []

    for cfile in paths:
        cur = FileFinder(
            cfile,
            with_extension = Config['valid_extensions'],
            filename_blacklist = Config["filename_blacklist"],
            recursive = Config['recursive'])

        try:
            valid_files.extend(cur.findFiles())
        except InvalidPath:
            warn("Invalid path: %s" % cfile)

    if len(valid_files) == 0:
        raise NoValidFilesFoundError()

    # Remove duplicate files (all paths from FileFinder are absolute)
    valid_files = list(set(valid_files))

    return valid_files
Example #5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('path',
                        type=str,
                        help="file or directory to retrieve subtitles")
    parser.add_argument('--quiet', '-q', action='store_true')
    parser.add_argument('--choose',
                        '-c',
                        action='store_true',
                        default=False,
                        help="Choose sub manually")
    parser.add_argument('--force',
                        '-f',
                        action='store_true',
                        default=False,
                        help="override existing file")
    parser.add_argument('--keyword',
                        '-k',
                        type=str,
                        help="Add keyword to search among subtitles")
    parser.add_argument('--title',
                        '-t',
                        type=str,
                        help="Set the title of the show")
    args = parser.parse_args()
    lib.setup_logger(lib.LOGGER_LEVEL)

    if not args.quiet:
        console = logging.StreamHandler()
        console.setFormatter(lib.LOGGER_FORMATTER)
        lib.logger.addHandler(console)

    cursor = FileFinder(args.path, with_extension=_extensions)

    for filepath in cursor.findFiles():
        # skip if a subtitle for this file exists
        sub_file = os.path.splitext(filepath)[0] + '.srt'
        if os.path.exists(sub_file):
            if args.force:
                os.remove(sub_file)
            else:
                continue

        filename = os.path.basename(filepath)

        try:
            info = guessit(filename)
            number = f"s{info['season']:02}e{info['episode']:02}" if info[
                "type"] == "episode" else info["year"]

            metadata = extract_meta_data(filename, args.keyword)

            if (args.title):
                title = args.title
            else:
                title = info["title"]
            url = lib.get_subtitle_url(title, number, metadata, args.choose)
        except lib.NoResultsError as e:
            lib.logger.error(str(e))
            url = ''
        if (url != ''):
            with subtitle_renamer(filepath):
                lib.get_subtitle(url, 'temp__' + filename)