Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.

Commit d3783cd

Browse files
committed
Change file delivery
Signed-off-by: Sven Haardiek <[email protected]>
1 parent 6169d45 commit d3783cd

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

ess-server

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/env python
22
# -*- coding: utf-8 -*-
33
from ess import server
4-
server.app.run(debug=True, port=5001, threaded=True)
4+
server.app.run(host='0.0.0.0', debug=True, port=5001, threaded=True)

ess/server.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
sys.setdefaultencoding('utf8')
88

99
# Imports
10-
from flask import Flask, request, redirect, url_for, render_template, send_from_directory, abort, jsonify
10+
from flask import Flask, request, redirect, url_for, render_template, jsonify, stream_with_context, Response
1111
from sqlalchemy import or_
1212
import json
1313
from ess.db import get_session, Song, Artist, Album, Player, Playlist
14-
14+
import os.path
1515
# Create aplication
1616
app = Flask(__name__)
1717
app.config.from_object(__name__)
@@ -122,11 +122,18 @@ def deliver_song(song_id):
122122
song = get_session().query(Song).filter(Song.id ==
123123
song_id).first()
124124

125-
if song:
126-
[path,filename] = song.uri.rsplit('/' , 1)
127-
return send_from_directory(path, filename)
128-
129-
abort(404)
125+
if not song:
126+
return '', 404
127+
128+
def generate():
129+
with open(song.uri,'rb') as f:
130+
part = f.read(1024)
131+
while part:
132+
yield part
133+
part = f.read(128*1024)
134+
response = Response(stream_with_context(generate()), mimetype='application/octet-stream')
135+
response.headers['content-length'] = os.path.getsize(song.uri)
136+
return response
130137

131138

132139
@app.route('/player', methods = ['POST'])

0 commit comments

Comments
 (0)