/* eslint-disable camelcase */ import useSWR from "swr"; import { useTranslation } from "next-i18next"; import { BsFillPlayFill, BsPauseFill, BsCpu, BsFillCpuFill } from "react-icons/bs"; import { MdOutlineSmartDisplay, MdSmartDisplay } from "react-icons/md"; import Widget from "components/services/widgets/widget"; import { formatProxyUrl } from "utils/api-helpers"; function millisecondsToTime(milliseconds) { const seconds = Math.floor((milliseconds / 1000) % 60); const minutes = Math.floor((milliseconds / (1000 * 60)) % 60); const hours = Math.floor((milliseconds / (1000 * 60 * 60)) % 24); return { hours, minutes, seconds }; } function millisecondsToString(milliseconds) { const { hours, minutes, seconds } = millisecondsToTime(milliseconds); const parts = []; if (hours > 0) { parts.push(hours); } parts.push(minutes); parts.push(seconds); return parts.map((part) => part.toString().padStart(2, "0")).join(":"); } function SingleSessionEntry({ session }) { const { full_title, duration, view_offset, progress_percent, state, video_decision, audio_decision } = session; return ( <>
{full_title}
{video_decision === "direct play" && audio_decision === "direct play" && ( )} {video_decision === "copy" && audio_decision === "copy" && } {video_decision !== "copy" && video_decision !== "direct play" && (audio_decision !== "copy" || audio_decision !== "direct play") && } {(video_decision === "copy" || video_decision === "direct play") && audio_decision !== "copy" && audio_decision !== "direct play" && }
{state === "paused" && ( )} {state !== "paused" && ( )}
{millisecondsToString(view_offset)} / {millisecondsToString(duration)}
); } function SessionEntry({ session }) { const { full_title, view_offset, progress_percent, state, video_decision, audio_decision } = session; return (
{state === "paused" && ( )} {state !== "paused" && ( )}
{full_title}
{video_decision === "direct play" && audio_decision === "direct play" && ( )} {video_decision === "copy" && audio_decision === "copy" && } {video_decision !== "copy" && video_decision !== "direct play" && (audio_decision !== "copy" || audio_decision !== "direct play") && } {(video_decision === "copy" || video_decision === "direct play") && audio_decision !== "copy" && audio_decision !== "direct play" && }
{millisecondsToString(view_offset)}
); } export default function Component({ service }) { const { t } = useTranslation(); const config = service.widget; const { data: activityData, error: activityError } = useSWR(formatProxyUrl(config, "get_activity"), { refreshInterval: 5000, }); if (activityError) { return ; } if (!activityData) { return (
-
-
); } const playing = activityData.response.data.sessions.sort((a, b) => { if (a.view_offset > b.view_offset) { return 1; } if (a.view_offset < b.view_offset) { return -1; } return 0; }); if (playing.length === 0) { return (
{t("tautulli.no_active")}
-
); } if (playing.length === 1) { const session = playing[0]; return (
); } return (
{playing.map((session) => ( ))}
); }