Skip to content

Commit

Permalink
Merge pull request #146 from MaxwellDPS/working
Browse files Browse the repository at this point in the history
Fix Transmission download
  • Loading branch information
MaxwellDPS committed Jan 30, 2022
2 parents cd0405e + f6c8fbc commit 4a519d2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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 .
23 changes: 15 additions & 8 deletions radio/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import functools
import ssl
import sys
import re
import json
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 4a519d2

Please sign in to comment.