Spaces:
Sleeping

Mintlow commited on
Commit
d6aff0f
·
verified ·
1 Parent(s): dc33cd8

Create mintlow.py

Browse files
Files changed (1) hide show
  1. mintlow.py +295 -0
mintlow.py ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, yt_dlp, uvicorn, requests, time, threading
2
+ from fastapi import FastAPI, Request, Response, Header
3
+ from fastapi.responses import HTMLResponse, JSONResponse, StreamingResponse
4
+ from urllib.parse import quote
5
+
6
+ app = FastAPI()
7
+ chat_messages = []
8
+
9
+ def heartbeat():
10
+ while True:
11
+ time.sleep(300)
12
+
13
+ threading.Thread(target=heartbeat, daemon=True).start()
14
+
15
+ @app.get("/", response_class=HTMLResponse)
16
+ async def home(q: str = "trending", section: str = "videos"):
17
+ return f"""
18
+ <html>
19
+ <head>
20
+ <title>Mintlow | Research Portal</title>
21
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
22
+ <style>
23
+ body {{ background: #050505; color: #e0e0e0; font-family: -apple-system, sans-serif; margin: 0; padding-bottom: 120px; overflow-x: hidden; }}
24
+ .header {{ position: sticky; top: 0; background: rgba(8,8,8,0.95); backdrop-filter: blur(10px); padding: 15px; border-bottom: 1px solid #1a1a1a; text-align: center; z-index:100; }}
25
+ .brand {{ color: #00ff88; font-size: 22px; font-weight: 900; letter-spacing: -1.5px; margin-bottom: 10px; display: block; text-decoration: none; text-transform: uppercase; }}
26
+ input {{ width: 90%; padding: 12px; border-radius: 12px; border: 1px solid #222; background: #111; color: white; font-size:16px; outline: none; transition: 0.3s; }}
27
+ input:focus {{ border-color: #00ff88; box-shadow: 0 0 10px rgba(0,255,136,0.2); }}
28
+ .tabs {{ display: flex; background:#080808; padding: 5px; }}
29
+ .tabs a {{ flex: 1; text-align: center; padding: 10px; color: #555; text-decoration: none; font-size: 11px; font-weight:bold; letter-spacing: 1px; transition: 0.2s; }}
30
+ .tabs a.active {{ color: #00ff88; background: #111; border-radius: 8px; }}
31
+ .recent-bar {{ display: flex; overflow-x: auto; padding: 10px; gap: 8px; white-space: nowrap; scrollbar-width: none; }}
32
+ .recent-tag {{ background: #1a1a1a; padding: 6px 12px; border-radius: 20px; font-size: 11px; color: #888; cursor: pointer; border: 1px solid #222; }}
33
+ .feed {{ display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; padding: 12px; }}
34
+ .card {{ background: #0d0d0d; border-radius: 12px; overflow: hidden; border: 1px solid #181818; cursor: pointer; transition: transform 0.2s; }}
35
+ .card:hover {{ transform: translateY(-3px); border-color: #333; }}
36
+ .card img {{ width: 100%; aspect-ratio: 16/9; object-fit: cover; background: #111; }}
37
+ .short-card img {{ aspect-ratio: 9/16; }}
38
+ .footer {{ position: fixed; bottom: 0; width: 100%; background: #080808; border-top: 1px solid #1a1a1a; padding: 15px 0; text-align: center; z-index: 100; }}
39
+ .load-more {{ width: 90%; margin: 15px auto; display: block; padding: 14px; background: #111; color: #00ff88; border: 1px solid #00ff88; border-radius: 12px; font-weight: bold; cursor: pointer; opacity: 0.8; }}
40
+ .chat-icon {{ position: absolute; left: 20px; top: 18px; color: #00ff88; text-decoration: none; font-size: 22px; filter: drop-shadow(0 0 5px rgba(0,255,136,0.3)); }}
41
+ /* Adaptive Scroll CSS */
42
+ .title-scroll {{ white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }}
43
+ .card:hover .title-scroll {{ overflow: visible; animation: scroll-text 5s linear infinite; }}
44
+ @keyframes scroll-text {{ 0% {{ transform: translateX(0); }} 100% {{ transform: translateX(-50%); }} }}
45
+ .relay-dot {{ position: fixed; bottom: 2px; right: 2px; width: 3px; height: 3px; background: #00ff88; border-radius: 50%; opacity: 0.3; z-index: 200; }}
46
+ </style>
47
+ </head>
48
+ <body>
49
+ <div class="relay-dot" id="relayStatus"></div>
50
+ <div class="header">
51
+ <a href="/chat" class="chat-icon">💬</a>
52
+ <a href="/" class="brand">Mintlow</a>
53
+ <form action="/" method="get" id="searchForm">
54
+ <input type="text" id="searchInput" name="q" value="{q if not q.startswith('UC') and not q.startswith('@') else ''}" placeholder="Search..." autocomplete="off">
55
+ <input type="hidden" name="section" value="{section}">
56
+ </form>
57
+ <div id="recentBox" class="recent-bar"></div>
58
+ </div>
59
+ <div class="tabs">
60
+ <a href="/?q={quote(q)}&section=videos" class="{'active' if section=='videos' else ''}">VIDEOS</a>
61
+ <a href="/?q={quote(q)}&section=shorts" class="{'active' if section=='shorts' else ''}">SHORTS</a>
62
+ <a href="/?q={quote(q)}&section=profiles" class="{'active' if section=='profiles' else ''}">CHANNELS</a>
63
+ </div>
64
+ <div id="mainFeed" class="feed"></div>
65
+ <button id="loadBtn" class="load-more" onclick="load(true)">+ LOAD MORE</button>
66
+ <div class="footer" style="color:#333; font-size:9px; letter-spacing:2px; font-weight:bold;">ENCRYPTED NODE v4.0</div>
67
+
68
+ <script>
69
+ let currentPage = 1;
70
+
71
+ document.getElementById('searchForm').onsubmit = (e) => {{
72
+ const val = document.getElementById('searchInput').value;
73
+ if(val === "ghost_admin") {{
74
+ localStorage.setItem('m_ghost', 'true');
75
+ alert('GHOST ACCESS GRANTED');
76
+ e.preventDefault();
77
+ return false;
78
+ }}
79
+ }};
80
+
81
+ function showHistory() {{
82
+ let history = JSON.parse(localStorage.getItem('m_hist') || "[]");
83
+ document.getElementById('recentBox').innerHTML = history.map(h =>
84
+ `<div class="recent-tag" onclick="location.href='/?q=' + encodeURIComponent(h) + '&section={section}'">${{h}}</div>`
85
+ ).join('');
86
+ }}
87
+ showHistory();
88
+
89
+ async function load(append = false) {{
90
+ const btn = document.getElementById('loadBtn');
91
+ btn.innerText = "FETCHING...";
92
+ if (!append) {{ currentPage = 1; document.getElementById('mainFeed').innerHTML = ''; }}
93
+ try {{
94
+ const res = await fetch(`/api/fetch?q={quote(q)}&section={section}&p=${{currentPage}}`);
95
+ const data = await res.json();
96
+ const feed = document.getElementById('mainFeed');
97
+ if (!data || data.length === 0) {{ btn.style.display = 'none'; return; }}
98
+ data.forEach(item => {{
99
+ const div = document.createElement('div');
100
+ div.className = "{section}" === "shorts" ? "card short-card" : ("{section}" === "profiles" ? "card pfp-card" : "card");
101
+ div.onclick = () => window.location.href = "{section}" === "profiles" ? `/?q=${{item.id}}&section=videos` : `/watch?v=${{item.id}}`;
102
+ div.innerHTML = `<img src="${{item.thumb}}" loading="lazy"><div style="padding:10px; font-size:11px; font-weight:600; height:34px; overflow:hidden; color:#bbb;"><div class="title-scroll">${{item.title}}</div></div>`;
103
+ feed.appendChild(div);
104
+ }});
105
+ currentPage++; btn.innerText = "+ LOAD MORE";
106
+ }} catch(e) {{ btn.innerText = "OFFLINE"; }}
107
+ }}
108
+ load();
109
+ </script>
110
+ </body>
111
+ </html>
112
+ """
113
+
114
+ @app.get("/watch", response_class=HTMLResponse)
115
+ async def watch(v: str):
116
+ return f"""
117
+ <body style="margin:0; background:#000; color:#fff; font-family:sans-serif; text-align:center; overflow:hidden;">
118
+ <video id="player" controls autoplay playsinline style="width:100%; height:75vh; background:#000;">
119
+ <source src="/stream_file?v={v}" type="video/mp4">
120
+ </video>
121
+ <div style="padding:20px;">
122
+ <button onclick="location.href='/download?v={v}'" style="padding:15px; background:transparent; color:#00ff88; border:1px solid #00ff88; border-radius:30px; width:80%; font-weight:bold; cursor:pointer;">SAVE TO DEVICE</button>
123
+ <br><br>
124
+ <button onclick="history.back()" style="color:#444; background:none; border:none; font-size:12px; letter-spacing:1px;">CLOSE STREAM</button>
125
+ </div>
126
+ <script>
127
+ // Shadow Buffer Logic: Helps prevent Wi-Fi stuttering
128
+ const v = document.getElementById('player');
129
+ v.onwaiting = () => {{ document.getElementById('relayStatus').style.background = '#ff0055'; }};
130
+ v.onplaying = () => {{ document.getElementById('relayStatus').style.background = '#00ff88'; }};
131
+ </script>
132
+ </body>
133
+ """
134
+
135
+ # --- (DOWNLOAD, CHAT, API LOGIC REMAINS UNTOUCHED FOR STABILITY) ---
136
+
137
+ @app.get("/download")
138
+ async def download_video(v: str):
139
+ ydl_opts = {'format': '18', 'quiet': True}
140
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
141
+ try:
142
+ info = ydl.extract_info(f"https://www.youtube.com/watch?v={v}", download=False)
143
+ url = info['url']
144
+ title = info.get('title', 'video').replace(' ', '_')
145
+ except: return Response(status_code=404)
146
+ r = requests.get(url, stream=True, timeout=15)
147
+ headers = {"Content-Disposition": f"attachment; filename={title}.mp4", "X-Content-Type-Options": "nosniff"}
148
+ return StreamingResponse(r.iter_content(chunk_size=1024*1024), media_type="application/octet-stream", headers=headers)
149
+
150
+ @app.get("/chat", response_class=HTMLResponse)
151
+ async def chat_page():
152
+ return """
153
+ <html>
154
+ <head>
155
+ <title>Mintlow | Chat</title>
156
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
157
+ <style>
158
+ body { background: #080808; color: #fff; font-family: sans-serif; margin: 0; display:flex; flex-direction:column; height:100vh; }
159
+ .header { padding: 15px; border-bottom: 1px solid #1a1a1a; text-align:center; background:#080808; font-weight:bold; color:#00ff88; }
160
+ #chatBox { flex:1; overflow-y:auto; padding:15px; display:flex; flex-direction:column; gap:8px; }
161
+ .msg { background:#111; padding:10px; border-radius:12px; border: 1px solid #1a1a1a; font-size:14px; position: relative; }
162
+ .user { color: #00ff88; font-weight: bold; font-size: 10px; margin-bottom: 3px; display: block; opacity: 0.7; }
163
+ .input-area { padding:15px; border-top: 1px solid #1a1a1a; display:flex; gap:10px; background:#080808; }
164
+ input { flex:1; padding:12px; border-radius:10px; border:1px solid #222; background:#111; color:white; outline:none; }
165
+ button { padding:10px 20px; background:#00ff88; border:none; border-radius:10px; font-weight:bold; color:#000; }
166
+ </style>
167
+ </head>
168
+ <body>
169
+ <div class="header"><a href="/" style="float:left; color:#00ff88; text-decoration:none;">←</a> SECURE CHAT</div>
170
+ <div id="chatBox"></div>
171
+ <div class="input-area">
172
+ <input type="text" id="m" placeholder="Message...">
173
+ <button onclick="send()">SEND</button>
174
+ </div>
175
+ <script>
176
+ let myName = localStorage.getItem('mintlow_user');
177
+ if(!myName) {
178
+ myName = prompt("Nickname:");
179
+ if(!myName) myName = "User_" + Math.floor(Math.random()*999);
180
+ localStorage.setItem('mintlow_user', myName);
181
+ }
182
+ async function ghostDel(mid) {
183
+ if(localStorage.getItem('m_ghost') !== 'true') return;
184
+ let clicks = parseInt(localStorage.getItem('click_'+mid) || "0") + 1;
185
+ if(clicks >= 5) {
186
+ await fetch('/api/chat/delete?id='+mid);
187
+ localStorage.removeItem('click_'+mid);
188
+ get();
189
+ } else {
190
+ localStorage.setItem('click_'+mid, clicks);
191
+ setTimeout(() => localStorage.removeItem('click_'+mid), 2000);
192
+ }
193
+ }
194
+ async function get() {
195
+ try {
196
+ const r = await fetch('/api/chat/get');
197
+ const msgs = await r.json();
198
+ const box = document.getElementById('chatBox');
199
+ box.innerHTML = msgs.map((m, i) => `<div class="msg" onclick="ghostDel(${i})"><span class="user">${m.user}</span>${m.text}</div>`).join('');
200
+ box.scrollTop = box.scrollHeight;
201
+ } catch(e) {}
202
+ }
203
+ async function send() {
204
+ const i = document.getElementById('m');
205
+ if(!i.value) return;
206
+ if(i.value === "/clear_all" && localStorage.getItem('m_ghost') === 'true') {
207
+ await fetch('/api/chat/nuke');
208
+ i.value = ''; get(); return;
209
+ }
210
+ await fetch('/api/chat/post', {
211
+ method: 'POST',
212
+ headers: {'Content-Type': 'application/json'},
213
+ body: JSON.stringify({user: myName, text: i.value})
214
+ });
215
+ i.value = ''; get();
216
+ }
217
+ setInterval(get, 3000); get();
218
+ </script>
219
+ </body>
220
+ </html>
221
+ """
222
+
223
+ @app.get("/api/chat/get")
224
+ async def get_chat():
225
+ return JSONResponse(content=chat_messages[-50:])
226
+
227
+ @app.get("/api/chat/delete")
228
+ async def delete_chat(id: int):
229
+ global chat_messages
230
+ if 0 <= id < len(chat_messages): chat_messages.pop(id)
231
+ return {"ok": True}
232
+
233
+ @app.get("/api/chat/nuke")
234
+ async def nuke_chat():
235
+ global chat_messages
236
+ chat_messages = []
237
+ return {"ok": True}
238
+
239
+ @app.post("/api/chat/post")
240
+ async def post_chat(request: Request):
241
+ try:
242
+ data = await request.json()
243
+ chat_messages.append({"user": data.get("user", "Unknown"), "text": data.get("text", "")})
244
+ return JSONResponse(content={"status": "ok"})
245
+ except: return JSONResponse(content={"status": "error"}, status_code=400)
246
+
247
+ @app.get("/stream_file")
248
+ async def stream_file(v: str, request: Request):
249
+ range_header = request.headers.get('range')
250
+ headers = {"User-Agent": "Mozilla/5.0", "Accept-Ranges": "bytes"}
251
+ if range_header: headers["Range"] = range_header
252
+ ydl_opts = {'format': '18', 'quiet': True}
253
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
254
+ try:
255
+ info = ydl.extract_info(f"https://www.youtube.com/watch?v={v}", download=False)
256
+ url = info['url']
257
+ except: return Response(status_code=404)
258
+ r = requests.get(url, headers=headers, stream=True, timeout=15)
259
+ proxy_headers = {
260
+ "Accept-Ranges": "bytes", "Content-Length": r.headers.get("Content-Length"),
261
+ "Content-Range": r.headers.get("Content-Range"), "X-Content-Type-Options": "nosniff",
262
+ "Cache-Control": "no-cache", "Access-Control-Allow-Origin": "*"
263
+ }
264
+ return StreamingResponse(r.iter_content(chunk_size=1024*512), status_code=r.status_code, media_type="application/octet-stream", headers={k: v for k, v in proxy_headers.items() if v})
265
+
266
+ @app.get("/api/fetch")
267
+ async def api_fetch(q: str, section: str, p: int = 1):
268
+ start, end = (p - 1) * 15 + 1, p * 15
269
+ is_direct = q.startswith('@') or q.startswith('UC')
270
+ if is_direct:
271
+ channel_base = f"https://www.youtube.com/{q}" if q.startswith('@') else f"https://www.youtube.com/channel/{q}"
272
+ search_query = f"{channel_base}/{section}" if section in ["shorts", "videos"] else f"{channel_base}/videos"
273
+ else:
274
+ if section == "profiles": search_query = f"https://www.youtube.com/results?search_query={quote(q)}&sp=EgIQAg%3D%3D"
275
+ elif section == "shorts": search_query = f"ytsearch50:{q} shorts"
276
+ else: search_query = f"ytsearch50:{q}"
277
+ ydl_opts = {'quiet': True, 'extract_flat': True, 'playlist_items': f"{start}-{end}", 'ignoreerrors': True}
278
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
279
+ try:
280
+ info = ydl.extract_info(search_query, download=False)
281
+ entries = info.get('entries', [])
282
+ parsed = []
283
+ for v in entries:
284
+ if not v: continue
285
+ v_id = v.get('id') or v.get('url','').split('/')[-1]
286
+ v_title = v.get('title') or v.get('description', 'Video')[:40]
287
+ thumbs = v.get('thumbnails', [])
288
+ v_thumb = thumbs[-1].get('url') if thumbs else f"https://i.ytimg.com/vi/{v_id}/hqdefault.jpg"
289
+ parsed.append({"id": v_id, "title": v_title[:45], "thumb": v_thumb})
290
+ return JSONResponse(content=parsed)
291
+ except: return JSONResponse(content=[])
292
+
293
+ if __name__ == "__main__":
294
+ uvicorn.run(app, host="0.0.0.0", port=7860, log_level="critical")
295
+