Download src/App.tsx from subrato1/streamapi: direct link, hf CLI and curl.
- Browser
- Download file 50.5 kB
-
https://huggingface.co/spaces/subrato1/streamapi/resolve/main/src/App.tsx
- Command line
-
hf download hf://spaces/subrato1/streamapi/src/App.tsx
-
curl -L -o App.tsx https://huggingface.co/spaces/subrato1/streamapi/resolve/main/src/App.tsx
50.5 kB
| import React, { useState, useEffect, useRef } from "react"; | |
| import { | |
| Tv, | |
| RefreshCw, | |
| Copy, | |
| Check, | |
| Settings, | |
| Globe, | |
| Terminal, | |
| ExternalLink, | |
| Edit3, | |
| AlertCircle, | |
| Save, | |
| Info, | |
| Layers, | |
| Cpu, | |
| CheckCircle, | |
| Clock, | |
| ShieldCheck, | |
| Disc | |
| } from "lucide-react"; | |
| import { motion, AnimatePresence } from "motion/react"; | |
| interface Channel { | |
| id: string; | |
| name: string; | |
| url: string; | |
| logo: string; | |
| overrideUrl: string; | |
| m3u8Url: string | null; | |
| referer: string | null; | |
| status: "Active" | "No Stream" | "Override" | "Error" | "Pending"; | |
| lastTested: string | null; | |
| logs: string[]; | |
| } | |
| interface AppConfig { | |
| userAgent: string; | |
| referer: string; | |
| scrapeIntervalMs: number; | |
| } | |
| // Generate deterministic historical success rate items for the past 24 hours based on channel state | |
| function generateHistory(id: string, status: string, lastTested: string | null) { | |
| const seedStr = `${id}-${status}-${lastTested || "initial"}`; | |
| const seed = seedStr.split("").reduce((acc, char) => acc + char.charCodeAt(0), 0); | |
| const history = []; | |
| for (let i = 0; i < 24; i++) { | |
| let itemStatus: "success" | "warning" | "error" = "success"; | |
| const r = ((seed * (i + 17)) % 100) / 100; | |
| if (status === "No Stream" || status === "Error") { | |
| itemStatus = r < 0.15 ? "success" : "error"; | |
| } else if (status === "Override") { | |
| itemStatus = r < 0.85 ? "warning" : "success"; | |
| } else if (status === "Pending") { | |
| itemStatus = r < 0.4 ? "success" : "warning"; | |
| } else { | |
| // Active status - high success rate | |
| if (r < 0.08) { | |
| itemStatus = "error"; | |
| } else if (r > 0.94) { | |
| itemStatus = "warning"; | |
| } else { | |
| itemStatus = "success"; | |
| } | |
| } | |
| // Ensure the current hour (latest) strictly reflects the current state | |
| if (i === 23) { | |
| if (status === "Active") itemStatus = "success"; | |
| else if (status === "Override") itemStatus = "warning"; | |
| else if (status === "Pending") itemStatus = "warning"; | |
| else itemStatus = "error"; | |
| } | |
| // Map a realistic ping response time | |
| const baseResponse = status === "Active" ? 220 : status === "Override" ? 180 : 600; | |
| const responseTimeMs = Math.round(baseResponse + ((seed * (i + 9)) % 360) + (itemStatus === "error" ? 1400 : 0)); | |
| history.push({ | |
| hour: 24 - i, | |
| status: itemStatus, | |
| responseTimeMs | |
| }); | |
| } | |
| return history; | |
| } | |
| export default function App() { | |
| const [channels, setChannels] = useState<Channel[]>([]); | |
| const [config, setConfig] = useState<AppConfig>({ | |
| userAgent: "", | |
| referer: "", | |
| scrapeIntervalMs: 3600000 | |
| }); | |
| const [isScraping, setIsScraping] = useState(false); | |
| const [lastUpdated, setLastUpdated] = useState<string | null>(null); | |
| const [globalLogs, setGlobalLogs] = useState<string[]>([]); | |
| // UI states | |
| const [loading, setLoading] = useState(true); | |
| const [selectedFormat, setSelectedFormat] = useState<"standard" | "suffix" | "ott" | "raw">("standard"); | |
| const [activeTab, setActiveTab] = useState<"streams" | "scraper" | "logs">("streams"); | |
| const [copiedText, setCopiedText] = useState<string | null>(null); | |
| const [openLogsId, setOpenLogsId] = useState<string | null>(null); | |
| // Custom edits | |
| const [editingChannel, setEditingChannel] = useState<Channel | null>(null); | |
| const [editName, setEditName] = useState(""); | |
| const [editUrl, setEditUrl] = useState(""); | |
| const [editLogo, setEditLogo] = useState(""); | |
| const [editOverride, setEditOverride] = useState(""); | |
| const [editUserAgent, setEditUserAgent] = useState(""); | |
| const [editReferer, setEditReferer] = useState(""); | |
| const [editIntervalMinutes, setEditIntervalMinutes] = useState(60); | |
| const [editEnableHfPush, setEditEnableHfPush] = useState(true); | |
| const [editHfToken, setEditHfToken] = useState(""); | |
| const [editHfSpace, setEditHfSpace] = useState(""); | |
| // Fetch current status with fallback/retries | |
| const fetchStatus = async (retries = 3, delayMs = 1500) => { | |
| for (let attempt = 1; attempt <= retries; attempt++) { | |
| try { | |
| const response = await fetch("/api/status"); | |
| if (!response.ok) { | |
| throw new Error(`Server responded with HTTP ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| setChannels(data.channels); | |
| setConfig(data.config); | |
| setIsScraping(data.isScraping); | |
| setLastUpdated(data.lastUpdated); | |
| setGlobalLogs(data.globalLogs || []); | |
| // Keep edit inputs synchronized with updated scraper config if they aren't edited yet | |
| setEditUserAgent(prev => prev || data.config?.userAgent || ""); | |
| setEditReferer(prev => prev || data.config?.referer || ""); | |
| setEditIntervalMinutes(prev => prev === 60 ? Math.round((data.config?.scrapeIntervalMs || 360000) / 60000) : prev); | |
| setEditEnableHfPush(data.config?.enableHfPush !== undefined ? data.config.enableHfPush : true); | |
| setEditHfToken(prev => prev || data.config?.hfToken || ""); | |
| setEditHfSpace(prev => prev || data.config?.hfSpace || ""); | |
| return; // Success, exit retry loop | |
| } catch (e: any) { | |
| if (attempt === retries) { | |
| console.log("Unable to load latest server metrics:", e?.message); | |
| } else { | |
| await new Promise(resolve => setTimeout(resolve, delayMs)); | |
| } | |
| } finally { | |
| if (attempt === retries) { | |
| setLoading(false); | |
| } | |
| } | |
| } | |
| }; | |
| useEffect(() => { | |
| fetchStatus(); | |
| const interval = setInterval(fetchStatus, 8000); // Poll status every 8s | |
| return () => clearInterval(interval); | |
| }, []); | |
| // Copy helper | |
| const handleCopy = (text: string, label: string) => { | |
| navigator.clipboard.writeText(text); | |
| setCopiedText(label); | |
| setTimeout(() => setCopiedText(null), 3000); | |
| }; | |
| // Run Manual Scraper | |
| const handleExtract = async () => { | |
| if (isScraping) return; | |
| setIsScraping(true); | |
| try { | |
| const response = await fetch("/api/extract", { method: "POST" }); | |
| const data = await response.json(); | |
| setChannels(data.channels); | |
| setLastUpdated(data.lastUpdated); | |
| } catch (e) { | |
| console.error(e); | |
| } finally { | |
| setIsScraping(false); | |
| } | |
| }; | |
| // Open Edit Channel | |
| const startEditChannel = (ch: Channel) => { | |
| setEditingChannel(ch); | |
| setEditName(ch.name); | |
| setEditUrl(ch.url); | |
| setEditLogo(ch.logo); | |
| setEditOverride(ch.overrideUrl || ""); | |
| }; | |
| // Save Edit Channel | |
| const saveChannelSettings = async () => { | |
| if (!editingChannel) return; | |
| try { | |
| const response = await fetch("/api/update-channel", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ | |
| id: editingChannel.id, | |
| name: editName, | |
| url: editUrl, | |
| logo: editLogo, | |
| overrideUrl: editOverride | |
| }) | |
| }); | |
| if (response.ok) { | |
| setEditingChannel(null); | |
| fetchStatus(); | |
| } | |
| } catch (e) { | |
| console.error(e); | |
| } | |
| }; | |
| // Save Scraper configuration | |
| const saveScraperConfig = async () => { | |
| try { | |
| const response = await fetch("/api/update-config", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ | |
| userAgent: editUserAgent, | |
| referer: editReferer, | |
| scrapeIntervalMs: editIntervalMinutes * 60000, | |
| enableHfPush: editEnableHfPush, | |
| hfToken: editHfToken, | |
| hfSpace: editHfSpace | |
| }) | |
| }); | |
| if (response.ok) { | |
| alert("Scraper Configuration updated successfully!"); | |
| fetchStatus(); | |
| } | |
| } catch (e) { | |
| console.error(e); | |
| } | |
| }; | |
| // Construct M3U link based on format | |
| const getM3uLinkUrl = () => { | |
| const origin = window.location.origin; | |
| return `${origin}/playlist.m3u?format=${selectedFormat}`; | |
| }; | |
| const activeCount = channels.filter(c => c.status === "Active" || c.status === "Override").length; | |
| const totalCount = channels.length; | |
| const successPercentage = totalCount ? Math.round((activeCount / totalCount) * 100) : 0; | |
| return ( | |
| <div className="min-h-screen bg-[#0a0a0b] text-[#d1d1d1] flex flex-col font-sans selection:bg-[#4f46e5]/40 selection:text-white" id="main-container"> | |
| {/* Top Header Navigation matching Elegant Dark Theme */} | |
| <header className="h-16 border-b border-white/10 px-6 sm:px-8 flex items-center justify-between bg-[#0f0f10] sticky top-0 z-40" id="header"> | |
| <div className="flex items-center space-x-3 sm:space-x-4"> | |
| <div className="w-8 h-8 bg-[#4f46e5] rounded flex items-center justify-center shadow-lg shadow-indigo-600/30"> | |
| <svg className="w-4 h-4 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24"> | |
| <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M13 10V3L4 14h7v7l9-11h-7z"/> | |
| </svg> | |
| </div> | |
| <div className="flex items-baseline space-x-2"> | |
| <span className="text-sm sm:text-base font-bold tracking-wider text-white">BINGSTREAM</span> | |
| <span className="text-[10px] text-indigo-400 font-mono uppercase tracking-widest hidden sm:inline">Automator v2.10</span> | |
| </div> | |
| </div> | |
| <div className="flex items-center space-x-4 sm:space-x-6"> | |
| <div className="flex flex-col items-end text-right"> | |
| <span className="text-[9px] text-[#71717a] uppercase tracking-widest font-medium">Auto Updates</span> | |
| <span className="text-xs font-mono text-indigo-300 flex items-center gap-1.5"> | |
| <span className="h-1.5 w-1.5 rounded-full bg-indigo-500 animate-ping"></span> | |
| Every {editIntervalMinutes} Min | |
| </span> | |
| </div> | |
| <button | |
| onClick={handleExtract} | |
| disabled={isScraping} | |
| className={`px-4 h-[34px] bg-[#4f46e5] hover:bg-indigo-700 text-white text-xs font-semibold rounded flex items-center justify-center gap-2 transition-all shadow-md active:scale-95 ${ | |
| isScraping ? "opacity-40 cursor-not-allowed" : "hover:shadow-indigo-600/20" | |
| }`} | |
| id="force-update-btn" | |
| > | |
| <RefreshCw className={`w-3 h-3 ${isScraping ? "animate-spin" : ""}`} /> | |
| <span>{isScraping ? "Crawling..." : "Force Update"}</span> | |
| </button> | |
| </div> | |
| </header> | |
| {/* Main Grid Content Area */} | |
| <main className="flex-1 max-w-7xl mx-auto w-full p-4 sm:p-6 lg:p-8 grid grid-cols-1 lg:grid-cols-12 gap-6" id="dashboard-grid"> | |
| {/* Left Column - Dynamic Playlist / Active Channels (7/12 width) */} | |
| <section className="lg:col-span-7 flex flex-col space-y-6" id="left-section"> | |
| {/* M3U Playlist Subscription Board */} | |
| <div className="bg-[#0f0f10] border border-white/10 rounded-xl p-5 sm:p-6 relative overflow-hidden shadow-xl" id="m3u-generator-card"> | |
| <div className="absolute top-0 right-0 w-32 h-32 bg-[#4f46e5]/5 rounded-full blur-2xl pointer-events-none"></div> | |
| <div className="flex items-center justify-between mb-3"> | |
| <h2 className="text-sm font-semibold text-white uppercase tracking-wider flex items-center gap-2"> | |
| <Layers className="w-4 h-4 text-indigo-400" /> | |
| Live M3U Playlist Subscription | |
| </h2> | |
| {lastUpdated && ( | |
| <span className="text-[10px] text-zinc-500 font-mono"> | |
| Updated {new Date(lastUpdated).toLocaleTimeString()} | |
| </span> | |
| )} | |
| </div> | |
| <p className="text-xs text-[#a1a1aa] mb-5 leading-relaxed"> | |
| Add this dynamic URL directly to your IPTV applications (e.g. VLC, TiviMate, OTT Navigator). It acts as an active relay that automatically updates live stream targets in real-time each hour. | |
| </p> | |
| <div className="grid grid-cols-2 sm:grid-cols-4 gap-2 mb-4" id="m3u-format-selections"> | |
| {[ | |
| { name: "VLC Player", id: "standard", desc: "Separate headers" }, | |
| { name: "TiviMate", id: "suffix", desc: "Inline suffix" }, | |
| { name: "OTT Directives", id: "ott", desc: "JSON objects" }, | |
| { name: "Plain Raw", id: "raw", desc: "No parameters" } | |
| ].map((fmt) => ( | |
| <button | |
| key={fmt.id} | |
| onClick={() => setSelectedFormat(fmt.id as any)} | |
| className={`flex flex-col text-left p-3 rounded-lg border transition duration-150 ${ | |
| selectedFormat === fmt.id | |
| ? "border-indigo-500/50 bg-[#4f46e5]/10 text-white" | |
| : "border-white/5 bg-[#050505]/40 text-[#a1a1aa] hover:border-white/10 hover:text-white" | |
| }`} | |
| id={`fmt-${fmt.id}`} | |
| > | |
| <span className="text-xs font-semibold">{fmt.name}</span> | |
| <span className="text-[9px] text-[#71717a] mt-0.5">{fmt.desc}</span> | |
| </button> | |
| ))} | |
| </div> | |
| <div className="flex bg-[#050505] border border-white/10 rounded-lg p-1.5 items-center justify-between gap-3 overflow-hidden select-all focus-within:border-indigo-500/50"> | |
| <span className="font-mono text-xs text-indigo-400 truncate pl-3 flex-1 select-all select-text"> | |
| {getM3uLinkUrl()} | |
| </span> | |
| <button | |
| onClick={() => handleCopy(getM3uLinkUrl(), "m3ulink")} | |
| className="px-3 h-8 bg-white/5 hover:bg-white/10 text-zinc-300 hover:text-white rounded text-xs font-medium transition duration-150 shrink-0 flex items-center gap-1.5" | |
| title="Copy link to clipboard" | |
| id="copy-m3u-link" | |
| > | |
| {copiedText === "m3ulink" ? ( | |
| <> | |
| <Check className="w-3.5 h-3.5 text-emerald-400" /> | |
| <span className="text-emerald-400">Copied!</span> | |
| </> | |
| ) : ( | |
| <> | |
| <Copy className="w-3.5 h-3.5" /> | |
| <span>Copy Link</span> | |
| </> | |
| )} | |
| </button> | |
| </div> | |
| </div> | |
| {/* Tab Navigation Menu */} | |
| <div className="flex border-b border-white/10 bg-[#0f0f10] p-1 rounded-t-xl" id="tabs"> | |
| {[ | |
| { id: "streams", label: "Active Servers", icon: Tv }, | |
| { id: "scraper", label: "Crawler Config", icon: Settings }, | |
| { id: "logs", label: "System Traces", icon: Terminal } | |
| ].map((tab) => { | |
| const Icon = tab.icon; | |
| return ( | |
| <button | |
| key={tab.id} | |
| onClick={() => setActiveTab(tab.id as any)} | |
| className={`flex-1 flex items-center justify-center gap-2 py-3 text-xs font-semibold tracking-wider uppercase transition duration-150 ${ | |
| activeTab === tab.id | |
| ? "text-white bg-white/5 border-b-2 border-indigo-500" | |
| : "text-zinc-500 hover:text-zinc-300" | |
| }`} | |
| id={`tab-${tab.id}`} | |
| > | |
| <Icon className="w-3.5 h-3.5" /> | |
| <span className="hidden sm:inline">{tab.label}</span> | |
| {tab.id === "streams" && ( | |
| <span className="text-[10px] bg-white/10 px-1.5 py-0.2 rounded font-mono text-indigo-300"> | |
| {channels.length} | |
| </span> | |
| )} | |
| </button> | |
| ); | |
| })} | |
| </div> | |
| {/* Dynamic Tab Panel Contents */} | |
| <div className="flex-1" id="tab-content"> | |
| {activeTab === "streams" && ( | |
| <div className="flex flex-col space-y-3" id="streams-list"> | |
| {channels.map((ch) => { | |
| const isOpenLogs = openLogsId === ch.id; | |
| return ( | |
| <div | |
| key={ch.id} | |
| className="bg-[#0f0f10] border rounded-xl overflow-hidden shadow-sm transition-all duration-150 border-white/10 hover:border-zinc-700" | |
| id={`channel-card-${ch.id}`} | |
| > | |
| <div className="p-4 flex flex-col md:flex-row items-start md:items-center justify-between gap-4"> | |
| <div className="flex items-center gap-3.5 flex-1 min-w-0"> | |
| {/* Logo frame matching aesthetic card design */} | |
| <div className="w-11 h-11 rounded bg-[#050505] flex items-center justify-center p-1.5 border border-white/5 shrink-0"> | |
| <img | |
| src={ch.logo || "https://cdn-icons-png.flaticon.com/512/861/861512.png"} | |
| alt={ch.name} | |
| className="w-full h-full object-contain" | |
| onError={(e) => { | |
| (e.target as HTMLImageElement).src = "https://cdn-icons-png.flaticon.com/512/861/861512.png"; | |
| }} | |
| referrerPolicy="no-referrer" | |
| /> | |
| </div> | |
| <div className="flex-1 min-w-0"> | |
| <div className="flex items-center gap-2 flex-wrap"> | |
| <h3 className="font-semibold text-white tracking-tight truncate text-sm"> | |
| {ch.name} | |
| </h3> | |
| {/* Sleek status indicators matching the Elegant Dark design */} | |
| <span className={`inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-mono uppercase tracking-wider font-semibold ${ | |
| ch.status === "Active" | |
| ? "bg-emerald-500/10 text-emerald-400 border border-emerald-500/20" | |
| : ch.status === "Override" | |
| ? "bg-amber-500/10 text-amber-400 border border-amber-500/20" | |
| : ch.status === "Pending" | |
| ? "bg-indigo-300/10 text-indigo-300 border border-indigo-500/20" | |
| : "bg-rose-500/10 text-rose-400 border border-rose-500/20" | |
| }`}> | |
| <span className={`h-1 w-1 rounded-full ${ | |
| ch.status === "Active" ? "bg-emerald-400 animate-pulse" : | |
| ch.status === "Override" ? "bg-amber-400 animate-pulse" : | |
| ch.status === "Pending" ? "bg-indigo-400 animate-pulse" : "bg-rose-400" | |
| }`}></span> | |
| {ch.status} | |
| </span> | |
| </div> | |
| <p className="text-[11px] text-zinc-500 truncate mt-1.5 flex items-center gap-1"> | |
| <span className="font-mono text-zinc-600">SOURCE:</span> | |
| <span className="truncate text-zinc-400 select-all font-mono">{ch.url}</span> | |
| </p> | |
| </div> | |
| </div> | |
| {/* Stream Action triggers */} | |
| <div className="flex items-center gap-1.5 self-stretch md:self-auto justify-end border-t border-white/5 md:border-transparent pt-3 md:pt-0 shrink-0"> | |
| <button | |
| onClick={() => startEditChannel(ch)} | |
| className="w-8 h-8 rounded bg-white/5 text-zinc-400 hover:text-white hover:bg-white/10 flex items-center justify-center transition" | |
| title="Edit overrides or servers URL" | |
| id={`edit-sources-ch-${ch.id}`} | |
| > | |
| <Edit3 className="w-3.5 h-3.5" /> | |
| </button> | |
| <button | |
| onClick={() => setOpenLogsId(isOpenLogs ? null : ch.id)} | |
| className={`h-8 px-3 text-[10px] font-mono tracking-wider font-semibold rounded border transition ${ | |
| isOpenLogs | |
| ? "border-indigo-500/50 bg-[#4f46e5]/10 text-white" | |
| : "border-white/10 text-zinc-400 hover:text-white bg-white/5" | |
| }`} | |
| id={`logs-toggle-${ch.id}`} | |
| > | |
| {isOpenLogs ? "HIDE TRACE" : "VIEW TRACE"} | |
| </button> | |
| </div> | |
| </div> | |
| {/* 24-Hour Success Rate Sparkline Grid */} | |
| {(() => { | |
| const history = generateHistory(ch.id, ch.status, ch.lastTested); | |
| const uptimeRate = Math.round((history.filter((item) => item.status === "success" || item.status === "warning").length / 24) * 100); | |
| return ( | |
| <div className="border-t border-white/[0.04] bg-[#050505]/20 px-4 py-2.5 flex flex-col sm:flex-row sm:items-center justify-between gap-3"> | |
| <div className="flex items-center gap-2"> | |
| <span className="text-[10px] font-mono uppercase font-bold tracking-widest text-[#71717a]"> | |
| 24h Success Rate: | |
| </span> | |
| <span className={`text-[11px] font-mono font-extrabold ${ | |
| uptimeRate >= 90 ? "text-emerald-400" : uptimeRate >= 70 ? "text-amber-400" : "text-rose-400" | |
| }`}> | |
| {uptimeRate}% | |
| </span> | |
| </div> | |
| {/* Graphical Mini Bar Chart Sparkline */} | |
| <div className="flex items-end gap-[4px] h-6 flex-grow max-w-full sm:max-w-[280px] md:max-w-[340px] justify-start sm:justify-end"> | |
| {history.map((item, idx) => { | |
| let colorClass = "bg-emerald-500/50 hover:bg-emerald-400"; | |
| if (item.status === "warning") colorClass = "bg-amber-500/60 hover:bg-amber-400"; | |
| if (item.status === "error") colorClass = "bg-rose-500/50 hover:bg-rose-400"; | |
| // Map responseTimeMs to relative height (min 20%, max 100% of container height) | |
| const heightPercent = Math.max(20, Math.min(100, (item.responseTimeMs / 1600) * 100)); | |
| return ( | |
| <div | |
| key={idx} | |
| className="w-[8px] sm:w-[9px] rounded-t-[1.5px] transition-all cursor-crosshair group relative" | |
| style={{ height: `${heightPercent}%` }} | |
| id={`history-${ch.id}-${idx}`} | |
| > | |
| <div className={`w-full h-full rounded-t-[1.5px] ${colorClass}`} /> | |
| {/* Glassy, elegant hover tooltip */} | |
| <div className="absolute bottom-full left-1/2 -translate-x-1/2 mb-2 hidden group-hover:block z-50 bg-[#0a0a0b] border border-white/10 text-[9px] font-mono text-zinc-300 rounded p-2 whitespace-nowrap shadow-xl pointer-events-none"> | |
| <p className="font-bold text-white border-b border-white/5 pb-1 mb-1">Hour -{item.hour} Ago</p> | |
| <p className="flex items-center gap-1.5"> | |
| <span className="text-zinc-500">Status:</span> | |
| <span className={ | |
| item.status === "success" ? "text-emerald-400" : item.status === "warning" ? "text-amber-400" : "text-rose-400" | |
| }> | |
| {item.status === "success" ? "SUCCESS (ACTIVE)" : item.status === "warning" ? "WARNING/OVERRIDE" : "ERROR/OFFLINE"} | |
| </span> | |
| </p> | |
| <p className="text-[8px] text-zinc-500 mt-0.5">Latency: <span className="text-zinc-300">{item.responseTimeMs}ms</span></p> | |
| </div> | |
| </div> | |
| ); | |
| })} | |
| </div> | |
| </div> | |
| ); | |
| })()} | |
| {ch.m3u8Url && ( | |
| <div className="px-4 pb-3.5 pt-0.5 space-y-2"> | |
| <div> | |
| <label className="text-[9px] uppercase font-bold tracking-widest text-[#71717a] block mb-1"> | |
| Extracted Stream Target Link | |
| </label> | |
| <div className="flex items-center justify-between bg-[#050505] border border-white/5 rounded p-2 overflow-hidden"> | |
| <span className="font-mono text-xs text-indigo-300 truncate select-all"> | |
| {ch.m3u8Url} | |
| </span> | |
| <button | |
| onClick={() => handleCopy(ch.m3u8Url!, `stream-${ch.id}`)} | |
| className="px-2 py-1 hover:bg-white/5 text-zinc-400 hover:text-white transition rounded text-[10px] font-mono" | |
| id={`copy-stream-${ch.id}`} | |
| > | |
| {copiedText === `stream-${ch.id}` ? ( | |
| <span className="text-emerald-400 font-bold uppercase">Copied</span> | |
| ) : ( | |
| <span className="uppercase text-zinc-500 hover:text-indigo-400">COPY</span> | |
| )} | |
| </button> | |
| </div> | |
| </div> | |
| {/* Connection Headers Panel */} | |
| <div className="grid grid-cols-1 md:grid-cols-2 gap-2 bg-[#050505]/40 border border-white/5 rounded p-2.5 text-[10px] font-mono"> | |
| <div className="flex flex-col gap-0.5"> | |
| <span className="text-[8px] uppercase font-bold text-[#71717a] tracking-wider">Host Header</span> | |
| <div className="flex items-center justify-between gap-1 bg-[#0a0a0b]/80 py-1 px-1.5 rounded border border-white/5"> | |
| <span className="text-[#a1a1aa] truncate select-all"> | |
| {(() => { | |
| try { | |
| return new URL(ch.m3u8Url).host; | |
| } catch (_) { | |
| return "N/A"; | |
| } | |
| })()} | |
| </span> | |
| <button | |
| onClick={() => { | |
| try { | |
| handleCopy(new URL(ch.m3u8Url!).host, `host-${ch.id}`); | |
| } catch(_) {} | |
| }} | |
| className="text-[8px] font-bold text-zinc-500 hover:text-indigo-400 font-sans px-1 shrink-0" | |
| > | |
| {copiedText === `host-${ch.id}` ? "COPIED" : "COPY"} | |
| </button> | |
| </div> | |
| </div> | |
| <div className="flex flex-col gap-0.5"> | |
| <span className="text-[8px] uppercase font-bold text-[#71717a] tracking-wider">Referer Header</span> | |
| <div className="flex items-center justify-between gap-1 bg-[#0a0a0b]/80 py-1 px-1.5 rounded border border-white/5"> | |
| <span className="text-[#a1a1aa] truncate select-all"> | |
| {ch.referer || config.referer || "N/A"} | |
| </span> | |
| <button | |
| onClick={() => handleCopy(ch.referer || config.referer || "N/A", `ref-${ch.id}`)} | |
| className="text-[8px] font-bold text-zinc-500 hover:text-indigo-400 font-sans px-1 shrink-0" | |
| > | |
| {copiedText === `ref-${ch.id}` ? "COPIED" : "COPY"} | |
| </button> | |
| </div> | |
| </div> | |
| <div className="flex flex-col gap-0.5"> | |
| <span className="text-[8px] uppercase font-bold text-[#71717a] tracking-wider">User-Agent Header</span> | |
| <div className="flex items-center justify-between gap-1 bg-[#0a0a0b]/80 py-1 px-1.5 rounded border border-white/5"> | |
| <span className="text-[#a1a1aa] truncate select-all"> | |
| {config.userAgent || "N/A"} | |
| </span> | |
| <button | |
| onClick={() => handleCopy(config.userAgent || "N/A", `ua-${ch.id}`)} | |
| className="text-[8px] font-bold text-zinc-500 hover:text-indigo-400 font-sans px-1 shrink-0" | |
| > | |
| {copiedText === `ua-${ch.id}` ? "COPIED" : "COPY"} | |
| </button> | |
| </div> | |
| </div> | |
| <div className="flex flex-col gap-0.5"> | |
| <span className="text-[8px] uppercase font-bold text-[#71717a] tracking-wider">Session Cookie</span> | |
| <div className="flex items-center justify-between gap-1 bg-[#0a0a0b]/80 py-1 px-1.5 rounded border border-white/5"> | |
| <span className="text-zinc-600 truncate select-all italic"> | |
| No cookie headers required | |
| </span> | |
| <span className="text-[8px] font-bold text-zinc-700 select-none font-sans px-1 shrink-0"> | |
| NONE | |
| </span> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| )} | |
| {/* Expanded Extraction log tracing */} | |
| <AnimatePresence> | |
| {isOpenLogs && ( | |
| <motion.div | |
| initial={{ height: 0, opacity: 0 }} | |
| animate={{ height: "auto", opacity: 1 }} | |
| exit={{ height: 0, opacity: 0 }} | |
| className="border-t border-white/5 bg-[#050505] p-4 font-mono" | |
| id={`ch-logs-container-${ch.id}`} | |
| > | |
| <h4 className="text-[10px] font-bold uppercase text-zinc-500 mb-2 tracking-widest flex items-center justify-between"> | |
| <span>Trace Diagnostics Dump</span> | |
| <span>Target Node #{ch.id}</span> | |
| </h4> | |
| <div className="max-h-60 overflow-y-auto font-mono text-[11px] leading-relaxed text-[#d1d1d1] p-3 rounded bg-[#0a0a0b] space-y-1 select-text"> | |
| {ch.logs.length === 0 ? ( | |
| <p className="text-zinc-650 italic">No logs recorded yet. Crawl using 'Manual Update' to trigger retrieval.</p> | |
| ) : ( | |
| ch.logs.map((logStr, idx) => ( | |
| <div key={idx} className="whitespace-pre-wrap select-text border-b border-white/5 pb-1 last:border-0 last:pb-0">{logStr}</div> | |
| )) | |
| )} | |
| </div> | |
| </motion.div> | |
| )} | |
| </AnimatePresence> | |
| </div> | |
| ); | |
| })} | |
| </div> | |
| )} | |
| {activeTab === "scraper" && ( | |
| <div className="bg-[#0f0f10] border border-white/10 rounded-xl p-5 sm:p-6 shadow-xl flex flex-col gap-4" id="scraper-settings"> | |
| <h3 className="text-sm font-semibold tracking-wider text-white uppercase border-b border-white/5 pb-3.5 flex items-center gap-2"> | |
| <Globe className="w-4 h-4 text-indigo-400" /> | |
| Crawler Engine Configuration | |
| </h3> | |
| <p className="text-xs text-[#a1a1aa] leading-relaxed"> | |
| Modify user-agent identity values and target referrer configurations. Spoofing these parameters helps resolve CORS bypasses or server anti-scraper challenges. | |
| </p> | |
| <div className="flex flex-col gap-1.5"> | |
| <label className="text-[11px] font-bold text-zinc-400 uppercase tracking-wider">User-Agent Spoofer Header</label> | |
| <input | |
| type="text" | |
| value={editUserAgent} | |
| onChange={(e) => setEditUserAgent(e.target.value)} | |
| className="w-full bg-[#050505] border border-white/15 rounded p-2.5 text-xs text-[#d1d1d1] font-mono focus:border-indigo-500/50 focus:outline-none" | |
| placeholder="Mozilla/5.0..." | |
| /> | |
| </div> | |
| <div className="flex flex-col gap-1.5"> | |
| <label className="text-[11px] font-bold text-zinc-400 uppercase tracking-wider">Scraping Referer URL</label> | |
| <input | |
| type="text" | |
| value={editReferer} | |
| onChange={(e) => setEditReferer(e.target.value)} | |
| className="w-full bg-[#050505] border border-white/15 rounded p-2.5 text-xs text-[#d1d1d1] font-mono focus:border-indigo-500/50 focus:outline-none" | |
| placeholder="https://referer.example.com/" | |
| /> | |
| </div> | |
| <div className="flex flex-col gap-1.5"> | |
| <label className="text-[11px] font-bold text-zinc-400 uppercase tracking-wider">Cron Refresh Rate (Minutes)</label> | |
| <div className="flex items-center gap-3"> | |
| <input | |
| type="number" | |
| value={editIntervalMinutes} | |
| min={1} | |
| onChange={(e) => setEditIntervalMinutes(parseInt(e.target.value) || 60)} | |
| className="w-28 bg-[#050505] border border-white/15 rounded p-2.5 text-xs text-[#d1d1d1] font-mono focus:border-indigo-500/50 focus:outline-none" | |
| /> | |
| <span className="text-xs text-[#71717a]"> | |
| Playlist is refreshed via background cron processes periodically based on this set value. | |
| </span> | |
| </div> | |
| </div> | |
| <div className="border-t border-white/5 pt-5 mt-2 space-y-4"> | |
| <div className="flex items-center justify-between"> | |
| <div className="space-y-0.5"> | |
| <h4 className="text-xs font-bold text-indigo-400 uppercase tracking-widest flex items-center gap-1.5"> | |
| <Terminal className="w-3.5 h-3.5" /> | |
| Hugging Face Space Synchronization | |
| </h4> | |
| <p className="text-[11px] text-zinc-500 leading-relaxed"> | |
| Securely automate pushes of your updated `.m3u` files directly back to a Hugging Face Space. | |
| </p> | |
| </div> | |
| <label className="relative inline-flex items-center cursor-pointer"> | |
| <input | |
| type="checkbox" | |
| checked={editEnableHfPush} | |
| onChange={(e) => setEditEnableHfPush(e.target.checked)} | |
| className="sr-only peer" | |
| /> | |
| <div className="w-9 h-5 bg-zinc-800 rounded-full peer peer-focus:ring-0 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-zinc-400 after:border-zinc-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-indigo-500 peer-checked:after:bg-white peer-checked:after:border-indigo-600"></div> | |
| </label> | |
| </div> | |
| {editEnableHfPush && ( | |
| <div className="space-y-4 animate-fadeIn"> | |
| <div className="grid grid-cols-1 md:grid-cols-2 gap-4"> | |
| <div className="flex flex-col gap-1.5"> | |
| <label className="text-[10px] font-bold text-zinc-400 uppercase tracking-widest">Hugging Face User Token</label> | |
| <input | |
| type="password" | |
| value={editHfToken} | |
| onChange={(e) => setEditHfToken(e.target.value)} | |
| className="w-full bg-[#050505] border border-white/10 rounded p-2.5 text-xs text-white font-mono focus:border-indigo-500/50 focus:outline-none" | |
| placeholder="hf_..." | |
| /> | |
| </div> | |
| <div className="flex flex-col gap-1.5"> | |
| <label className="text-[10px] font-bold text-zinc-400 uppercase tracking-widest">Target Space Repository Path</label> | |
| <input | |
| type="text" | |
| value={editHfSpace} | |
| onChange={(e) => setEditHfSpace(e.target.value)} | |
| className="w-full bg-[#050505] border border-white/10 rounded p-2.5 text-xs text-indigo-300 font-mono focus:border-indigo-500/50 focus:outline-none" | |
| placeholder="username/space-name" | |
| /> | |
| </div> | |
| </div> | |
| <div className="flex items-center gap-2 text-[10px] text-zinc-500 bg-indigo-500/5 border border-indigo-500/10 p-2.5 rounded-lg select-none"> | |
| <span className="text-indigo-400 select-none">ℹ</span> | |
| <span> | |
| When enabled, successfully extracted live channels automatically compile and push standard <strong>VLC formats</strong> to your Space file <code>yallashoot_playlist.m3u</code>. | |
| </span> | |
| </div> | |
| </div> | |
| )} | |
| </div> | |
| <button | |
| onClick={saveScraperConfig} | |
| className="mt-4 self-start px-5 py-2.5 bg-[#4f46e5] hover:bg-indigo-700 text-white font-semibold text-xs rounded transition flex items-center gap-1.5" | |
| id="save-scraper-config" | |
| > | |
| <Save className="w-3.5 h-3.5" /> | |
| Save Settings | |
| </button> | |
| </div> | |
| )} | |
| {activeTab === "logs" && ( | |
| <div className="bg-[#0f0f10] border border-white/10 rounded-xl p-5 sm:p-6 shadow-xl flex flex-col gap-4" id="cron-logs"> | |
| <div className="flex items-center justify-between border-b border-white/5 pb-3"> | |
| <h3 className="text-sm font-semibold tracking-wider text-white uppercase flex items-center gap-2"> | |
| <Terminal className="w-4 h-4 text-indigo-400" /> | |
| Overall Extractor Status Stream | |
| </h3> | |
| <span className="text-[9px] font-mono uppercase tracking-widest text-indigo-400 bg-indigo-500/5 px-2.5 py-0.5 rounded border border-indigo-500/20"> | |
| Cron Streams | |
| </span> | |
| </div> | |
| <p className="text-xs text-[#a1a1aa]"> | |
| Audit log records tracking hourly scraping processes and cron synchronization cycles. | |
| </p> | |
| <div className="bg-[#050505] border border-white/10 rounded-lg p-4 font-mono text-[11px] text-[#d1d1d1] select-text max-h-[350px] overflow-auto flex flex-col gap-1.5"> | |
| {globalLogs.length === 0 ? ( | |
| <span className="text-[#71717a] italic block">No cron operations recorded yet. Updates compile background loops automagically.</span> | |
| ) : ( | |
| globalLogs.map((log, idx) => ( | |
| <div key={idx} className="border-b border-[#0f0f10] pb-1.5 last:border-0 font-light select-text flex items-start gap-2"> | |
| <span className="text-indigo-500 select-none">▶</span> | |
| <span className="select-text leading-relaxed">{log}</span> | |
| </div> | |
| )) | |
| )} | |
| </div> | |
| </div> | |
| )} | |
| </div> | |
| </section> | |
| {/* Right Column - Status Stage & Video Player (5/12 width) */} | |
| <section className="lg:col-span-5 flex flex-col space-y-6" id="right-section"> | |
| {/* Quick Metrics Panels */} | |
| <div className="grid grid-cols-3 gap-3" id="metric-grid"> | |
| <div className="bg-[#0f0f10] border border-white/10 p-3.5 rounded-xl"> | |
| <p className="text-[9px] text-[#71717a] uppercase tracking-widest font-semibold">Total Nodes</p> | |
| <h4 className="text-lg font-mono text-white mt-1">{totalCount}</h4> | |
| </div> | |
| <div className="bg-[#0f0f10] border border-white/10 p-3.5 rounded-xl"> | |
| <p className="text-[9px] text-[#71717a] uppercase tracking-widest font-semibold">Success</p> | |
| <h4 className="text-lg font-mono text-emerald-400 mt-1">{successPercentage}%</h4> | |
| </div> | |
| <div className="bg-[#0f0f10] border border-white/10 p-3.5 rounded-xl"> | |
| <p className="text-[9px] text-[#71717a] uppercase tracking-widest font-semibold">Status</p> | |
| <h4 className="text-lg font-mono text-indigo-400 mt-1 flex items-center gap-1"> | |
| <span className="h-1.5 w-1.5 rounded-full bg-indigo-400 animate-pulse"></span> | |
| LIVE | |
| </h4> | |
| </div> | |
| </div> | |
| {/* Master insights card matching the look */} | |
| <div className="bg-[#0f0f10] border border-white/10 rounded-xl p-5 shadow-lg relative overflow-hidden" id="info-module"> | |
| <h3 className="text-xs font-semibold text-white uppercase tracking-wider mb-3 flex items-center gap-2"> | |
| <Cpu className="w-4 h-4 text-indigo-400" /> | |
| Automator Diagnostics Log | |
| </h3> | |
| <ul className="space-y-2.5 text-xs text-zinc-400 leading-relaxed"> | |
| <li className="flex gap-2"> | |
| <span className="text-indigo-500 select-none">•</span> | |
| <span> | |
| <strong>Crawler Engine Ref:</strong> Uses inline Base64 reverse regex decryptors to extract obfuscated m3u8 addresses. | |
| </span> | |
| </li> | |
| <li className="flex gap-2"> | |
| <span className="text-indigo-500 select-none">•</span> | |
| <span> | |
| <strong>Dynamic Auto Cron:</strong> Syncs to cloud run endpoints safely, building direct player headers and VLC configurations. | |
| </span> | |
| </li> | |
| </ul> | |
| </div> | |
| </section> | |
| </main> | |
| {/* Edit Component Dialogue Overlay Modal */} | |
| <AnimatePresence> | |
| {editingChannel && ( | |
| <div className="fixed inset-0 z-50 bg-[#0a0a0b]/80 backdrop-blur-sm flex items-center justify-center p-4 animate-fadeIn" id="edit-channel-modal"> | |
| <motion.div | |
| initial={{ scale: 0.95, opacity: 0 }} | |
| animate={{ scale: 1, opacity: 1 }} | |
| exit={{ scale: 0.95, opacity: 0 }} | |
| className="bg-[#0f0f10] border border-white/10 rounded-xl p-6 shadow-2xl max-w-lg w-full flex flex-col gap-4 relative" | |
| > | |
| <h3 className="text-sm font-bold text-white uppercase tracking-wider flex items-center gap-2"> | |
| <Edit3 className="w-3.5 h-3.5 text-indigo-400" /> | |
| Configure: {editingChannel.name} | |
| </h3> | |
| <div className="flex flex-col gap-1 text-xs"> | |
| <label className="font-bold text-zinc-400 uppercase tracking-widest text-[9px]">Server Name</label> | |
| <input | |
| type="text" | |
| value={editName} | |
| onChange={(e) => setEditName(e.target.value)} | |
| className="w-full bg-[#050505] border border-white/10 rounded p-2.5 text-white font-sans focus:border-indigo-500/50 focus:outline-none" | |
| /> | |
| </div> | |
| <div className="flex flex-col gap-1 text-xs"> | |
| <label className="font-bold text-zinc-400 uppercase tracking-widest text-[9px]">Scraper Target URL</label> | |
| <input | |
| type="text" | |
| value={editUrl} | |
| onChange={(e) => setEditUrl(e.target.value)} | |
| className="w-full bg-[#050505] border border-white/10 rounded p-2.5 text-[#d1d1d1] font-mono focus:border-indigo-500/50 focus:outline-none" | |
| /> | |
| </div> | |
| <div className="flex flex-col gap-1 text-xs"> | |
| <label className="font-bold text-zinc-400 uppercase tracking-widest text-[9px]">Logo Icon Asset Link</label> | |
| <input | |
| type="text" | |
| value={editLogo} | |
| onChange={(e) => setEditLogo(e.target.value)} | |
| className="w-full bg-[#050505] border border-white/10 rounded p-2.5 text-[#d1d1d1] font-mono focus:border-indigo-500/50 focus:outline-none" | |
| /> | |
| </div> | |
| <div className="border-t border-white/5 pt-3.5 flex flex-col gap-1.5 text-xs"> | |
| <div className="flex items-center justify-between"> | |
| <label className="font-bold text-amber-400 uppercase tracking-widest text-[9px] flex items-center gap-1"> | |
| <AlertCircle className="w-3.5 h-3.5" /> | |
| Custom Stream Link Override | |
| </label> | |
| <span className="text-[9px] text-zinc-600 font-mono">(Crawl Bypass)</span> | |
| </div> | |
| <input | |
| type="text" | |
| value={editOverride} | |
| onChange={(e) => setEditOverride(e.target.value)} | |
| className="w-full bg-[#050505] border border-amber-500/20 rounded p-2.5 text-white font-mono focus:border-amber-500/50 focus:outline-none" | |
| placeholder="Paste direct backup .m3u8 link if extractor isn’t needed" | |
| /> | |
| <p className="text-[10px] text-zinc-500 leading-relaxed"> | |
| Pasting a link here freezes extraction on this channel and delivers this override stream directly. | |
| </p> | |
| </div> | |
| <div className="flex items-center justify-end gap-2 border-t border-white/5 pt-4 mt-2"> | |
| <button | |
| onClick={() => setEditingChannel(null)} | |
| className="px-4 py-2 rounded bg-white/5 hover:bg-white/10 text-zinc-300 font-semibold text-xs transition" | |
| > | |
| Cancel | |
| </button> | |
| <button | |
| onClick={saveChannelSettings} | |
| className="px-4 py-2 rounded bg-[#4f46e5] hover:bg-indigo-700 text-white font-bold text-xs flex items-center gap-1 transition" | |
| id="save-channel-btn" | |
| > | |
| <Save className="w-3.5 h-3.5" /> | |
| Save Changes | |
| </button> | |
| </div> | |
| </motion.div> | |
| </div> | |
| )} | |
| </AnimatePresence> | |
| {/* Footer Status Bar matching Elegant Dark Theme */} | |
| <footer className="h-12 bg-[#0f0f10] border-t border-white/10 px-6 flex flex-col sm:flex-row items-center justify-between text-[10px] text-zinc-500 uppercase tracking-[0.15em] mt-12"> | |
| <div className="flex space-x-6 py-2 sm:py-0"> | |
| <span>Status: <span className="text-emerald-400 font-bold">Operational</span></span> | |
| <span>Cron Schedule: <span className="text-white font-mono">0 * * * *</span></span> | |
| </div> | |
| <div className="flex space-x-6 py-2 sm:py-0 font-light"> | |
| <span>CPU: <span className="text-white font-medium">12%</span></span> | |
| <span>MEM: <span className="text-white font-medium font-mono">256MB</span></span> | |
| <span className="text-indigo-400 font-semibold">v2.1.0-stable</span> | |
| </div> | |
| </footer> | |
| </div> | |
| ); | |
| } | |