use streaming proxy
This commit is contained in:
parent
16a9439152
commit
c230b57dca
9 changed files with 34 additions and 25 deletions
|
|
@ -11,6 +11,8 @@ from . import models
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
stream_prefix_cache = {}
|
||||
|
||||
def get_ip(request):
|
||||
if 'HTTP_X_FORWARDED_FOR' in request.META:
|
||||
ip = request.META['HTTP_X_FORWARDED_FOR'].split(',')[0]
|
||||
|
|
@ -21,17 +23,17 @@ def get_ip(request):
|
|||
return ip
|
||||
|
||||
def get_stream_prefix(request):
|
||||
return settings.DEFAULT_PANDORA_API.replace('/api/', '/')
|
||||
'''
|
||||
domain = settings.DEFAULT_PANDORA_API.split('/')[3]
|
||||
prefix = "https://v2.%s/" % domain
|
||||
#domain = settings.DEFAULT_PANDORA_API.split('/')[2]
|
||||
domain = 'njp.ma'
|
||||
prefix = "https://media.v1.%s" % domain
|
||||
cdn = {
|
||||
'Eastern Asia': "https://v1.%s/" % domain,
|
||||
'Southern Asia': "https://v1.%s/" % domain,
|
||||
'Asia': "https://v1.%s/" % domain,
|
||||
'Eastern Asia': "https://media.v2.%s" % domain,
|
||||
'Southern Asia': "https://media.v2.%s" % domain,
|
||||
'Asia': "https://media.v2.%s" % domain,
|
||||
}
|
||||
'''
|
||||
ip = get_ip(request)
|
||||
if ip in stream_prefix_cache:
|
||||
return stream_prefix_cache[ip]
|
||||
try:
|
||||
g = GeoIP2()
|
||||
country = g.country(ip)
|
||||
|
|
@ -42,15 +44,19 @@ def get_stream_prefix(request):
|
|||
location = info.get(key)
|
||||
#print(location)
|
||||
if location in cdn:
|
||||
stream_prefix_cache[ip] = cdn[location]
|
||||
return cdn[location]
|
||||
except:
|
||||
logger.error('using default prefix, no geoip data found, run ./mange.py update_geoio', exc_info=True)
|
||||
stream_prefix_cache[ip] = prefix
|
||||
return prefix
|
||||
stream_prefix_cache[ip] = prefix
|
||||
return prefix
|
||||
|
||||
def films(request):
|
||||
context = {}
|
||||
context['films'] = models.Film.objects.filter(public=True).order_by('position', 'data__title')
|
||||
context['stream_prefix'] = get_stream_prefix(request)
|
||||
context['settings'] = settings
|
||||
return render(request, 'films.html', context)
|
||||
|
||||
|
|
@ -66,10 +72,10 @@ def film_play(request, slug, id):
|
|||
context = {}
|
||||
context['settings'] = settings
|
||||
context['config'] = json.dumps({
|
||||
'stream_prefix': get_stream_prefix(request),
|
||||
'layer': 'transcripts',
|
||||
'item': id
|
||||
})
|
||||
context['stream_prefix'] = get_stream_prefix(request)
|
||||
context['pandora_url'] = settings.DEFAULT_PANDORA_API.replace('/api/', '')
|
||||
return render(request, 'film_play.html', context)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue