feat: add IPTV export functionality with M3U and XMLTV generation, including UI components for export dialog

This commit is contained in:
2026-03-14 02:11:20 +01:00
parent 66ec0c51c0
commit e610c23fea
9 changed files with 462 additions and 32 deletions

View File

@@ -1,7 +1,16 @@
"use client";
import Link from "next/link";
import { Pencil, Trash2, RefreshCw, Tv2, CalendarDays, Download, ChevronUp, ChevronDown } from "lucide-react";
import {
Pencil,
Trash2,
RefreshCw,
Tv2,
CalendarDays,
Download,
ChevronUp,
ChevronDown,
} from "lucide-react";
import { Button } from "@/components/ui/button";
import { useActiveSchedule } from "@/hooks/use-channels";
import type { ChannelResponse } from "@/lib/types";
@@ -34,7 +43,12 @@ function useScheduleStatus(channelId: string) {
const h = Math.ceil(hoursLeft);
return { status: "expiring" as const, label: `Expires in ${h}h` };
}
const fmt = expiresAt.toLocaleDateString(undefined, { weekday: "short", hour: "2-digit", minute: "2-digit", hour12: false });
const fmt = expiresAt.toLocaleDateString(undefined, {
weekday: "short",
hour: "2-digit",
minute: "2-digit",
hour12: false,
});
return { status: "ok" as const, label: `Until ${fmt}` };
}
@@ -55,10 +69,13 @@ export function ChannelCard({
const { status, label } = useScheduleStatus(channel.id);
const scheduleColor =
status === "expired" ? "text-red-400" :
status === "expiring" ? "text-amber-400" :
status === "ok" ? "text-zinc-500" :
"text-zinc-600";
status === "expired"
? "text-red-400"
: status === "expiring"
? "text-amber-400"
: status === "ok"
? "text-zinc-500"
: "text-zinc-600";
return (
<div className="flex flex-col gap-4 rounded-xl border border-zinc-800 bg-zinc-900 p-5 transition-colors hover:border-zinc-700">
@@ -131,9 +148,7 @@ export function ChannelCard({
<span>
{blockCount} {blockCount === 1 ? "block" : "blocks"}
</span>
{label && (
<span className={scheduleColor}>{label}</span>
)}
{label && <span className={scheduleColor}>{label}</span>}
</div>
{/* Actions */}
@@ -144,11 +159,12 @@ export function ChannelCard({
disabled={isGenerating}
className={`flex-1 ${status === "expired" ? "border border-red-800/50 bg-red-950/30 text-red-300 hover:bg-red-900/40" : ""}`}
>
<RefreshCw className={`size-3.5 ${isGenerating ? "animate-spin" : ""}`} />
<RefreshCw
className={`size-3.5 ${isGenerating ? "animate-spin" : ""}`}
/>
{isGenerating ? "Generating…" : "Generate schedule"}
</Button>
<Button
variant="outline"
size="icon-sm"
onClick={onViewSchedule}
title="View schedule"
@@ -157,7 +173,6 @@ export function ChannelCard({
<CalendarDays className="size-3.5" />
</Button>
<Button
variant="outline"
size="icon-sm"
asChild
title="Watch on TV"

View File

@@ -0,0 +1,116 @@
"use client";
import { useState } from "react";
import { Copy, Check } from "lucide-react";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { toast } from "sonner";
const API_BASE =
process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:3000/api/v1";
interface IptvExportDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
token: string;
}
export function IptvExportDialog({
open,
onOpenChange,
token,
}: IptvExportDialogProps) {
const m3uUrl = `${API_BASE}/iptv/playlist.m3u?token=${token}`;
const xmltvUrl = `${API_BASE}/iptv/epg.xml?token=${token}`;
const [copiedM3u, setCopiedM3u] = useState(false);
const [copiedXmltv, setCopiedXmltv] = useState(false);
const copy = async (text: string, which: "m3u" | "xmltv") => {
try {
await navigator.clipboard.writeText(text);
if (which === "m3u") {
setCopiedM3u(true);
setTimeout(() => setCopiedM3u(false), 2000);
} else {
setCopiedXmltv(true);
setTimeout(() => setCopiedXmltv(false), 2000);
}
toast.success("Copied to clipboard");
} catch {
toast.error("Failed to copy");
}
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="bg-zinc-900 border-zinc-800 text-zinc-100 sm:max-w-lg">
<DialogHeader>
<DialogTitle>IPTV Export</DialogTitle>
<DialogDescription className="text-zinc-400">
Paste these URLs into your IPTV client (TiviMate, VLC, etc.).
</DialogDescription>
</DialogHeader>
<div className="space-y-4">
<div className="space-y-1.5">
<Label className="text-zinc-300 text-xs">M3U Playlist</Label>
<p className="text-xs text-zinc-500">
Add Playlist paste URL
</p>
<div className="flex gap-2">
<Input
readOnly
value={m3uUrl}
className="bg-zinc-800 border-zinc-700 text-zinc-300 font-mono text-xs"
/>
<Button
variant="outline"
size="icon"
className="shrink-0 border-zinc-700 text-zinc-400 hover:text-zinc-100"
onClick={() => copy(m3uUrl, "m3u")}
>
{copiedM3u ? <Check className="size-4" /> : <Copy className="size-4" />}
</Button>
</div>
</div>
<div className="space-y-1.5">
<Label className="text-zinc-300 text-xs">XMLTV EPG</Label>
<p className="text-xs text-zinc-500">
EPG Source paste URL
</p>
<div className="flex gap-2">
<Input
readOnly
value={xmltvUrl}
className="bg-zinc-800 border-zinc-700 text-zinc-300 font-mono text-xs"
/>
<Button
variant="outline"
size="icon"
className="shrink-0 border-zinc-700 text-zinc-400 hover:text-zinc-100"
onClick={() => copy(xmltvUrl, "xmltv")}
>
{copiedXmltv ? <Check className="size-4" /> : <Copy className="size-4" />}
</Button>
</div>
</div>
<p className="text-xs text-zinc-600">
The token in these URLs is your session JWT. Anyone with these URLs
can stream your channels.
</p>
</div>
</DialogContent>
</Dialog>
);
}