Merge pull request #2139 from dalf/fix_update_languages

Fix update languages
This commit is contained in:
Markus Heiser 2023-01-29 17:59:59 +01:00 committed by GitHub
commit 4f808088f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 10 deletions

View file

@ -22,9 +22,7 @@ about = {
categories = ["videos"] categories = ["videos"]
paging = True paging = True
base_url = "https://peer.tube" base_url = "https://peer.tube"
supported_languages_url = ( supported_languages_url = 'https://peer.tube/api/v1/videos/languages'
'https://framagit.org/framasoft/peertube/search-index/-/raw/master/client/src/views/Search.vue'
)
# do search-request # do search-request
@ -84,9 +82,6 @@ def response(resp):
def _fetch_supported_languages(resp): def _fetch_supported_languages(resp):
import re videolanguages = resp.json()
peertube_languages = list(videolanguages.keys())
# https://docs.python.org/3/howto/regex.html#greedy-versus-non-greedy
videolanguages = re.search(r"videoLanguages \(\)[^\n]+(.*?)\]", resp.text, re.DOTALL)
peertube_languages = [m.group(1) for m in re.finditer(r"\{ id: '([a-z]+)', label:", videolanguages.group(1))]
return peertube_languages return peertube_languages

View file

@ -106,9 +106,9 @@ def _fetch_supported_languages(resp):
for tr in trs: for tr in trs:
td = tr.xpath('./td') td = tr.xpath('./td')
code = td[3].xpath('./a')[0].text code = td[3].xpath('./a')[0].text
name = td[2].xpath('./a')[0].text name = td[1].xpath('./a')[0].text
english_name = td[1].xpath('./a')[0].text english_name = td[1].xpath('./a')[0].text
articles = int(td[4].xpath('./a/b')[0].text.replace(',', '')) articles = int(td[4].xpath('./a')[0].text.replace(',', ''))
# exclude languages with too few articles # exclude languages with too few articles
if articles >= 100: if articles >= 100:
supported_languages[code] = {"name": name, "english_name": english_name} supported_languages[code] = {"name": name, "english_name": english_name}