Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,98 +1,77 @@
|
|
| 1 |
import os
|
| 2 |
-
import subprocess
|
| 3 |
import json
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
|
| 7 |
-
app =
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
@app.
|
| 13 |
-
|
| 14 |
-
if
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
)
|
| 23 |
-
if result.returncode == 0:
|
| 24 |
-
print("✅ Extraction complete")
|
| 25 |
-
else:
|
| 26 |
-
print(f"❌ Extraction failed: {result.stderr}")
|
| 27 |
-
else:
|
| 28 |
-
print("❌ File not found")
|
| 29 |
-
|
| 30 |
-
@app.get("/")
|
| 31 |
-
async def root():
|
| 32 |
-
exists = os.path.exists(EXTRACTED_JSON)
|
| 33 |
-
return {
|
| 34 |
-
"message": "🔍 Indian Database Search API",
|
| 35 |
-
"developer": "Gopal Parmar",
|
| 36 |
-
"status": "ready" if exists else "processing",
|
| 37 |
-
"file_size_gb": round(os.path.getsize(EXTRACTED_JSON)/(1024**3), 2) if exists else 0
|
| 38 |
-
}
|
| 39 |
|
| 40 |
-
@app.
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
return {"error": "File not found"}
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
elif header.startswith(b'Rar!'):
|
| 51 |
-
file_type = "RAR"
|
| 52 |
-
elif header.startswith(b'7z'):
|
| 53 |
-
file_type = "7ZIP"
|
| 54 |
-
else:
|
| 55 |
-
file_type = "UNKNOWN"
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
"detected_type": file_type,
|
| 60 |
-
"magic_bytes": header.hex()
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
@app.get("/testzip")
|
| 64 |
-
async def testzip():
|
| 65 |
-
if not os.path.exists(FILE_PATH):
|
| 66 |
-
return {"error": "File not found"}
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
with open(EXTRACTED_JSON, 'r', encoding='utf-8', errors='ignore') as f:
|
| 82 |
-
for line in f:
|
| 83 |
-
if q in line:
|
| 84 |
-
try:
|
| 85 |
-
results.append(json.loads(line))
|
| 86 |
-
except:
|
| 87 |
-
results.append({"raw": line.strip()})
|
| 88 |
-
if len(results) >= limit:
|
| 89 |
-
break
|
| 90 |
-
except Exception as e:
|
| 91 |
-
return {"error": str(e)}
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import json
|
| 3 |
+
from flask import Flask, render_template, send_from_directory, send_file, abort
|
| 4 |
+
import mimetypes
|
| 5 |
|
| 6 |
+
app = Flask(__name__)
|
| 7 |
|
| 8 |
+
# Configuration
|
| 9 |
+
DATA_DIR = "/data"
|
| 10 |
+
VIDEO_FILE = "Free Python Course Hindi.mp4" # Change this to your actual filename
|
| 11 |
|
| 12 |
+
@app.route('/')
|
| 13 |
+
def index():
|
| 14 |
+
# Check if video exists
|
| 15 |
+
video_path = os.path.join(DATA_DIR, VIDEO_FILE)
|
| 16 |
+
video_exists = os.path.exists(video_path)
|
| 17 |
+
|
| 18 |
+
return render_template('index.html',
|
| 19 |
+
video_exists=video_exists,
|
| 20 |
+
video_title="Free Python Course Hindi",
|
| 21 |
+
channel="@GpsirEra")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
@app.route('/video')
|
| 24 |
+
def stream_video():
|
| 25 |
+
video_path = os.path.join(DATA_DIR, VIDEO_FILE)
|
|
|
|
| 26 |
|
| 27 |
+
if not os.path.exists(video_path):
|
| 28 |
+
abort(404)
|
| 29 |
|
| 30 |
+
# Get file size
|
| 31 |
+
file_size = os.path.getsize(video_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
# Get range header for partial content
|
| 34 |
+
range_header = request.headers.get('Range', None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
if not range_header:
|
| 37 |
+
# Serve full file
|
| 38 |
+
return send_file(video_path,
|
| 39 |
+
mimetype='video/mp4',
|
| 40 |
+
as_attachment=False)
|
| 41 |
+
|
| 42 |
+
# Parse range
|
| 43 |
+
byte1, byte2 = 0, None
|
| 44 |
+
match = re.search(r'(\d+)-(\d*)', range_header)
|
| 45 |
+
groups = match.groups()
|
| 46 |
+
|
| 47 |
+
if groups[0]:
|
| 48 |
+
byte1 = int(groups[0])
|
| 49 |
+
if groups[1]:
|
| 50 |
+
byte2 = int(groups[1])
|
| 51 |
|
| 52 |
+
if byte2 is None:
|
| 53 |
+
byte2 = file_size - 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
length = byte2 - byte1 + 1
|
| 56 |
+
|
| 57 |
+
# Read partial content
|
| 58 |
+
with open(video_path, 'rb') as f:
|
| 59 |
+
f.seek(byte1)
|
| 60 |
+
data = f.read(length)
|
| 61 |
+
|
| 62 |
+
response = Response(data, 206, mimetype='video/mp4',
|
| 63 |
+
content_type='video/mp4',
|
| 64 |
+
direct_passthrough=True)
|
| 65 |
+
response.headers.add('Content-Range', f'bytes {byte1}-{byte2}/{file_size}')
|
| 66 |
+
response.headers.add('Accept-Ranges', 'bytes')
|
| 67 |
+
response.headers.add('Content-Length', str(length))
|
| 68 |
+
|
| 69 |
+
return response
|
| 70 |
+
|
| 71 |
+
@app.route('/poster')
|
| 72 |
+
def get_poster():
|
| 73 |
+
# Use online Python logo/poster
|
| 74 |
+
return redirect('https://www.python.org/static/img/python-logo.png')
|
| 75 |
+
|
| 76 |
+
if __name__ == '__main__':
|
| 77 |
+
app.run(host='0.0.0.0', port=7860)
|