diff --git a/supysonic/api/media.py b/supysonic/api/media.py index 19c64ff..564610c 100644 --- a/supysonic/api/media.py +++ b/supysonic/api/media.py @@ -110,6 +110,8 @@ def stream_media(): current_app.logger.info('Transcoding track {0.id} for user {1.id}. Source: {2} at {0.bitrate}kbps. Dest: {3} at {4}kbps'.format(res, request.user, src_suffix, dst_suffix, dst_bitrate)) response = Response(transcode(), mimetype = dst_mimetype) + if estimateContentLength == 'true': + response.headers.add('Content-Length', dst_bitrate * 1000 * res.duration // 8) else: response = send_file(res.path, mimetype = dst_mimetype, conditional=True) diff --git a/tests/api/test_transcoding.py b/tests/api/test_transcoding.py index 78d8f85..0b3f959 100644 --- a/tests/api/test_transcoding.py +++ b/tests/api/test_transcoding.py @@ -44,7 +44,7 @@ class TranscodingTestCase(ApiTestBase): self._make_request('stream', { 'id': self.trackid, 'format': 'wat' }, error = 0) def test_direct_transcode(self): - rv = self._stream(maxBitRate = 96) + rv = self._stream(maxBitRate = 96, estimateContentLength = 'true') self.assertIn('tests/assets/folder/silence.mp3', rv.data) self.assertTrue(rv.data.endswith('96'))