diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..a6fceb4 --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 -t maxwelldps/trunkplayer:latest --push . \ No newline at end of file diff --git a/radio/views.py b/radio/views.py index 9ffb95f..3aa823b 100644 --- a/radio/views.py +++ b/radio/views.py @@ -1,4 +1,5 @@ #import functools +import ssl import sys import re import json @@ -124,37 +125,43 @@ def TransDetailView(request, slug): return render(request, template, {'object': query_data[0], 'status': status}) def transDownloadView(request, slug): - import urllib.request + import requests try: query_data = Transmission.objects.filter(slug=slug) if not query_data: raise Http404 except Transmission.DoesNotExist: raise Http404 + query_data2 = limit_transmission_history(request, query_data) - if not query_data2: - raise Http404 # Just raise 404 if its too old + if not query_data2: raise Http404 # Just raise 404 if its too old + restricted, new_query = restrict_talkgroups(request, query_data) - if not new_query: - raise Http404 + if not new_query: raise Http404 + trans = new_query[0] if trans.audio_file_type == 'm4a': audio_type = 'audio/m4a' else: audio_type = 'audio/mp3' + response = HttpResponse(content_type=audio_type) start_time = timezone.localtime(trans.start_datetime).strftime('%Y%m%d_%H%M%S') + filename = '{}_{}.{}'.format(start_time, trans.talkgroup_info.slug, trans.audio_file_type) + response['Content-Disposition'] = 'attachment; filename="{}"'.format(filename) + url = 'https:{}{}.{}'.format(trans.audio_url, trans.audio_file, trans.audio_file_type) if trans.audio_url[:2] != '//': url = 'http:' if request.is_secure(): url = 'https:' url += '//{}/{}{}.{}'.format(request.get_host(), trans.audio_url, trans.audio_file, trans.audio_file_type) - req = urllib.request.Request(url) - with urllib.request.urlopen(req) as web_response: - response.write(web_response.read()) + + data = requests.get(url, verify=False) + response.write(data.content) + return response