Fix #11 - Habilitación de subtítulos
This commit is contained in:
parent
1f7f66d5e6
commit
f7e6aa4c45
|
@ -1,3 +1,4 @@
|
||||||
|
import requests
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
|
@ -264,6 +265,63 @@ class MovieQuerySet(models.QuerySet):
|
||||||
else:
|
else:
|
||||||
return f"{num}{sym}"
|
return f"{num}{sym}"
|
||||||
|
|
||||||
|
def get_sub_lang(self, key):
|
||||||
|
"""
|
||||||
|
Obtiene los lenguajes de los subtítulos en diversas nomenclaturas.
|
||||||
|
|
||||||
|
La llave está en ISO-639-2 o ISO-639-3.
|
||||||
|
Cfr. https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
|
||||||
|
https://en.wikipedia.org/wiki/ISO_639-2
|
||||||
|
OJO: hay más variantes de Tarahumara y de Mixteco
|
||||||
|
"""
|
||||||
|
langs = {
|
||||||
|
"spa": {"iso639_1": "es", "label": "Español"},
|
||||||
|
"eng": {"iso639_1": "en", "label": "Inglés"},
|
||||||
|
"fra": {"iso639_1": "fr", "label": "Francés"},
|
||||||
|
"por": {"iso639_1": "pt", "label": "Portugués"},
|
||||||
|
"rum": {"iso639_1": "ro", "label": "Rumano"},
|
||||||
|
"cat": {"iso639_1": "ca", "label": "Catalán"},
|
||||||
|
"glg": {"iso639_1": "gl", "label": "Gallego"},
|
||||||
|
"grn": {"iso639_1": "gn", "label": "Guaraní"},
|
||||||
|
"gug": {"iso639_1": "gn", "label": "Guaraní"},
|
||||||
|
"nah": {"iso639_1": "!!", "label": "Náhuatl"},
|
||||||
|
"myn": {"iso639_1": "!!", "label": "Maya"},
|
||||||
|
"zap": {"iso639_1": "!!", "label": "Zapoteco"},
|
||||||
|
"oto": {"iso639_1": "!!", "label": "Otomí"},
|
||||||
|
"tar": {"iso639_1": "!!", "label": "Tarahumara"},
|
||||||
|
"mix": {"iso639_1": "!!", "label": "Mixteco"},
|
||||||
|
"apa": {"iso639_1": "!!", "label": "Apache"},
|
||||||
|
"rus": {"iso639_1": "ru", "label": "Ruso"},
|
||||||
|
"deu": {"iso639_1": "de", "label": "Alemán"},
|
||||||
|
"ger": {"iso639_1": "de", "label": "Alemán"},
|
||||||
|
"chi": {"iso639_1": "zh", "label": "Chino"},
|
||||||
|
"zho": {"iso639_1": "zh", "label": "Chino"},
|
||||||
|
}
|
||||||
|
if key in langs:
|
||||||
|
lang = langs[key]
|
||||||
|
lang["suffix"] = key
|
||||||
|
return lang
|
||||||
|
return {"suffix": key, "iso639_1": "!!", "label": key}
|
||||||
|
|
||||||
|
def get_subs(self, id):
|
||||||
|
"""
|
||||||
|
Obtiene subtítulos de película por id.
|
||||||
|
|
||||||
|
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 = Path(re.sub(r"^https?://", "", file))
|
||||||
|
page = requests.get(f"https://{file.parent}").text
|
||||||
|
soup = BeautifulSoup(page, 'html.parser')
|
||||||
|
subs = []
|
||||||
|
for node in soup.find_all("a"):
|
||||||
|
if node.get("href").endswith("vtt"):
|
||||||
|
url = node.get("href")
|
||||||
|
lang = self.get_sub_lang(Path(url).suffixes[0][1:])
|
||||||
|
lang["path"] = "https://" + str(file.parent / url)
|
||||||
|
subs.append(lang)
|
||||||
|
return subs
|
||||||
|
|
||||||
def get_wiki(self, movie, again=True):
|
def get_wiki(self, movie, again=True):
|
||||||
"""
|
"""
|
||||||
Obtiene artículo de Wikipedia.
|
Obtiene artículo de Wikipedia.
|
||||||
|
|
|
@ -51,6 +51,7 @@ function remove_notice () {
|
||||||
const player = new Plyr('#player', {
|
const player = new Plyr('#player', {
|
||||||
keyboard: { focused: true, global: true },
|
keyboard: { focused: true, global: true },
|
||||||
controls: ['play-large', 'play', 'progress', 'current-time', 'mute',
|
controls: ['play-large', 'play', 'progress', 'current-time', 'mute',
|
||||||
'volume', 'pip', 'airplay', 'download', 'fullscreen'],
|
'volume', 'pip', 'airplay', 'captions', 'settings', 'download',
|
||||||
|
'fullscreen'],
|
||||||
listeners: { seek: add_notice() },
|
listeners: { seek: add_notice() },
|
||||||
});
|
});
|
||||||
|
|
|
@ -37,7 +37,10 @@ def bugs(request):
|
||||||
|
|
||||||
|
|
||||||
def movie(request, id):
|
def movie(request, id):
|
||||||
context = {"movie": Movie.objects.get_movie_by_id(id)}
|
context = {
|
||||||
|
"movie": Movie.objects.get_movie_by_id(id),
|
||||||
|
"subs": Movie.objects.get_subs(id),
|
||||||
|
}
|
||||||
return render(request, "movie.html", context)
|
return render(request, "movie.html", context)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ function remove_notice () {
|
||||||
const player = new Plyr('#player', {
|
const player = new Plyr('#player', {
|
||||||
keyboard: { focused: true, global: true },
|
keyboard: { focused: true, global: true },
|
||||||
controls: ['play-large', 'play', 'progress', 'current-time', 'mute',
|
controls: ['play-large', 'play', 'progress', 'current-time', 'mute',
|
||||||
'volume', 'pip', 'airplay', 'download', 'fullscreen'],
|
'volume', 'pip', 'airplay', 'captions', 'settings', 'download',
|
||||||
|
'fullscreen'],
|
||||||
listeners: { seek: add_notice() },
|
listeners: { seek: add_notice() },
|
||||||
});
|
});
|
||||||
|
|
|
@ -64,6 +64,9 @@
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<video id="player" playsinline controls data-poster="{{ movie.cartel }}">
|
<video id="player" playsinline controls data-poster="{{ movie.cartel }}">
|
||||||
<source src="{{ movie.file_name }}" type="video/mp4">
|
<source src="{{ movie.file_name }}" type="video/mp4">
|
||||||
|
{% for sub in subs %}
|
||||||
|
<track kind="captions" label="{{ sub.label }}" src="{{ sub.path }}" srclang="{{ sub.iso639_1 }}" default />
|
||||||
|
{% endfor %}
|
||||||
</video>
|
</video>
|
||||||
{% load static %}
|
{% load static %}
|
||||||
<!-- CSS y JS necesario paara el reproductor -->
|
<!-- CSS y JS necesario paara el reproductor -->
|
||||||
|
|
Loading…
Reference in New Issue