Skip to content

Commit

Permalink
fix: rename from delivery/domand to dmc/dms
Browse files Browse the repository at this point in the history
  • Loading branch information
xpadev-net committed Nov 22, 2023
1 parent e88339f commit 0ba920c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 55 deletions.
2 changes: 1 addition & 1 deletion electron/lib/niconico/dmc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const downloadDMC = async (
sendMessageToController({
title: "動画情報の取得に失敗しました",
message:
"DMCサーバー上に動画が見つかりませんでした\nDomandサーバーからの取得を試してみてください\nlib/niconico/dmc.ts / downloadDMC / invalid server",
"DMC上に動画が見つかりませんでした\nDMSからの取得を試してみてください\nlib/niconico/dmc.ts / downloadDMC / invalid server",
type: "message",
});
return;
Expand Down
20 changes: 9 additions & 11 deletions src/@types/niconico.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ export type TWatchV3Metadata<T extends "dmc" | "dms" | "" = ""> = {
comment: V3MetadataComment;
media: {
delivery: T extends "dmc"
? V3MetadataDeliveryMedia
: V3MetadataDeliveryMedia | null;
domand: T extends "dms"
? V3MetadataDomandMedia
: V3MetadataDomandMedia | null;
? V3MetadataDMCMedia
: V3MetadataDMCMedia | null;
domand: T extends "dms" ? V3MetadataDMSMedia : V3MetadataDMSMedia | null;
};
video: {
id: string;
Expand Down Expand Up @@ -70,7 +68,7 @@ export type V3MetadataVideoItem = {
};
};

export type V3MetadataDeliveryMedia = {
export type V3MetadataDMCMedia = {
recipeId: string;
encryption: null | {
encryptedKey: string;
Expand Down Expand Up @@ -106,13 +104,13 @@ export type V3MetadataDeliveryMedia = {
trackingId: string;
};

export type V3MetadataDomandMedia = {
videos: V3MetadataDomandVideoItem[];
audios: V3MetadataDomandAudioItem[];
export type V3MetadataDMSMedia = {
videos: V3MetadataDMSVideoItem[];
audios: V3MetadataDMSAudioItem[];
accessRightKey: string;
};

export type V3MetadataDomandVideoItem = {
export type V3MetadataDMSVideoItem = {
id: string;
isAvailable: boolean;
label: string;
Expand All @@ -123,7 +121,7 @@ export type V3MetadataDomandVideoItem = {
recommendedHighestAudioQualityLevel: number;
};

export type V3MetadataDomandAudioItem = {
export type V3MetadataDMSAudioItem = {
id: string;
isAvailable: boolean;
bitRate: number;
Expand Down
14 changes: 7 additions & 7 deletions src/controller/movie-picker/remote/dmc/dmc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import type { TWatchV3Metadata } from "@/@types/niconico";
import type { TDMCFormat } from "@/@types/queue";
import { SelectField } from "@/components/SelectField";
import Styles from "@/controller/movie/movie.module.scss";
import { getDeliveryBestSegment } from "@/util/niconico";
import { getDMCBestSegment } from "@/util/niconico";

type Props = {
metadata: TWatchV3Metadata<"dmc">;
onChange: (val: TDMCFormat | undefined) => void;
};

const DeliveryMoviePicker: FC<Props> = ({ metadata, onChange }) => {
const DMCMoviePicker: FC<Props> = ({ metadata, onChange }) => {
const [selectedVideo, setSelectedVideo] = useState<string>("");
const [selectedAudio, setSelectedAudio] = useState<string>("");
useEffect(() => {
setSelectedAudio(
getDeliveryBestSegment(metadata.data.media.delivery.movie.audios).id,
getDMCBestSegment(metadata.data.media.delivery.movie.audios).id,
);
setSelectedVideo(
getDeliveryBestSegment(metadata.data.media.delivery.movie.videos).id,
getDMCBestSegment(metadata.data.media.delivery.movie.videos).id,
);
}, [metadata]);
useEffect(() => {
Expand All @@ -41,7 +41,7 @@ const DeliveryMoviePicker: FC<Props> = ({ metadata, onChange }) => {
variant={"standard"}
value={selectedVideo}
defaultValue={
getDeliveryBestSegment(metadata.data.media.delivery.movie.videos).id
getDMCBestSegment(metadata.data.media.delivery.movie.videos).id
}
className={Styles.input}
onChange={(e) => setSelectedVideo(e.target.value)}
Expand All @@ -62,7 +62,7 @@ const DeliveryMoviePicker: FC<Props> = ({ metadata, onChange }) => {
variant={"standard"}
className={Styles.input}
defaultValue={
getDeliveryBestSegment(metadata.data.media.delivery.movie.audios).id
getDMCBestSegment(metadata.data.media.delivery.movie.audios).id
}
value={selectedAudio}
onChange={(e) => setSelectedAudio(e.target.value)}
Expand All @@ -80,4 +80,4 @@ const DeliveryMoviePicker: FC<Props> = ({ metadata, onChange }) => {
);
};

export { DeliveryMoviePicker };
export { DMCMoviePicker };
22 changes: 7 additions & 15 deletions src/controller/movie-picker/remote/dms/dms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@ import type { TWatchV3Metadata } from "@/@types/niconico";
import type { TDMSFormat } from "@/@types/queue";
import { SelectField } from "@/components/SelectField";
import Styles from "@/controller/movie/movie.module.scss";
import { getDomandBestSegment } from "@/util/niconico";
import { getDMSBestSegment } from "@/util/niconico";

type Props = {
metadata: TWatchV3Metadata<"dms">;
onChange: (val: TDMSFormat | undefined) => void;
};

const DomandMoviePicker: FC<Props> = ({ metadata, onChange }) => {
const DMSMoviePicker: FC<Props> = ({ metadata, onChange }) => {
const [selectedVideo, setSelectedVideo] = useState<string>("");
const [selectedAudio, setSelectedAudio] = useState<string>("");
useEffect(() => {
setSelectedAudio(
getDomandBestSegment(metadata.data.media.domand.audios).id,
);
setSelectedVideo(
getDomandBestSegment(metadata.data.media.domand.videos).id,
);
setSelectedAudio(getDMSBestSegment(metadata.data.media.domand.audios).id);
setSelectedVideo(getDMSBestSegment(metadata.data.media.domand.videos).id);
}, [metadata]);

useEffect(() => {
Expand All @@ -38,9 +34,7 @@ const DomandMoviePicker: FC<Props> = ({ metadata, onChange }) => {
label={"動画"}
variant={"standard"}
value={selectedVideo}
defaultValue={
getDomandBestSegment(metadata.data.media.domand.videos).id
}
defaultValue={getDMSBestSegment(metadata.data.media.domand.videos).id}
className={Styles.input}
onChange={(e) => setSelectedVideo(e.target.value)}
>
Expand All @@ -59,9 +53,7 @@ const DomandMoviePicker: FC<Props> = ({ metadata, onChange }) => {
label={"音声"}
variant={"standard"}
className={Styles.input}
defaultValue={
getDomandBestSegment(metadata.data.media.domand.audios).id
}
defaultValue={getDMSBestSegment(metadata.data.media.domand.audios).id}
value={selectedAudio}
onChange={(e) => setSelectedAudio(e.target.value)}
>
Expand All @@ -78,4 +70,4 @@ const DomandMoviePicker: FC<Props> = ({ metadata, onChange }) => {
);
};

export { DomandMoviePicker };
export { DMSMoviePicker };
16 changes: 8 additions & 8 deletions src/controller/movie-picker/remote/remote-movie-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Button from "@mui/material/Button";
import { useSetAtom } from "jotai";
import type { ChangeEvent, FC } from "react";
import { useState } from "react";
import { DeliveryMoviePicker } from "src/controller/movie-picker/remote/dmc";
import { DomandMoviePicker } from "src/controller/movie-picker/remote/dms";
import { DMCMoviePicker } from "src/controller/movie-picker/remote/dmc";
import { DMSMoviePicker } from "src/controller/movie-picker/remote/dms";

import type { TWatchV3Metadata } from "@/@types/niconico";
import type { TMovieItemRemote, TRemoteMovieItemFormat } from "@/@types/queue";
Expand Down Expand Up @@ -134,23 +134,23 @@ const RemoteMoviePicker: FC<Props> = ({ onChange }) => {
row
>
<FormControlLabel
value={"delivery"}
value={"dmc"}
control={<Radio />}
label={"delivery"}
label={"DMC"}
disabled={!metadata.data.media.delivery}
/>
<FormControlLabel
value={"domand"}
value={"dms"}
control={<Radio />}
disabled={!metadata.data.media.domand}
label={"domand"}
label={"DMS"}
/>
</RadioGroup>
{mediaServer === "dmc" && typeGuard.controller.v3DMC(metadata) && (
<DeliveryMoviePicker metadata={metadata} onChange={setFormat} />
<DMCMoviePicker metadata={metadata} onChange={setFormat} />
)}
{mediaServer === "dms" && typeGuard.controller.v3DMS(metadata) && (
<DomandMoviePicker metadata={metadata} onChange={setFormat} />
<DMSMoviePicker metadata={metadata} onChange={setFormat} />
)}
<Button variant={"outlined"} onClick={onClick}>
確定
Expand Down
21 changes: 8 additions & 13 deletions src/util/niconico.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { NicoId } from "@/@types/brand";
import type {
V3MetadataAudioItem,
V3MetadataDomandAudioItem,
V3MetadataDomandVideoItem,
V3MetadataDMSAudioItem,
V3MetadataDMSVideoItem,
V3MetadataVideoItem,
} from "@/@types/niconico";

Expand All @@ -19,9 +19,9 @@ const getNicoId = (url: string): NicoId | undefined => {
return match[1] as NicoId;
};

function getDeliveryBestSegment<
T extends V3MetadataAudioItem | V3MetadataVideoItem,
>(input: T[]): T {
function getDMCBestSegment<T extends V3MetadataAudioItem | V3MetadataVideoItem>(
input: T[],
): T {
let bestItem = input[0];
for (const item of input) {
if (!item.isAvailable) continue;
Expand All @@ -32,8 +32,8 @@ function getDeliveryBestSegment<
return bestItem;
}

const getDomandBestSegment = <
T extends V3MetadataDomandAudioItem | V3MetadataDomandVideoItem,
const getDMSBestSegment = <
T extends V3MetadataDMSAudioItem | V3MetadataDMSVideoItem,
>(
input: T[],
): T => {
Expand All @@ -47,9 +47,4 @@ const getDomandBestSegment = <
return bestItem;
};

export {
getDeliveryBestSegment,
getDomandBestSegment,
getNicoId,
isNicovideoUrl,
};
export { getDMCBestSegment, getDMSBestSegment, getNicoId, isNicovideoUrl };

0 comments on commit 0ba920c

Please sign in to comment.