import os import re from flask import Flask, render_template, send_file, abort, request, Response, redirect app = Flask(__name__) # Configuration DATA_DIR = "/data" VIDEO_FILE = "Free Python Course Hindi.mp4" # Change this to your actual filename @app.route('/') def index(): # Check if video exists video_path = os.path.join(DATA_DIR, VIDEO_FILE) video_exists = os.path.exists(video_path) return render_template('index.html', video_exists=video_exists, video_title="Free Python Course Hindi", channel="@GpsirEra") @app.route('/video') def stream_video(): video_path = os.path.join(DATA_DIR, VIDEO_FILE) if not os.path.exists(video_path): abort(404) # Get file size file_size = os.path.getsize(video_path) # Get range header for partial content range_header = request.headers.get('Range', None) if not range_header: # Serve full file return send_file(video_path, mimetype='video/mp4', as_attachment=False) # Parse range byte1, byte2 = 0, None match = re.search(r'(\d+)-(\d*)', range_header) groups = match.groups() if groups[0]: byte1 = int(groups[0]) if groups[1]: byte2 = int(groups[1]) if byte2 is None: byte2 = file_size - 1 length = byte2 - byte1 + 1 # Read partial content with open(video_path, 'rb') as f: f.seek(byte1) data = f.read(length) response = Response(data, 206, mimetype='video/mp4', content_type='video/mp4', direct_passthrough=True) response.headers.add('Content-Range', f'bytes {byte1}-{byte2}/{file_size}') response.headers.add('Accept-Ranges', 'bytes') response.headers.add('Content-Length', str(length)) return response @app.route('/poster') def get_poster(): # Use online Python logo/poster return redirect('https://www.python.org/static/img/python-logo.png') if __name__ == '__main__': app.run(host='0.0.0.0', port=7860)