This commit is contained in:
Mauricio 2023-04-09 21:43:36 -06:00
parent f7e6aa4c45
commit cf13c3e6c4
2 changed files with 45 additions and 31 deletions

View File

@ -275,27 +275,27 @@ class MovieQuerySet(models.QuerySet):
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]
@ -309,17 +309,24 @@ 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'{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) subs.append(v)
subs.append(lang)
return subs return subs
def get_wiki(self, movie, again=True): def get_wiki(self, movie, again=True):

View File

@ -146,3 +146,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"},
}