Spaces:
Paused
Paused
Commit
·
3d35386
1
Parent(s):
e4f04cc
fix player
Browse files
app.py
CHANGED
@@ -219,16 +219,41 @@ def film_player(title):
|
|
219 |
|
220 |
@app.route('/cached_films/<path:title>')
|
221 |
def serve_cached_film(title):
|
222 |
-
|
223 |
-
|
224 |
-
return jsonify({'error': 'Film not cached'}), 404
|
225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
def generate():
|
227 |
-
with open(
|
228 |
while chunk := f.read(8192):
|
229 |
yield chunk
|
230 |
|
231 |
-
return Response(generate(), mimetype=
|
|
|
232 |
|
233 |
if __name__ == '__main__':
|
234 |
app.run(debug=True, host="0.0.0.0", port=7860)
|
|
|
219 |
|
220 |
@app.route('/cached_films/<path:title>')
|
221 |
def serve_cached_film(title):
|
222 |
+
# Decode the title and construct the path
|
223 |
+
folder_path = os.path.join(CACHE_DIR, urllib.parse.unquote(title))
|
|
|
224 |
|
225 |
+
# Check if the folder exists
|
226 |
+
if not os.path.isdir(folder_path):
|
227 |
+
return jsonify({'error': 'Film folder not found'}), 404
|
228 |
+
|
229 |
+
# Get the list of files in the folder
|
230 |
+
files = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
|
231 |
+
|
232 |
+
# If no files found, return error
|
233 |
+
if not files:
|
234 |
+
return jsonify({'error': 'No film files found in the folder'}), 404
|
235 |
+
|
236 |
+
# Assuming there's only one file, get its path
|
237 |
+
file_path = os.path.join(folder_path, files[0])
|
238 |
+
|
239 |
+
# Determine the MIME type based on the file extension
|
240 |
+
mime_type = 'video/mp4'
|
241 |
+
if file_path.lower().endswith('.mkv'):
|
242 |
+
mime_type = 'video/x-matroska'
|
243 |
+
elif file_path.lower().endswith('.avi'):
|
244 |
+
mime_type = 'video/x-msvideo'
|
245 |
+
elif file_path.lower().endswith('.webm'):
|
246 |
+
mime_type = 'video/webm'
|
247 |
+
elif file_path.lower().endswith('.ts'):
|
248 |
+
mime_type = 'video/mp2t'
|
249 |
+
|
250 |
def generate():
|
251 |
+
with open(file_path, 'rb') as f:
|
252 |
while chunk := f.read(8192):
|
253 |
yield chunk
|
254 |
|
255 |
+
return Response(generate(), mimetype=mime_type)
|
256 |
+
|
257 |
|
258 |
if __name__ == '__main__':
|
259 |
app.run(debug=True, host="0.0.0.0", port=7860)
|