Skip to content

Commit 296fa02

Browse files
if ffmpeg-python is not available just send the raw file
1 parent 8fb715d commit 296fa02

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

beetsplug/beetstream/stream.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
from beetsplug.beetstream.utils import path_to_content_type
22
from flask import send_file, Response
33

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
59

610
def send_raw_file(filePath):
711
return send_file(filePath, mimetype=path_to_content_type(filePath))
812

913
def transcode_and_stream(filePath, maxBitrate):
14+
if not have_ffmpeg:
15+
raise RuntimeError("Can't transcode, ffmpeg-python is not available")
16+
1017
outputStream = (
1118
ffmpeg
1219
.input(filePath)
@@ -17,4 +24,7 @@ def transcode_and_stream(filePath, maxBitrate):
1724
return Response(outputStream.stdout, mimetype='audio/mpeg')
1825

1926
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)

0 commit comments

Comments
 (0)