diff --git a/vocabsieve/config/general_tab.py b/vocabsieve/config/general_tab.py index 9cda669..fba68c0 100644 --- a/vocabsieve/config/general_tab.py +++ b/vocabsieve/config/general_tab.py @@ -1,7 +1,8 @@ import json from bidict import bidict from PyQt5.QtWidgets import QLabel, QComboBox, QLineEdit, QPushButton, QCheckBox, QFormLayout -from PyQt5.QtCore import pyqtSignal +from PyQt5.QtCore import pyqtSignal, QRegExp +from PyQt5.QtGui import QRegExpValidator from .base_tab import BaseTab from ..constants import langcodes from .dictmanager import DictManager @@ -23,6 +24,8 @@ def initWidgets(self): "\nfor frequency lists from Migaku. ") self.bold_word = QCheckBox("Bold selected word") self.audio_format = QComboBox() + self.preferred_accent = QLineEdit() + self.preferred_accent.setValidator(QRegExpValidator(QRegExp("[a-z]{2}"))) self.freq_source = QComboBox() self.gtrans_lang = QComboBox() self.web_preset = QComboBox() @@ -59,6 +62,9 @@ def setupLayout(self): layout.addRow(QLabel("Forvo audio format"), self.audio_format) layout.addRow(QLabel("◊ Choose mp3 for playing on iOS, " "but ogg may save space")) + layout.addRow(QLabel("Forvo preferred accent"), self.preferred_accent) + layout.addRow(QLabel("Will prefer provided accent by sorting it to the top of the pronunciations list")) + layout.addRow(QLabel("Pronunciations have an accent in brackets e.g. yelkoastur(es)/gracias")) layout.addRow(QLabel("Frequency list"), self.freq_source) layout.addRow(self.lemfreq) layout.addRow( @@ -105,6 +111,7 @@ def setupAutosave(self): 'en', code_translate=True) self.register_config_handler(self.audio_format, 'audio_format', 'mp3') + self.register_config_handler(self.preferred_accent, 'preferred_accent', '') self.register_config_handler(self.lemfreq, 'lemfreq', True) self.register_config_handler( diff --git a/vocabsieve/sources/forvo_audio_source.py b/vocabsieve/sources/forvo_audio_source.py index 606cfba..5a93bae 100644 --- a/vocabsieve/sources/forvo_audio_source.py +++ b/vocabsieve/sources/forvo_audio_source.py @@ -35,12 +35,11 @@ class PronunciationList: class Forvo: - def __init__(self, word, lang, accent=""): + def __init__(self, word, lang): self.url = "https://forvo.com/word/" + quote(word) self.pronunciations = [] self.session = requests.Session() self.language = lang - self.accent = accent def get_pronunciations(self): res = cached_get(self.url, forvo_headers=True) @@ -64,11 +63,6 @@ def get_pronunciations(self): filter( lambda el: el.language == self.language, available_pronunciations_lists)) - if self.accent: - available_pronunciations_lists = list( - filter( - lambda el: el.accent == self.accent, - available_pronunciations_lists)) for l in available_pronunciations_lists: pronunciation_item = l.pronunciation_list @@ -139,7 +133,7 @@ def get_pronunciations(self): ) self.pronunciations.append(pronunciation_object) - self.pronunciations = sorted(self.pronunciations, key=lambda x: x.votes, reverse=True) + self.pronunciations = sorted(self.pronunciations, key=lambda x: (x.accent != settings.value("preferred_accent", ""), -x.votes)) # Non-matching accents after, then sort by votes descending return self