Exemple #1
0
    def do_matching(self, videos, subtitles):
        if self.options.logging > logging.DEBUG and self.options.verbose:
            progress = progressbar.ProgressBar(
                widgets=conf.Terminal.progress_bar_style,
                maxval=len(videos)).start()

        for i, video in enumerate(videos):
            if self.options.logging > logging.DEBUG and self.options.verbose:
                progress.update(i + 1)
            self.log.debug("Processing %s..." % video.getFileName())

            possible_subtitle = Subtitle.AutoDetectSubtitle(
                video.getFilePath())
            #self.log.debug("possible subtitle is: %s"% possible_subtitle)
            sub_match = None
            for subtitle in subtitles:
                sub_match = None
                if possible_subtitle == subtitle.getFilePath():
                    sub_match = subtitle
                    self.log.debug("Match found: %s" % sub_match.getFileName())
                    break
            if sub_match:
                sub_lang = Subtitle.AutoDetectLang(sub_match.getFilePath())
                sub_match.setLanguage(Languages.name2xxx(sub_lang))
                video.addSubtitle(sub_match)
        if self.options.logging > logging.DEBUG and self.options.verbose:
            progress.finish()
 def dropEvent(self, event):
     if event.mimeData().hasFormat('text/uri-list'):
         paths = [url for url in event.mimeData().urls()]
         # If we drop many files, only the first one will be take into
         # acount
         fileName = paths[0]
         index = self.indexAt(event.pos())
         row, col = index.row(), index.column()
         settings = QSettings()
         if col == UploadListView.COL_VIDEO:
             if (VideoTools.isVideofile(fileName)):
                 settings.setValue("mainwindow/workingDirectory", fileName)
                 video = VideoFile(fileName)
                 self.model().layoutAboutToBeChanged.emit()
                 self.model().addVideos(row, [video])
                 subtitle = Subtitle.AutoDetectSubtitle(video.getFilePath())
                 if subtitle:
                     sub = SubtitleFile(False, subtitle)
                     self.model().addSubs(row, [sub])
                     thread.start_new_thread(
                         self.uploadModel.ObtainUploadInfo, ())
                 self.resizeRowsToContents()
                 self.model().layoutChanged.emit()
         else:  # if it's the column in SUBTITLES
             print(fileName)
             if (Subtitle.isSubtitle(fileName)):
                 settings.setValue("mainwindow/workingDirectory", fileName)
                 sub = SubtitleFile(False, fileName)
                 self.model().layoutAboutToBeChanged.emit()
                 self.model().addSubs(row, [sub])
                 self.resizeRowsToContents()
                 self.model().layoutChanged.emit()
                 thread.start_new_thread(self.uploadModel.ObtainUploadInfo,
                                         ())
 def dropEvent(self, event):
     if event.mimeData().hasFormat('text/uri-list'):
         paths = [url for url in event.mimeData().urls()]
         # If we drop many files, only the first one will be take into
         # acount
         fileName = paths[0]
         index = self.indexAt(event.pos())
         row, col = index.row(), index.column()
         settings = QSettings()
         if col == UploadListView.COL_VIDEO:
             if(VideoTools.isVideofile(fileName)):
                 settings.setValue("mainwindow/workingDirectory", fileName)
                 video = VideoFile(fileName)
                 self.model().layoutAboutToBeChanged.emit()
                 self.model().addVideos(row, [video])
                 subtitle = Subtitle.AutoDetectSubtitle(video.getFilePath())
                 if subtitle:
                     sub = SubtitleFile(False, subtitle)
                     self.model().addSubs(row, [sub])
                     thread.start_new_thread(
                         self.uploadModel.ObtainUploadInfo, ())
                 self.resizeRowsToContents()
                 self.model().layoutChanged.emit()
         else:  # if it's the column in SUBTITLES
             print(fileName)
             if(Subtitle.isSubtitle(fileName)):
                 settings.setValue("mainwindow/workingDirectory", fileName)
                 sub = SubtitleFile(False, fileName)
                 self.model().layoutAboutToBeChanged.emit()
                 self.model().addSubs(row, [sub])
                 self.resizeRowsToContents()
                 self.model().layoutChanged.emit()
                 thread.start_new_thread(
                     self.uploadModel.ObtainUploadInfo, ())
    def AutoDetectLangFromFileName(self):
        all_langs = []
        xxx_lang = ""
        for sub in self._subs:
            if sub:
                lang = sub.getLanguage()
                if lang == None:
                    lang = Subtitle.GetLangFromFilename(sub.getFilePath())
                    if len(lang) == 2 and lang in languages.ListAll_xx():
                        all_langs.append(languages.xx2xxx(lang))
                    elif len(lang) == 3 and lang in languages.ListAll_xxx():
                        all_langs.append(lang)
                else:
                    all_langs.append(lang)

        max = 0
        max_lang = ""
        for lang in all_langs:
            if all_langs.count(lang) > max:
                max = all_langs.count(lang)
                max_lang = lang

        xxx_lang = max_lang
        log.debug("Majoritary Language Autodetected by filename = " +
                  str(xxx_lang))
        if xxx_lang:
            self._main.language_updated.emit(xxx_lang, "filename")
    def AutoDetectLangFromContent(self):
        all_langs = []
        for sub in self._subs:
            if sub:
                lang = sub.getLanguage()
                if lang == None:
                    lang = Subtitle.AutoDetectLang(sub.getFilePath())
                    sub.setLanguage(lang)
                all_langs.append(lang)


# FIXME: Clean this code here and put it in a shared script for also CLI to use
        max = 0
        max_lang = ""
        for lang in all_langs:
            if all_langs.count(lang) > max:
                max = all_langs.count(lang)
                max_lang = lang

        xxx_lang = languages.name2xxx(max_lang)
        log.debug("Majoritary Language Autodetected by content = " +
                  str(xxx_lang))
        if xxx_lang:
            self._main.language_updated.emit(xxx_lang, "content")
Exemple #6
0
    def subtitles_to_download(self):
        subtitles_to_download = {}
        self.log.debug("Building subtitle matrix ...")
        for video in self.videos:
            self.log.debug("(total: %i online: %i..." % (video.getTotalSubtitles(), video.getTotalOnlineSubtitles()))
            if video.getTotalOnlineSubtitles() == 1:
                subtitle = video.getOneSubtitle()
                choice = "y"
                if self.interactive:
                    self.log.info(
                        "Only one subtitle was found for %s: %s" % (video.getFileName(), subtitle.getFileName())
                    )
                    choice = input("Is that correct? [Y/n]").lower() or "y"
                if choice == "y":
                    self.log.debug("- adding: %s: %s" % (subtitle.getIdFileOnline(), subtitle.getFileName()))
                    # subtitles_to_download[subtitle.getIdFileOnline()] = {'subtitle_path': os.path.join(video.getFolderPath(), subtitle.getFileName()), 'video': video}
                    if self.rename_subs:
                        subtitle_filename = Subtitle.subtitle_name_gen(video.getFileName())
                    else:
                        subtitle_filename = subtitle.getFileName()
                    subtitles_to_download[subtitle.getIdFileOnline()] = os.path.join(
                        video.getFolderPath(), subtitle_filename
                    )
            elif video.getTotalOnlineSubtitles() > 1:
                choice = "auto_"
                if self.interactive:
                    self.log.info('Looks like "%s" has more than one subtitle candidate.' % video.getFileName())
                    choices = ["auto"]
                    for i, sub in enumerate(video.getOnlineSubtitles()):
                        self.log.info("[%i] %s (rate: %s)" % (i, sub.getFileName(), sub.getRating()))
                        choices += [str(i)]
                    self.log.info("[auto] Subdownloader will select one for you.")
                    while choice not in choices:
                        choice = input("Please make your choice: [auto] ").lower() or "auto"
                    if choice != "auto":
                        sub_choice = video.getOnlineSubtitles()[int(choice)]

                if choice == "auto" or choice == "auto_":
                    # set a starting point to compare scores
                    best_rated_sub = video.getOnlineSubtitles()[0]
                    # iterate over all subtitles
                    subpath_list = {}
                    for sub in video.getOnlineSubtitles():
                        subpath_list[sub.getIdOnline()] = sub
                        if sub.getRating() > best_rated_sub.getRating():
                            best_rated_sub = sub
                    # compare video name with subtitles name to find best match
                    # FIXME: seems u sending a dictionary, but this function
                    # needs a list
                    sub_match = Subtitle.AutoDetectSubtitle(video.getFilePath(), sub_list=subpath_list)
                    if sub_match:
                        self.log.debug("Subtitle choosen by match")
                        sub_choice = subpath_list[sub_match]
                    else:
                        self.log.debug("Subtitle choosen by rating")
                        sub_choice = best_rated_sub
                    self.log.debug("- adding: %s" % (sub_choice.getFileName()))

                # subtitles_to_download[sub_choice.getIdFileOnline()] = {'subtitle_path': os.path.join(video.getFolderPath(), sub_choice.getFileName()), 'video': video}
                if self.rename_subs:
                    subtitle_filename = Subtitle.subtitle_name_gen(video.getFileName())
                else:
                    subtitle_filename = sub_choice.getFileName()

                #                subtitle_filename = Subtitle.subtitle_name_gen(video.getFileName())
                # subtitles_to_download[sub_choice.getIdFileOnline()] = {'subtitle_path': os.path.join(video.getFolderPath(), subtitle_filename), 'video': video}
                subtitles_to_download[sub_choice.getIdFileOnline()] = os.path.join(
                    video.getFolderPath(), subtitle_filename
                )
            else:
                self.log.info('No subtitle was downloaded "%s". Maybe you already have it?' % video.getFileName())

        return subtitles_to_download
Exemple #7
0
    def subtitles_to_download(self):
        subtitles_to_download = {}
        self.log.debug("Building subtitle matrix ...")
        for video in self.videos:
            self.log.debug(
                "(total: %i online: %i..." %
                (video.getTotalSubtitles(), video.getTotalOnlineSubtitles()))
            if video.getTotalOnlineSubtitles() == 1:
                subtitle = video.getOneSubtitle()
                choice = 'y'
                if self.interactive:
                    self.log.info(
                        "Only one subtitle was found for %s: %s" %
                        (video.getFileName(), subtitle.getFileName()))
                    choice = input("Is that correct? [Y/n]").lower() or 'y'
                if choice == 'y':
                    self.log.debug(
                        "- adding: %s: %s" %
                        (subtitle.getIdFileOnline(), subtitle.getFileName()))
                    #subtitles_to_download[subtitle.getIdFileOnline()] = {'subtitle_path': os.path.join(video.getFolderPath(), subtitle.getFileName()), 'video': video}
                    if self.rename_subs:
                        subtitle_filename = Subtitle.subtitle_name_gen(
                            video.getFileName())
                    else:
                        subtitle_filename = subtitle.getFileName()
                    subtitles_to_download[
                        subtitle.getIdFileOnline()] = os.path.join(
                            video.getFolderPath(), subtitle_filename)
            elif video.getTotalOnlineSubtitles() > 1:
                choice = 'auto_'
                if self.interactive:
                    self.log.info(
                        "Looks like \"%s\" has more than one subtitle candidate."
                        % video.getFileName())
                    choices = ['auto']
                    for i, sub in enumerate(video.getOnlineSubtitles()):
                        self.log.info("[%i] %s (rate: %s)" %
                                      (i, sub.getFileName(), sub.getRating()))
                        choices += [str(i)]
                    self.log.info(
                        "[auto] Subdownloader will select one for you.")
                    while choice not in choices:
                        choice = input("Please make your choice: [auto] "
                                       ).lower() or 'auto'
                    if choice != 'auto':
                        sub_choice = video.getOnlineSubtitles()[int(choice)]

                if choice == 'auto' or choice == 'auto_':
                    # set a starting point to compare scores
                    best_rated_sub = video.getOnlineSubtitles()[0]
                    # iterate over all subtitles
                    subpath_list = {}
                    for sub in video.getOnlineSubtitles():
                        subpath_list[sub.getIdOnline()] = sub
                        if sub.getRating() > best_rated_sub.getRating():
                            best_rated_sub = sub
                    # compare video name with subtitles name to find best match
                    # FIXME: seems u sending a dictionary, but this function
                    # needs a list
                    sub_match = Subtitle.AutoDetectSubtitle(
                        video.getFilePath(), sub_list=subpath_list)
                    if sub_match:
                        self.log.debug("Subtitle choosen by match")
                        sub_choice = subpath_list[sub_match]
                    else:
                        self.log.debug("Subtitle choosen by rating")
                        sub_choice = best_rated_sub
                    self.log.debug("- adding: %s" % (sub_choice.getFileName()))

                #subtitles_to_download[sub_choice.getIdFileOnline()] = {'subtitle_path': os.path.join(video.getFolderPath(), sub_choice.getFileName()), 'video': video}
                if self.rename_subs:
                    subtitle_filename = Subtitle.subtitle_name_gen(
                        video.getFileName())
                else:
                    subtitle_filename = sub_choice.getFileName()

#                subtitle_filename = Subtitle.subtitle_name_gen(video.getFileName())
#subtitles_to_download[sub_choice.getIdFileOnline()] = {'subtitle_path': os.path.join(video.getFolderPath(), subtitle_filename), 'video': video}
                subtitles_to_download[
                    sub_choice.getIdFileOnline()] = os.path.join(
                        video.getFolderPath(), subtitle_filename)
            else:
                self.log.info(
                    "No subtitle was downloaded \"%s\". Maybe you already have it?"
                    % video.getFileName())

        return subtitles_to_download