Esempio n. 1
0
def ScanFolder(folderpath,
               recursively=True,
               report_progress=None,
               progress_end=None):
    # Let's reset the progress bar to 0%
    log.debug("Scanning Folder %s" % folderpath)

    if report_progress == None:
        report_progress = FakeProgress

    # Let's reset the progress bar to 0%
    report_progress(0)

    parser = RecursiveParser.RecursiveParser()
    files_found = []
    try:
        # it's a file
        open(folderpath, 'r')
        if get_extension(folderpath).lower() in videofile.VIDEOS_EXT:
            files_found.append(folderpath)
        folderpath = os.path.dirname(folderpath)
    except IOError:
        # it's a directory
        # Scanning VIDEOS
        files_found = parser.getRecursiveFileList(folderpath,
                                                  videofile.VIDEOS_EXT)

    videos_found = []
    # only work the video files if any were found
    if len(files_found):
        percentage = 100 / len(files_found)
        count = 0
        for i, filepath in enumerate(files_found):
            log.debug("Parsing %s ..." % filepath)
            if metadata.parse(filepath):
                videos_found.append(videofile.VideoFile(filepath))
            count += percentage

            # ,_("Parsing video: %s")% os.path.basename(filepath))
            report_progress(count)
    report_progress(0)

    # Scanning Subs
    files_found = parser.getRecursiveFileList(folderpath,
                                              subtitlefile.SUBTITLES_EXT)
    subs_found = []
    # only work the subtitles if any were found
    if len(files_found):
        percentage = 100 / len(files_found)
        count = 0
        for i, filepath in enumerate(files_found):
            subs_found.append(
                subtitlefile.SubtitleFile(online=False, id=filepath))
            count += percentage
            report_progress(count)  # ,_("Parsing sub: %s") % filepath)
    report_progress(100)  # ,_("Finished hashing"))
    if progress_end:
        progress_end()

    return videos_found, subs_found
Esempio n. 2
0
def ScanSubtitlesFolder(folderpath, recursively=True, report_progress=None, progress_end=None):
    if report_progress == None:
        report_progress = FakeProgress

    # Let's reset the progress bar to 0%
    report_progress(0)
    # Scanning Subs
    if recursively:
        files_found = parser.getRecursiveFileList(
            folderpath, subtitlefile.SUBTITLES_EXT)
    else:
        files_found = []
        for filename in os.listdir(folderpath):
            if os.path.isfile(os.path.join(folderpath, filename)) and get_extension(filename).lower() in subtitlefile.SUBTITLES_EXT:
                files_found.append(os.path.join(folderpath, filename))

    subs_found = []
    # only work the subtitles if any were found
    if len(files_found):
        percentage = 100 / len(files_found)
        count = 0
        for i, filepath in enumerate(files_found):
            subs_found.append(
                subtitlefile.SubtitleFile(online=False, id=filepath))
            count += percentage
            report_progress(count, _("Parsing sub: %s") % os.path.basename(
                filepath).decode(sys.getfilesystemencoding()))
    report_progress(100, _("Finished hashing"))
    if progress_end:
        progress_end()

    return subs_found
Esempio n. 3
0
def ScanFilesFolders(filepaths,
                     recursively=True,
                     report_progress=None,
                     progress_end=None):
    all_videos_found = []
    all_subs_found = []
    for path in filepaths:
        log.debug("Scanning: %s" % path)

        if os.path.isdir(path):
            videos_found, subs_found = ScanFolder(
                path,
                recursively=True,
                report_progress=report_progress,
                progress_end=progress_end)
            all_videos_found += videos_found
            all_subs_found += subs_found
        else:
            if get_extension(path).lower() in videofile.VIDEOS_EXT:
                all_videos_found.append(videofile.VideoFile(path))
            # Interested to know which subtitles we have in the same folder
            all_subs_found += ScanSubtitlesFolder(
                os.path.dirname(path),
                recursively=False,
                report_progress=report_progress,
                progress_end=progress_end)
    return all_videos_found, all_subs_found
Esempio n. 4
0
def ScanFolder(folderpath, recursively=True, report_progress=None, progress_end=None):
    # Let's reset the progress bar to 0%
    log.debug("Scanning Folder %s" % folderpath)

    if report_progress == None:
        report_progress = FakeProgress

    # Let's reset the progress bar to 0%
    report_progress(0)

    parser = RecursiveParser.RecursiveParser()
    files_found = []
    try:
        # it's a file
        open(folderpath, 'r')
        if get_extension(folderpath).lower() in videofile.VIDEOS_EXT:
            files_found.append(folderpath)
        folderpath = os.path.dirname(folderpath)
    except IOError:
        # it's a directory
        # Scanning VIDEOS
        files_found = parser.getRecursiveFileList(
            folderpath, videofile.VIDEOS_EXT)

    videos_found = []
    # only work the video files if any were found
    if len(files_found):
        percentage = 100 / len(files_found)
        count = 0
        for i, filepath in enumerate(files_found):
            log.debug("Parsing %s ..." % filepath)
            if metadata.parse(filepath):
                videos_found.append(videofile.VideoFile(filepath))
            count += percentage

            # ,_("Parsing video: %s")% os.path.basename(filepath))
            report_progress(count)
    report_progress(0)

    # Scanning Subs
    files_found = parser.getRecursiveFileList(
        folderpath, subtitlefile.SUBTITLES_EXT)
    subs_found = []
    # only work the subtitles if any were found
    if len(files_found):
        percentage = 100 / len(files_found)
        count = 0
        for i, filepath in enumerate(files_found):
            subs_found.append(
                subtitlefile.SubtitleFile(online=False, id=filepath))
            count += percentage
            report_progress(count)  # ,_("Parsing sub: %s") % filepath)
    report_progress(100)  # ,_("Finished hashing"))
    if progress_end:
        progress_end()

    return videos_found, subs_found
Esempio n. 5
0
def subtitle_name_gen(video_filename, extension=".srt"):
    """Generates a subtitle file name given the video file name
    """
    video_name = ""
    sub_name = ""
    if isinstance(video_filename, str):
       # video_filename = video_filename.lower()
        if get_extension(video_filename) in videofile.VIDEOS_EXT:
            video_name = without_extension(video_filename)
    elif isinstance(video_filename, videofile):
        if get_extension(video_filename.getFileName()) in videofile.VIDEOS_EXT:
            video_name = without_extension(video_filename.getFileName())

    if video_name:
        sub_name = video_name + extension
        return sub_name
    else:
        log.debug("No video name to generate subtitle file name")
        return ""
Esempio n. 6
0
def ScanFilesFolders(filepaths,recursively = True,report_progress=None, progress_end=None):
    all_videos_found = []
    all_subs_found = []
    for path in filepaths:
        log.debug("Scanning: %s"% path)

        if os.path.isdir(path):
            videos_found, subs_found = ScanFolder(path,recursively = True,report_progress=report_progress, progress_end=progress_end)
            all_videos_found += videos_found
            all_subs_found += subs_found
        else:
            if get_extension(path).lower() in videofile.VIDEOS_EXT:
                all_videos_found.append(videofile.VideoFile(path))
             #Interested to know which subtitles we have in the same folder
            all_subs_found += ScanSubtitlesFolder(os.path.dirname(path),recursively = False,report_progress=report_progress, progress_end=progress_end) 
    return all_videos_found, all_subs_found
Esempio n. 7
0
def ScanSubtitlesFolder(folderpath,
                        recursively=True,
                        report_progress=None,
                        progress_end=None):
    if report_progress == None:
        report_progress = FakeProgress

    # Let's reset the progress bar to 0%
    report_progress(0)
    # Scanning Subs
    if recursively:
        files_found = parser.getRecursiveFileList(folderpath,
                                                  subtitlefile.SUBTITLES_EXT)
    else:
        files_found = []
        for filename in os.listdir(folderpath):
            if os.path.isfile(os.path.join(
                    folderpath, filename)) and get_extension(
                        filename).lower() in subtitlefile.SUBTITLES_EXT:
                files_found.append(os.path.join(folderpath, filename))

    subs_found = []
    # only work the subtitles if any were found
    if len(files_found):
        percentage = 100 / len(files_found)
        count = 0
        for i, filepath in enumerate(files_found):
            subs_found.append(
                subtitlefile.SubtitleFile(online=False, id=filepath))
            count += percentage
            report_progress(
                count,
                _("Parsing sub: %s") %
                os.path.basename(filepath).decode(sys.getfilesystemencoding()))
    report_progress(100, _("Finished hashing"))
    if progress_end:
        progress_end()

    return subs_found
Esempio n. 8
0
def isVideofile(filepath):
    if get_extension(filepath).lower() in videofile.VIDEOS_EXT:
        return True
    return False
Esempio n. 9
0
def isSubtitle(filepath):
    if get_extension(filepath).lower() in subtitlefile.SUBTITLES_EXT:
        return True
    return False
Esempio n. 10
0
def GetLangFromFilename(filepath):
    filepath = os.path.basename(filepath)
    if filepath.count('.') >= 2:
        return get_extension(without_extension(filepath))
    else:
        return ""