1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-14 22:22:18 +00:00

send X-Content-Duration header for html5 player seeking support

This commit is contained in:
Emory P 2013-11-03 21:38:03 -05:00
parent 1e0f9576a2
commit c734f8dd09

View File

@ -5,6 +5,7 @@ import os.path
from PIL import Image from PIL import Image
import subprocess import subprocess
import shlex import shlex
import mutagen
import config, scanner import config, scanner
from web import app from web import app
@ -60,6 +61,9 @@ def stream_media():
dst_mimetype = scanner.get_mime(dst_suffix) dst_mimetype = scanner.get_mime(dst_suffix)
do_transcoding = True do_transcoding = True
duration = mutagen.File(res.path).info.length
app.logger.debug('Duration of file: ' + str(duration))
if do_transcoding: if do_transcoding:
transcoder = config.get('transcoding', 'transcoder_{}_{}'.format(src_suffix, dst_suffix)) transcoder = config.get('transcoding', 'transcoder_{}_{}'.format(src_suffix, dst_suffix))
@ -95,13 +99,14 @@ def stream_media():
dec_proc = subprocess.Popen(decoder, stdout = subprocess.PIPE, shell=False) dec_proc = subprocess.Popen(decoder, stdout = subprocess.PIPE, shell=False)
proc = subprocess.Popen(encoder, stdin = dec_proc.stdout, stdout = subprocess.PIPE, shell=False) proc = subprocess.Popen(encoder, stdin = dec_proc.stdout, stdout = subprocess.PIPE, shell=False)
response = Response(transcode(proc.stdout.readline), 200, {'Content-Type': dst_mimetype}) response = Response(transcode(proc.stdout.readline), 206, {'Content-Type': dst_mimetype, 'X-Content-Duration': str(duration)})
except: except:
return request.error_formatter(0, 'Error while running the transcoding process') return request.error_formatter(0, 'Error while running the transcoding process')
else: else:
app.logger.warn('no transcode') app.logger.warn('no transcode')
response = send_file(res.path, mimetype = dst_mimetype) response = send_file(res.path, mimetype = dst_mimetype)
response.headers['X-Content-Duration'] = str(duration)
res.play_count = res.play_count + 1 res.play_count = res.play_count + 1
res.last_play = now() res.last_play = now()