Пример #1
0
    def on_node_expanded(self, index):
        node = index.internalPointer()
        node.set_expanded(True)

        data = node.get_data()
        if isinstance(data, RemoteMovieNetwork):
            remote_movie_network = data
            if not remote_movie_network.get_nb_subs_available() and remote_movie_network.get_nb_subs_total():
                callback = ProgressCallbackWidget(self._treeview)
                callback.set_title_text(_('Search'))
                callback.set_label_text(_('Searching...'))
                callback.set_cancellable(False)
                callback.set_block(True)

                callback.show()

                success = False
                try:
                    # FIXME: use callback
                    success = remote_movie_network.search_more_subtitles()
                except ProviderConnectionError:
                    pass

                if not success:
                    QMessageBox.about(self._treeview, _('Info'),
                                      _('An unknown problem occurred or this type of movie cannot be handled.'))
                    self._treeview.collapse(index)
                    node.set_expanded(False)
                    callback.finish()
                    return

                # FIXME: do not use Node objects but add metadata to objects
                self.underlying_data_changed()

                callback.finish()
Пример #2
0
    def on_node_expanded(self, index):
        node = index.internalPointer()
        node.set_expanded(True)

        data = node.get_data()
        if isinstance(data, RemoteMovie):
            movie = data
            if not movie.get_nb_subs_available() and movie.get_nb_subs_total():
                callback = ProgressCallbackWidget(self._treeview)
                callback.set_title_text(_('Search'))
                callback.set_label_text(_("Searching..."))
                callback.set_cancellable(False)
                callback.set_block(True)

                callback.show()

                # FIXME: don't create SearchByName object here
                s = SearchByName('')
                callback.update(0)
                added_subtitles = s.search_more_subtitles(movie=movie)
                if added_subtitles is None:
                    QMessageBox.about(self._treeview, _("Info"),
                                      _("An unknown problem occurred or this type of movie cannot be handled."))
                    self._treeview.collapse(index)
                else:
                    node_origin = node.get_clone_origin()
                    for subtitle in added_subtitles:
                        node_origin.add_child(subtitle)
                    if movie.get_nb_subs_available() < movie.get_nb_subs_total():
                        node_origin.add_child(SearchMore(what=movie, text=_('More subtitles ...')))
                    self._apply_filters()
                callback.finish()
Пример #3
0
    def onExpandMovie(self, index):
        if index.internalPointer() is None:
            return
        movie = index.internalPointer().data
        if type(movie) == Movie and not movie.subtitles and movie.totalSubs:

            callback = ProgressCallbackWidget(self)
            callback.set_title_text(_('Search'))
            callback.set_label_text(_("Searching..."))
            callback.set_cancellable(False)
            callback.set_block(True)

            callback.show()

            s = SearchByName()
            selected_language = self.ui.filterLanguage.get_selected_language()
            selected_language_xxx = None if selected_language.is_generic(
            ) else selected_language.xxx()
            callback.update(0)
            temp_movie = s.search_movie(
                languages=[UnknownLanguage.create_generic()],
                MovieID_link=movie.MovieSiteLink)
            # The internal results are not filtered by language, so in case we change the filter, we don't need to request again.
            # print temp_movie
            try:
                movie.subtitles = temp_movie[0].subtitles
            except IndexError:
                QMessageBox.about(
                    self, _("Info"),
                    _("This is a TV series and it cannot be handled."))
                callback.finish()
                return
            except AttributeError:
                # this means only one subtitle was returned
                movie.subtitles = [temp_movie[1]]
            # The treeview is filtered by language
            self.moviesModel.updateMovie(index, selected_language_xxx)
            self.ui.moviesView.collapse(index)
            self.ui.moviesView.expand(index)
            callback.finish()
Пример #4
0
    def onUploadButton(self, clicked):
        ok, error = self.uploadModel.validate()
        if not ok:
            QMessageBox.about(self, _("Error"), error)
            return
        else:
            imdb_id = self.ui.uploadIMDB.itemData(self.ui.uploadIMDB.currentIndex())
            if imdb_id is None:  # No IMDB
                QMessageBox.about(
                    self, _("Error"), _("Please identify the movie."))
                return
            else:
                callback = ProgressCallbackWidget(self)
                callback.set_title_text(_("Uploading..."))
                callback.set_label_text(_("Uploading subtitle"))
                callback.set_block(True)
                callback.set_cancellable(False)

                callback.show()

                log.debug("Compressing subtitle...")
                details = {}
                details['IDMovieImdb'] = imdb_id
                lang_xxx = self.ui.uploadLanguages.itemData(
                        self.ui.uploadLanguages.currentIndex())
                details['sublanguageid'] = lang_xxx
                details['movieaka'] = ''
                details['moviereleasename'] = self.ui.uploadReleaseText.text()
                comments = self.ui.uploadComments.toPlainText()
                details['subauthorcomment'] = comments

                movie_info = {}
                movie_info['baseinfo'] = {'idmovieimdb': details['IDMovieImdb'], 'moviereleasename': details['moviereleasename'], 'movieaka': details[
                    'movieaka'], 'sublanguageid': details['sublanguageid'], 'subauthorcomment': details['subauthorcomment']}

                nb = self.uploadModel.getTotalRows()
                callback.set_range(0, nb)
                for i in range(nb):
                    curr_sub = self.uploadModel._subs[i]
                    curr_video = self.uploadModel._videos[i]
                    if curr_sub:  # Make sure is not an empty row with None
                        buf = open(curr_sub.getFilePath(), mode='rb').read()
                        curr_sub_content = base64.encodestring(zlib.compress(buf))
                        cd = "cd" + str(i)
                        movie_info[cd] = {'subhash': curr_sub.get_hash(), 'subfilename': curr_sub.get_filepath(), 'moviehash': curr_video.get_hash(), 'moviebytesize': curr_video.get_size(
                        ), 'movietimems': curr_video.get_time_ms(), 'moviefps': curr_video.get_fps(), 'moviefilename': curr_video.get_filepath(), 'subcontent': curr_sub_content}
                    callback.update(i)

                try:
                    info = self.get_state().upload(movie_info)
                    callback.finish()
                    if info['status'] == "200 OK":
                        successBox = QMessageBox(_("Successful Upload"),
                                                 _(
                                                     "Subtitles successfully uploaded.\nMany Thanks!"),
                                                 QMessageBox.Information,
                                                 QMessageBox.Ok | QMessageBox.Default | QMessageBox.Escape,
                                                 QMessageBox.NoButton,
                                                 QMessageBox.NoButton,
                                                 self)

                        saveAsButton = successBox.addButton(
                            _("View Subtitle Info"), QMessageBox.ActionRole)
                        answer = successBox.exec_()
                        if answer == QMessageBox.NoButton:
                            webbrowser.open(info['data'], new=2, autoraise=1)
                        self.uploadCleanWindow()
                    else:
                        QMessageBox.about(self, _("Error"), _(
                            "Problem while uploading...\nError: %s") % info['status'])
                except:
                    callback.finish()
                    QMessageBox.about(self, _("Error"), _(
                        "Error contacting the server. Please restart or try later"))