Fix #11
This commit is contained in:
commit
abc9d348d1
|
@ -265,43 +265,43 @@ class MovieQuerySet(models.QuerySet):
|
||||||
else:
|
else:
|
||||||
return f"{num}{sym}"
|
return f"{num}{sym}"
|
||||||
|
|
||||||
def get_sub_lang(self, key):
|
# ~ def get_sub_lang(self, key):
|
||||||
"""
|
# ~ """
|
||||||
Obtiene los lenguajes de los subtítulos en diversas nomenclaturas.
|
# ~ Obtiene los lenguajes de los subtítulos en diversas nomenclaturas.
|
||||||
|
|
||||||
La llave está en ISO-639-2 o ISO-639-3.
|
# ~ La llave está en ISO-639-2 o ISO-639-3.
|
||||||
Cfr. https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
|
# ~ Cfr. https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
|
||||||
https://en.wikipedia.org/wiki/ISO_639-2
|
# ~ https://en.wikipedia.org/wiki/ISO_639-2
|
||||||
OJO: hay más variantes de Tarahumara y de Mixteco
|
# ~ OJO: hay más variantes de Tarahumara y de Mixteco
|
||||||
"""
|
# ~ """
|
||||||
langs = {
|
# ~ langs = {
|
||||||
"spa": {"iso639_1": "es", "label": "Español"},
|
# ~ "spa": {"iso639_1": "es", "label": "Español"},
|
||||||
"eng": {"iso639_1": "en", "label": "Inglés"},
|
# ~ "eng": {"iso639_1": "en", "label": "Inglés"},
|
||||||
"fra": {"iso639_1": "fr", "label": "Francés"},
|
# ~ "fra": {"iso639_1": "fr", "label": "Francés"},
|
||||||
"por": {"iso639_1": "pt", "label": "Portugués"},
|
# ~ "por": {"iso639_1": "pt", "label": "Portugués"},
|
||||||
"rum": {"iso639_1": "ro", "label": "Rumano"},
|
# ~ "rum": {"iso639_1": "ro", "label": "Rumano"},
|
||||||
"cat": {"iso639_1": "ca", "label": "Catalán"},
|
# ~ "cat": {"iso639_1": "ca", "label": "Catalán"},
|
||||||
"glg": {"iso639_1": "gl", "label": "Gallego"},
|
# ~ "glg": {"iso639_1": "gl", "label": "Gallego"},
|
||||||
"grn": {"iso639_1": "gn", "label": "Guaraní"},
|
# ~ "grn": {"iso639_1": "gn", "label": "Guaraní"},
|
||||||
"gug": {"iso639_1": "gn", "label": "Guaraní"},
|
# ~ "gug": {"iso639_1": "gn", "label": "Guaraní"},
|
||||||
"nah": {"iso639_1": "!!", "label": "Náhuatl"},
|
# ~ "nah": {"iso639_1": "!!", "label": "Náhuatl"},
|
||||||
"myn": {"iso639_1": "!!", "label": "Maya"},
|
# ~ "myn": {"iso639_1": "!!", "label": "Maya"},
|
||||||
"zap": {"iso639_1": "!!", "label": "Zapoteco"},
|
# ~ "zap": {"iso639_1": "!!", "label": "Zapoteco"},
|
||||||
"oto": {"iso639_1": "!!", "label": "Otomí"},
|
# ~ "oto": {"iso639_1": "!!", "label": "Otomí"},
|
||||||
"tar": {"iso639_1": "!!", "label": "Tarahumara"},
|
# ~ "tar": {"iso639_1": "!!", "label": "Tarahumara"},
|
||||||
"mix": {"iso639_1": "!!", "label": "Mixteco"},
|
# ~ "mix": {"iso639_1": "!!", "label": "Mixteco"},
|
||||||
"apa": {"iso639_1": "!!", "label": "Apache"},
|
# ~ "apa": {"iso639_1": "!!", "label": "Apache"},
|
||||||
"rus": {"iso639_1": "ru", "label": "Ruso"},
|
# ~ "rus": {"iso639_1": "ru", "label": "Ruso"},
|
||||||
"deu": {"iso639_1": "de", "label": "Alemán"},
|
# ~ "deu": {"iso639_1": "de", "label": "Alemán"},
|
||||||
"ger": {"iso639_1": "de", "label": "Alemán"},
|
# ~ "ger": {"iso639_1": "de", "label": "Alemán"},
|
||||||
"chi": {"iso639_1": "zh", "label": "Chino"},
|
# ~ "chi": {"iso639_1": "zh", "label": "Chino"},
|
||||||
"zho": {"iso639_1": "zh", "label": "Chino"},
|
# ~ "zho": {"iso639_1": "zh", "label": "Chino"},
|
||||||
}
|
# ~ }
|
||||||
if key in langs:
|
# ~ if key in langs:
|
||||||
lang = langs[key]
|
# ~ lang = langs[key]
|
||||||
lang["suffix"] = key
|
# ~ lang["suffix"] = key
|
||||||
return lang
|
# ~ return lang
|
||||||
return {"suffix": key, "iso639_1": "!!", "label": key}
|
# ~ return {"suffix": key, "iso639_1": "!!", "label": key}
|
||||||
|
|
||||||
def get_subs(self, id):
|
def get_subs(self, id):
|
||||||
"""
|
"""
|
||||||
|
@ -309,17 +309,25 @@ class MovieQuerySet(models.QuerySet):
|
||||||
|
|
||||||
TODO: en la restructuración de la DB no debería hacer requests.
|
TODO: en la restructuración de la DB no debería hacer requests.
|
||||||
"""
|
"""
|
||||||
file = self._fix_path_movie(Movie.objects.get(pk=id).file_name)
|
file_name = Movie.objects.get(pk=id).file_name
|
||||||
file = Path(re.sub(r"^https?://", "", file))
|
if not file_name:
|
||||||
page = requests.get(f"https://{file.parent}").text
|
return []
|
||||||
soup = BeautifulSoup(page, 'html.parser')
|
|
||||||
|
letter = file_name[0].upper()
|
||||||
|
if letter.isdigit():
|
||||||
|
letter = "0"
|
||||||
|
|
||||||
|
url_base = f"{settings.URL_CDN}/{letter}"
|
||||||
|
base_name = Path(file_name).stem
|
||||||
|
|
||||||
subs = []
|
subs = []
|
||||||
for node in soup.find_all("a"):
|
for k, v in settings.LANG_SUBTITLES.items():
|
||||||
if node.get("href").endswith("vtt"):
|
url_sub = f'{settings.URL_BASE}{url_base}/{base_name}.{k}.vtt'
|
||||||
url = node.get("href")
|
response = requests.get(url_sub)
|
||||||
lang = self.get_sub_lang(Path(url).suffixes[0][1:])
|
if response.status_code==200:
|
||||||
lang["path"] = "https://" + str(file.parent / url)
|
v['path'] = url_sub
|
||||||
subs.append(lang)
|
subs.append(v)
|
||||||
|
|
||||||
return subs
|
return subs
|
||||||
|
|
||||||
def get_wiki(self, movie, again=True):
|
def get_wiki(self, movie, again=True):
|
||||||
|
|
|
@ -21,6 +21,7 @@ from .conf import (
|
||||||
TOKEN_TELEGRAM,
|
TOKEN_TELEGRAM,
|
||||||
CHAT_ID,
|
CHAT_ID,
|
||||||
API_TOKEN,
|
API_TOKEN,
|
||||||
|
URL_BASE,
|
||||||
URL_CDN,
|
URL_CDN,
|
||||||
URL_DEBUG,
|
URL_DEBUG,
|
||||||
)
|
)
|
||||||
|
@ -146,3 +147,10 @@ SESSION_EXPIRE_AT_BROWSER_CLOSE = True
|
||||||
SESSION_COOKIE_AGE = 3600
|
SESSION_COOKIE_AGE = 3600
|
||||||
|
|
||||||
URL_MASTODON = "https://mstdn.mx/"
|
URL_MASTODON = "https://mstdn.mx/"
|
||||||
|
|
||||||
|
LANG_SUBTITLES = {
|
||||||
|
"spa": {"iso639_1": "es", "label": "Español", "suffix": "spa"},
|
||||||
|
"eng": {"iso639_1": "en", "label": "Inglés", "suffix": "eng"},
|
||||||
|
"fra": {"iso639_1": "fr", "label": "Francés", "suffix": "fra"},
|
||||||
|
"por": {"iso639_1": "pt", "label": "Portugués", "suffix": "por"},
|
||||||
|
}
|
Loading…
Reference in New Issue