mirror of
https://github.com/spl0k/supysonic.git
synced 2024-11-13 21:52:18 +00:00
Introducing client prefs
Allow setting default transcoding values for specific clients
This commit is contained in:
parent
82992047dd
commit
4cd1aace76
24
api/media.py
24
api/media.py
@ -7,7 +7,7 @@ import subprocess
|
|||||||
|
|
||||||
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
|
||||||
|
|
||||||
def prepare_transcoding_cmdline(base_cmdline, input_file, input_format, output_format, output_bitrate):
|
def prepare_transcoding_cmdline(base_cmdline, input_file, input_format, output_format, output_bitrate):
|
||||||
@ -24,17 +24,26 @@ 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()
|
||||||
|
|
||||||
do_transcoding = False
|
|
||||||
src_suffix = res.suffix()
|
src_suffix = res.suffix()
|
||||||
dst_suffix = res.suffix()
|
dst_suffix = res.suffix()
|
||||||
dst_bitrate = res.bitrate
|
dst_bitrate = res.bitrate
|
||||||
dst_mimetype = res.content_type
|
dst_mimetype = res.content_type
|
||||||
|
|
||||||
if format != 'raw': # That's from API 1.9.0 but whatever
|
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 maxBitRate:
|
if maxBitRate:
|
||||||
try:
|
try:
|
||||||
maxBitRate = int(maxBitRate)
|
maxBitRate = int(maxBitRate)
|
||||||
@ -42,15 +51,13 @@ def stream_media():
|
|||||||
return request.error_formatter(0, 'Invalid bitrate value')
|
return request.error_formatter(0, 'Invalid bitrate value')
|
||||||
|
|
||||||
if dst_bitrate > maxBitRate and maxBitRate != 0:
|
if dst_bitrate > maxBitRate and maxBitRate != 0:
|
||||||
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
|
|
||||||
dst_suffix = format
|
dst_suffix = format
|
||||||
dst_mimetype = scanner.get_mime(dst_suffix)
|
dst_mimetype = scanner.get_mime(dst_suffix)
|
||||||
|
|
||||||
if do_transcoding:
|
if format != 'raw' and (dst_suffix != src_suffix or dst_bitrate != res.bitrate):
|
||||||
transcoder = config.get('transcoding', 'transcoder_{}_{}'.format(src_suffix, dst_suffix))
|
transcoder = config.get('transcoding', 'transcoder_{}_{}'.format(src_suffix, dst_suffix))
|
||||||
decoder = config.get('transcoding', 'decoder_' + src_suffix) or config.get('transcoding', 'decoder')
|
decoder = config.get('transcoding', 'decoder_' + src_suffix) or config.get('transcoding', 'decoder')
|
||||||
encoder = config.get('transcoding', 'encoder_' + dst_suffix) or config.get('transcoding', 'encoder')
|
encoder = config.get('transcoding', 'encoder_' + dst_suffix) or config.get('transcoding', 'encoder')
|
||||||
@ -78,6 +85,7 @@ def stream_media():
|
|||||||
proc.terminate()
|
proc.terminate()
|
||||||
proc.wait()
|
proc.wait()
|
||||||
|
|
||||||
|
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)
|
response = Response(transcode(), mimetype = dst_mimetype)
|
||||||
else:
|
else:
|
||||||
response = send_file(res.path, mimetype = dst_mimetype)
|
response = send_file(res.path, mimetype = dst_mimetype)
|
||||||
|
8
db.py
8
db.py
@ -97,6 +97,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'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user