Merge branch 'main' of git.0x2620.org:0x2620/aab21 into main
This commit is contained in:
commit
0472f9d25c
8 changed files with 81 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@ venv
|
|||
*.swo
|
||||
secret.txt
|
||||
app/local_settings.py
|
||||
geo/GeoLite2-City.mmdb
|
||||
|
|
|
@ -143,7 +143,7 @@ STATICFILES_FINDERS = [
|
|||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
|
||||
TIMELINE_PREFIX = "https://aab21.pad.ma/"
|
||||
GEOIP_PATH = BASE_DIR / 'geo'
|
||||
|
||||
DEFAULT_PANDORA_API = "https://pad.ma/api/"
|
||||
|
||||
|
|
|
@ -30,7 +30,8 @@ document.querySelector('a#play-fullscreen').addEventListener('click', event => {
|
|||
video = document.createElement('video')
|
||||
video.classList.add('player')
|
||||
video.classList.add('fullscreen')
|
||||
setVideoSrc(video, 'https://pad.ma/' + film.id + '/480p.webm')
|
||||
//setVideoSrc(video, 'https://pad.ma/' + film.id + '/480p.webm')
|
||||
video.src = `${film.prefix}/stream/${film.id}.mp4`
|
||||
video.controls = true
|
||||
document.querySelector('main').appendChild(video)
|
||||
video.style.display = 'none'
|
||||
|
|
|
@ -33,11 +33,11 @@ body {
|
|||
|
||||
</div>
|
||||
<div class="video-block">
|
||||
<img src="{{ settings.TIMELINE_PREFIX }}{{ film.padma_id }}/loop.jpg" class="video-fallback-block">
|
||||
<img src="{{ stream_prefix }}{{ film.padma_id }}/loop.jpg" class="video-fallback-block">
|
||||
<video
|
||||
id="timeline-video"
|
||||
src="{{ settings.TIMELINE_PREFIX }}{{ film.padma_id }}/loop.mp4"
|
||||
poster="{{ settings.TIMELINE_PREFIX }}{{ film.padma_id }}/loop.jpg"
|
||||
src="{{ stream_prefix }}{{ film.padma_id }}/loop.mp4"
|
||||
poster="{{ stream_prefix }}{{ film.padma_id }}/loop.jpg"
|
||||
autoplay
|
||||
loop
|
||||
muted
|
||||
|
@ -86,6 +86,7 @@ body {
|
|||
{% block end %}
|
||||
<script>
|
||||
var film = {{ film.json | safe }};
|
||||
film.prefix = "{{ stream_prefix }}";
|
||||
</script>
|
||||
<script src="{% static 'js/film.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
|
29
app/video/management/commands/update_geoip.py
Normal file
29
app/video/management/commands/update_geoip.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
import os
|
||||
import re
|
||||
|
||||
import ox
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
"""
|
||||
help = 'update geoip database'
|
||||
args = ''
|
||||
|
||||
def handle(self, **options):
|
||||
force = False
|
||||
path = settings.GEOIP_PATH / 'GeoLite2-City.mmdb'
|
||||
index = ox.net.read_url('https://db-ip.com/db/download/ip-to-city-lite').decode()
|
||||
match = re.compile('href=[\'"](http.*.mmdb.gz)').findall(index)
|
||||
if match:
|
||||
url = match[0]
|
||||
print('download', url)
|
||||
ox.net.save_url(url, "%s.gz" % path)
|
||||
if os.path.exists(path):
|
||||
os.unlink(path)
|
||||
os.system('gunzip "%s.gz"' % path)
|
||||
else:
|
||||
print('failed to download GeoLite2-City.mmdb')
|
|
@ -1,9 +1,48 @@
|
|||
import logging
|
||||
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.conf import settings
|
||||
from django.contrib.gis.geoip2 import GeoIP2, GeoIP2Exception
|
||||
import ox.geo
|
||||
|
||||
from . import models
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def get_ip(request):
|
||||
if 'HTTP_X_FORWARDED_FOR' in request.META:
|
||||
ip = request.META['HTTP_X_FORWARDED_FOR'].split(',')[0]
|
||||
else:
|
||||
ip = request.META['REMOTE_ADDR']
|
||||
if ip.startswith('::ffff:'):
|
||||
ip = ip[len('::ffff:'):]
|
||||
return ip
|
||||
|
||||
def get_stream_prefix(request):
|
||||
prefix = "https://v2.phantas.ma/"
|
||||
cdn = {
|
||||
'Eastern Asia': "https://v1.phantas.ma/",
|
||||
'Southern Asia': "https://v1.phantas.ma/",
|
||||
'Asia': "https://v1.phantas.ma/",
|
||||
}
|
||||
ip = get_ip(request)
|
||||
try:
|
||||
g = GeoIP2()
|
||||
country = g.country(ip)
|
||||
if country:
|
||||
country = ox.get_country_name(country['country_code'])
|
||||
info = ox.geo.get_country(country)
|
||||
for key in ('name', 'region', 'continent'):
|
||||
location = info.get(key)
|
||||
#print(location)
|
||||
if location in cdn:
|
||||
return cdn[location]
|
||||
except:
|
||||
logger.error('using default prefix, no geoip data found, run ./mange.py update_geoio', exc_info=True)
|
||||
return prefix
|
||||
return prefix
|
||||
|
||||
def films(request):
|
||||
context = {}
|
||||
context['films'] = models.Film.objects.filter(public=True).order_by('position', 'data__title')
|
||||
|
@ -14,6 +53,7 @@ def film(request, slug):
|
|||
context = {}
|
||||
context['film'] = get_object_or_404(models.Film, slug=slug)
|
||||
context['settings'] = settings
|
||||
context['stream_prefix'] = get_stream_prefix(request)
|
||||
return render(request, 'film.html', context)
|
||||
|
||||
def film_play(request, slug, lang):
|
||||
|
|
1
geo
Symbolic link
1
geo
Symbolic link
|
@ -0,0 +1 @@
|
|||
/srv/pandora/data/geo/
|
|
@ -2,6 +2,7 @@ Django
|
|||
libsass
|
||||
django-compressor
|
||||
django-sass-processor
|
||||
geoip2
|
||||
|
||||
ox
|
||||
lxml
|
||||
|
|
Loading…
Reference in a new issue