Пример #1
0
    def eventFilter(self, _, event):
        if event.type() == QtCore.QEvent.MouseButtonPress:
            self.setIcon(ResourcesManager.get_icon("save_button_red"))
            self.save_subs()
            return True

        elif event.type() == QtCore.QEvent.Leave:
            self.setIcon(ResourcesManager.get_icon("save"))
            return True

        return False
Пример #2
0
 def __init__(self, country, flag_widget):
     super(FlagButton, self).__init__()
     self.released_path = ResourcesManager.get_flag(country)[0]
     self.pressed_path = ResourcesManager.get_flag_pressed(country)[0]
     self.country = country
     self.setIcon(QIcon(self.released_path))
     self.clicked.connect(self.on_click)
     self.flag_widget = flag_widget
     self.setCheckable(True)
     self.setStyleSheet(CssManager.get_css_as_string(self))
     self.setIconSize(QSize(100, 150))
Пример #3
0
 def download_video(cls, youtube_url):
     youtube = pytube.YouTube(youtube_url)
     video = None
     try:
         video = youtube.streams.otf(False).first()
     except HTTPError as ex:
         logging.error(
             "YoutubeDownloader: GOOGLE Server is rejecting our requests with ex: ",
             ex)
         exit(-1)
     video.download(ResourcesManager.get_place_to_store_yt_videos())
     to_ret = ResourcesManager.get_place_to_store_yt_videos(
     ) + "\\" + youtube.streams[0].default_filename
     return to_ret.replace("\\", "/")
Пример #4
0
 def __init__(self, main_interface_instance):
     super(MenuWidget, self).__init__()
     self.addStretch(1)
     self.main_interface_instance = main_interface_instance
     self.button_open_new = ResourcesManager.get_return_button()
     self.button_open_new.clicked.connect(self.return_to_previous)
     self.addWidget(self.button_open_new, 0, Qt.AlignRight)
Пример #5
0
 def __init__(self, player_wrapper, subtitles):
     super().__init__(ResourcesManager.get_icon("save"))
     self.subtitles = subtitles
     self.media_player = player_wrapper
     self.clicked.connect(self.save_subs)
     self.setMouseTracking(True)
     self.installEventFilter(self)
Пример #6
0
    def reload_sentences(self):

        self.sentences = ResourcesManager.read_saved_subs()
        if len(self.sentences) != 0:
            self.index = randint(0, len(self.sentences) - 1)
            self.set_text()
        else:
            self.setText("Learn words by saving them")
Пример #7
0
    def _generate_subtitles(cls, path_to_wav):
        if path_to_wav is None:
            logging.error("Path to wav is None!")
            exit(1)
        if not os.path.exists(ResourcesManager.get_resource('model')):
            logging.error(
                "Please download the model from https://alphacephei.com/vosk/models and unpack as "
                "'model' in the resources folder.")
            exit(1)

        wf = wave.open(path_to_wav, "rb")

        model = Model(ResourcesManager.get_resource('model'))
        rec = KaldiRecognizer(model, wf.getframerate())
        while True:
            data = wf.readframes(4000)
            if len(data) == 0:
                break
            rec.AcceptWaveform(data)
        return rec.FinalResult()
Пример #8
0
    def create_subtitles(cls, path_to_file) -> Optional[str]:
        """
        Creates subtitles to given file,
        if file extension is not in SUPPORTED_EXTENSIONS
        :param path_to_file: path to file to which subtitles should be generated
        :return: path to subtitles with txt extension or None in case of failure
        """
        if not path_to_file.endswith(SUPPORTED_EXTENSIONS):
            logging.error("File extension not supported.")
            return None

        SubtitlesGenerator._enable_logs(True)
        new_path = SubtitlesGenerator._convert_to_mono_wav(
            path_to_file, ResourcesManager.get_resource('tmp'))
        if new_path is None:
            return None
        result = SubtitlesGenerator._generate_subtitles(new_path)
        SubtitlesGenerator._remove_tmp_file(new_path)
        return SubtitlesGenerator.write_to_txt(
            result, ResourcesManager.get_resource('subtitles'), path_to_file)
Пример #9
0
    def __init__(self):
        super().__init__()
        self.resize(800, 600)

        self.setStyleSheet("""
        *{
        background: rgb(222,97,218);
        background: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(158, 61, 103, 255), stop:0.509465 rgba(158, 57, 135, 255), stop:1 rgba(117, 60, 158, 255));
        }
        """)
        self.layout = QVBoxLayout()
        self.menu_box = MenuWidget(self)
        self.layout.addLayout(self.menu_box)
        self.window_type = None
        self.setWindowTitle("Subtitles Player")
        self.setWindowIcon(QIcon(ResourcesManager.get_resource('icon.png')))
Пример #10
0
 def write_subtitles_to_file(self):
     now = datetime.now()
     to_write = {
         "date":
         now.strftime("%d/%m/%Y %H:%M:%S"),
         "original_sentence":
         self.dictionary[self.current_position]["sentence"],
         "translated_sentence":
         self.dictionary[self.current_position][f"sentence_{self.to_lang}"],
         "language":
         self.to_lang
     }
     with open(ResourcesManager.get_user_learned(), 'a',
               encoding='utf-8') as file:
         file.write(json.dumps(to_write) + "\n")
     logging.debug("subtitles: wrote sentence to file")
Пример #11
0
    def __init__(self):
        """
        list_of_commands = {
        "What has been done" : is_done
        }
        """
        super(LoadingWidget, self).__init__()
        self.text_messages = QVBoxLayout()
        self.loading_process = QLabel()
        self.setStyleSheet(CssManager.get_css_as_string(self))
        self.label = QLabel()
        self.movie = QMovie(ResourcesManager.get_loading_gif())
        self.label.setMovie(self.movie)
        self.movie.start()
        self.text_messages.addWidget(self.label, 0, Qt.AlignCenter)

        self.text_messages.addWidget(self.loading_process, 0, Qt.AlignCenter)
        self.setLayout(self.text_messages)
        self.list_of_commands = {}
Пример #12
0
 def play(self):
     self.setIcon(ResourcesManager.get_icon("state_pause"))
     self.play_status = True
     self.media_player.play()
Пример #13
0
 def pause(self):
     self.setIcon(ResourcesManager.get_icon("state_play"))
     self.play_status = False
     self.media_player.pause()
Пример #14
0
 def __init__(self, player_wrapper):
     super().__init__(ResourcesManager.get_icon("state_pause"))
     self.media_player = player_wrapper
     self.play_status = True
     self.clicked.connect(self.change_state)