mirror of
https://github.com/spl0k/supysonic.git
synced 2024-11-15 06:32:16 +00:00
Merge branch 'master' of github.com:spl0k/supysonic
Conflicts: api/media.py
This commit is contained in:
commit
d49af86c17
19
api/media.py
19
api/media.py
@ -11,7 +11,7 @@ import mimetypes
|
|||||||
|
|
||||||
import config, scanner
|
import config, scanner
|
||||||
from web import app
|
from web import app
|
||||||
from db import Track, Folder, User, now, session
|
from db import Track, Folder, User, ClientPrefs, now, session
|
||||||
from api import get_entity
|
from api import get_entity
|
||||||
|
|
||||||
from flask import g
|
from flask import g
|
||||||
@ -56,7 +56,7 @@ def stream_media():
|
|||||||
if not status:
|
if not status:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
maxBitRate, format, timeOffset, size, estimateContentLength = map(request.args.get, [ 'maxBitRate', 'format', 'timeOffset', 'size', 'estimateContentLength' ])
|
maxBitRate, format, timeOffset, size, estimateContentLength, client = map(request.args.get, [ 'maxBitRate', 'format', 'timeOffset', 'size', 'estimateContentLength', 'c' ])
|
||||||
if format:
|
if format:
|
||||||
format = format.lower()
|
format = format.lower()
|
||||||
|
|
||||||
@ -66,7 +66,6 @@ def stream_media():
|
|||||||
dst_bitrate = res.bitrate
|
dst_bitrate = res.bitrate
|
||||||
dst_mimetype = mimetypes.guess_type('a.' + src_suffix)
|
dst_mimetype = mimetypes.guess_type('a.' + src_suffix)
|
||||||
|
|
||||||
if format != 'raw': # That's from API 1.9.0 but whatever
|
|
||||||
if maxBitRate:
|
if maxBitRate:
|
||||||
try:
|
try:
|
||||||
maxBitRate = int(maxBitRate)
|
maxBitRate = int(maxBitRate)
|
||||||
@ -77,11 +76,23 @@ def stream_media():
|
|||||||
do_transcoding = True
|
do_transcoding = True
|
||||||
dst_bitrate = maxBitRate
|
dst_bitrate = maxBitRate
|
||||||
|
|
||||||
if format and format != src_suffix:
|
if format and format != 'raw' and format != src_suffix:
|
||||||
do_transcoding = True
|
do_transcoding = True
|
||||||
dst_suffix = format
|
dst_suffix = format
|
||||||
dst_mimetype = mimetypes.guess_type(dst_suffix)
|
dst_mimetype = mimetypes.guess_type(dst_suffix)
|
||||||
|
|
||||||
|
if client:
|
||||||
|
prefs = ClientPrefs.query.get((request.user.id, client))
|
||||||
|
if not prefs:
|
||||||
|
prefs = ClientPrefs(user_id = request.user.id, client_name = client)
|
||||||
|
session.add(prefs)
|
||||||
|
|
||||||
|
if prefs.format:
|
||||||
|
dst_suffix = prefs.format
|
||||||
|
if prefs.bitrate and prefs.bitrate < dst_bitrate:
|
||||||
|
dst_bitrate = prefs.bitrate
|
||||||
|
|
||||||
|
|
||||||
if not format and src_suffix == 'flac':
|
if not format and src_suffix == 'flac':
|
||||||
dst_suffix = 'ogg'
|
dst_suffix = 'ogg'
|
||||||
dst_bitrate = 320
|
dst_bitrate = 320
|
||||||
|
8
db.py
8
db.py
@ -103,6 +103,14 @@ class User(Base):
|
|||||||
'shareRole': False
|
'shareRole': False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ClientPrefs(Base):
|
||||||
|
__tablename__ = 'client_prefs'
|
||||||
|
|
||||||
|
user_id = Column(UUID, ForeignKey('user.id'), primary_key = True)
|
||||||
|
client_name = Column(String(32), nullable = False, primary_key = True)
|
||||||
|
format = Column(String(8), nullable = True)
|
||||||
|
bitrate = Column(Integer, nullable = True)
|
||||||
|
|
||||||
class Folder(Base):
|
class Folder(Base):
|
||||||
__tablename__ = 'folder'
|
__tablename__ = 'folder'
|
||||||
|
|
||||||
|
@ -18,5 +18,34 @@
|
|||||||
</li>
|
</li>
|
||||||
<li><a href="{{ url_for('change_password') }}">Change password</a></li>
|
<li><a href="{{ url_for('change_password') }}">Change password</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
{% if clients.count() %}
|
||||||
|
<h2>Clients</h2>
|
||||||
|
<p>Here's a list of clients you used to stream music. If you want to use transcoding or downsampling with one of them (for instance using a low bitrate on
|
||||||
|
mobile connections to reduce used bandwidth), but the client doesn't provide options to do so, you can set default values here. They'll only be used if no
|
||||||
|
transcoding/downsampling is requested by the client.</p>
|
||||||
|
<form method="post">
|
||||||
|
<table>
|
||||||
|
<tr><th>Client</th><th>Format</th><th>Max bitrate</th><th>Forget</th></tr>
|
||||||
|
{% for client in clients %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ client.client_name }}</td>
|
||||||
|
<td><input type="text" name="{{ client.client_name }}_format" value="{{ client.format if client.format else '' }}" /></td>
|
||||||
|
<td><select name="{{ client.client_name }}_bitrate">
|
||||||
|
<option />
|
||||||
|
<option {{ 'selected="selected"' if client.bitrate == 64 else '' }}>64</option>
|
||||||
|
<option {{ 'selected="selected"' if client.bitrate == 96 else '' }}>96</option>
|
||||||
|
<option {{ 'selected="selected"' if client.bitrate == 128 else '' }}>128</option>
|
||||||
|
<option {{ 'selected="selected"' if client.bitrate == 192 else '' }}>192</option>
|
||||||
|
<option {{ 'selected="selected"' if client.bitrate == 256 else '' }}>256</option>
|
||||||
|
<option {{ 'selected="selected"' if client.bitrate == 320 else '' }}>320</option>
|
||||||
|
</select></td>
|
||||||
|
<td><input type="checkbox" name="{{ client.client_name }}_delete" /></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
<input type="submit" value="Save" />
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
25
user.py
25
user.py
@ -4,7 +4,7 @@ from flask import request, session, flash, render_template, redirect, url_for, m
|
|||||||
|
|
||||||
from web import app
|
from web import app
|
||||||
from managers.user import UserManager
|
from managers.user import UserManager
|
||||||
from db import User, session as db_sess
|
from db import User, ClientPrefs, session as db_sess
|
||||||
import uuid, csv
|
import uuid, csv
|
||||||
import config
|
import config
|
||||||
from lastfm import LastFm
|
from lastfm import LastFm
|
||||||
@ -23,7 +23,28 @@ def user_index():
|
|||||||
|
|
||||||
@app.route('/user/me')
|
@app.route('/user/me')
|
||||||
def user_profile():
|
def user_profile():
|
||||||
return render_template('profile.html', user = UserManager.get(session.get('userid'))[1], api_key = config.get('lastfm', 'api_key'))
|
prefs = ClientPrefs.query.filter(ClientPrefs.user_id == uuid.UUID(session.get('userid')))
|
||||||
|
return render_template('profile.html', user = UserManager.get(session.get('userid'))[1], api_key = config.get('lastfm', 'api_key'), clients = prefs)
|
||||||
|
|
||||||
|
@app.route('/user/me', methods = [ 'POST' ])
|
||||||
|
def update_clients():
|
||||||
|
clients_opts = {}
|
||||||
|
for client in set(map(lambda k: k.rsplit('_', 1)[0],request.form.keys())):
|
||||||
|
clients_opts[client] = { k.rsplit('_', 1)[1]: v for k, v in filter(lambda (k, v): k.startswith(client), request.form.iteritems()) }
|
||||||
|
app.logger.debug(clients_opts)
|
||||||
|
|
||||||
|
for client, opts in clients_opts.iteritems():
|
||||||
|
prefs = ClientPrefs.query.get((uuid.UUID(session.get('userid')), client))
|
||||||
|
if 'delete' in opts and opts['delete'] in [ 'on', 'true', 'checked', 'selected', '1' ]:
|
||||||
|
db_sess.delete(prefs)
|
||||||
|
continue
|
||||||
|
|
||||||
|
prefs.format = opts['format'] if 'format' in opts and opts['format'] else None
|
||||||
|
prefs.bitrate = int(opts['bitrate']) if 'bitrate' in opts and opts['bitrate'] else None
|
||||||
|
|
||||||
|
db_sess.commit()
|
||||||
|
flash('Clients preferences updated.')
|
||||||
|
return user_profile()
|
||||||
|
|
||||||
@app.route('/user/changemail', methods = [ 'GET', 'POST' ])
|
@app.route('/user/changemail', methods = [ 'GET', 'POST' ])
|
||||||
def change_mail():
|
def change_mail():
|
||||||
|
Loading…
Reference in New Issue
Block a user