File size: 2,164 Bytes
b46c500
4ce2668
 
b46c500
0bd4c41
b46c500
0bd4c41
 
 
b46c500
0bd4c41
 
 
 
 
 
 
 
 
 
b46c500
0bd4c41
 
 
79fbe77
0bd4c41
 
79fbe77
0bd4c41
 
79fbe77
0bd4c41
 
79fbe77
0bd4c41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b46c500
0bd4c41
 
b46c500
0bd4c41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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)