File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 1
1
from beetsplug .beetstream .utils import path_to_content_type
2
2
from flask import send_file , Response
3
3
4
- import ffmpeg
4
+ import importlib
5
+ have_ffmpeg = importlib .util .find_spec ("ffmpeg" ) is not None
6
+
7
+ if have_ffmpeg :
8
+ import ffmpeg
5
9
6
10
def send_raw_file (filePath ):
7
11
return send_file (filePath , mimetype = path_to_content_type (filePath ))
8
12
9
13
def transcode_and_stream (filePath , maxBitrate ):
14
+ if not have_ffmpeg :
15
+ raise RuntimeError ("Can't transcode, ffmpeg-python is not available" )
16
+
10
17
outputStream = (
11
18
ffmpeg
12
19
.input (filePath )
@@ -17,4 +24,7 @@ def transcode_and_stream(filePath, maxBitrate):
17
24
return Response (outputStream .stdout , mimetype = 'audio/mpeg' )
18
25
19
26
def try_to_transcode (filePath , maxBitrate ):
20
- return transcode_and_stream (filePath , maxBitrate )
27
+ if have_ffmpeg :
28
+ return transcode_and_stream (filePath , maxBitrate )
29
+ else :
30
+ return send_raw_file (filePath )
You can’t perform that action at this time.
0 commit comments