Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preferred accent option #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion vocabsieve/config/general_tab.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -59,6 +62,9 @@ def setupLayout(self):
layout.addRow(QLabel("Forvo audio format"), self.audio_format)
layout.addRow(QLabel("<i>◊ Choose mp3 for playing on iOS, "
"but ogg may save space</i>"))
layout.addRow(QLabel("Forvo preferred accent"), self.preferred_accent)
layout.addRow(QLabel("<i>Will prefer provided accent by sorting it to the top of the pronunciations list</i>"))
layout.addRow(QLabel("<i>Pronunciations have an accent in brackets e.g. yelkoastur(es)/gracias</i>"))
layout.addRow(QLabel("Frequency list"), self.freq_source)
layout.addRow(self.lemfreq)
layout.addRow(
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 2 additions & 8 deletions vocabsieve/sources/forvo_audio_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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


Expand Down