/* eslint-disable camelcase */ import { useTranslation } from "next-i18next"; import { BsFillPlayFill, BsPauseFill, BsCpu, BsFillCpuFill } from "react-icons/bs"; import { MdOutlineSmartDisplay, MdSmartDisplay } from "react-icons/md"; import Container from "components/services/widget/container"; import useWidgetAPI from "utils/proxy/use-widget-api"; 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 generateStreamTitle(session, showEpisodeNumber) { const { media_type, parent_media_index, media_index, title, grandparent_title, full_title } = session; if (media_type === "episode" && showEpisodeNumber) { return `${grandparent_title}: S${parent_media_index.toString().padStart(2, "0")} ยท E${media_index.toString().padStart(2, "0")} - ${title}`; } return full_title; } function SingleSessionEntry({ session, enableUser, showEpisodeNumber }) { const { duration, view_offset, progress_percent, state, video_decision, audio_decision, username } = session; const stream_title = generateStreamTitle(session, showEpisodeNumber) return ( <>
{stream_title} {enableUser && ` (${username})`}
{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, enableUser, showEpisodeNumber }) { const { view_offset, progress_percent, state, video_decision, audio_decision, username } = session; const stream_title = generateStreamTitle(session, showEpisodeNumber) return (
{state === "paused" && ( )} {state !== "paused" && ( )}
{stream_title} {enableUser && ` (${username})`}
{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 { widget } = service; const { data: activityData, error: activityError } = useWidgetAPI(widget, "get_activity", { refreshInterval: 5000, }); if (activityError || (activityData && Object.keys(activityData.response.data).length === 0)) { 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; }); const enableUser = !!service.widget?.enableUser; // default is false const expandOneStreamToTwoRows = service.widget?.expandOneStreamToTwoRows !== false; // default is true const showEpisodeNumber = !!service.widget?.showEpisodeNumber; // default is false if (playing.length === 0) { return (
{t("tautulli.no_active")}
{expandOneStreamToTwoRows && (
-
)}
); } if (expandOneStreamToTwoRows && playing.length === 1) { const session = playing[0]; return (
); } return (
{playing.map((session) => ( ))}
); }