mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-06-09 23:48:41 +01:00
Some checks failed
🏗️ Build Apps / 🤖 Build Android APK (Phone) (push) Has been cancelled
🏗️ Build Apps / 🤖 Build Android APK (TV) (push) Has been cancelled
🏗️ Build Apps / 🍎 Build iOS IPA (Phone) (push) Has been cancelled
🏗️ Build Apps / 🍎 Build iOS IPA (Phone - Unsigned) (push) Has been cancelled
🏗️ Build Apps / 🍎 Build tvOS IPA (push) Has been cancelled
🏗️ Build Apps / 🍎 Build tvOS IPA (Unsigned) (push) Has been cancelled
🔒 Lockfile Consistency Check / 🔍 Check bun.lock and package.json consistency (push) Has been cancelled
🛡️ CodeQL Analysis / 🔎 Analyze with CodeQL (actions) (push) Has been cancelled
🛡️ CodeQL Analysis / 🔎 Analyze with CodeQL (javascript-typescript) (push) Has been cancelled
🏷️🔀Merge Conflict Labeler / 🏷️ Labeling Merge Conflicts (push) Has been cancelled
🌐 Translation Sync / sync-translations (push) Has been cancelled
🚦 Security & Quality Gate / 📝 Validate PR Title (push) Has been cancelled
🚦 Security & Quality Gate / 🔍 Vulnerable Dependencies (push) Has been cancelled
🚦 Security & Quality Gate / 🚑 Expo Doctor Check (push) Has been cancelled
🚦 Security & Quality Gate / 🔍 Lint & Test (check) (push) Has been cancelled
🚦 Security & Quality Gate / 🔍 Lint & Test (format) (push) Has been cancelled
🚦 Security & Quality Gate / 🔍 Lint & Test (lint) (push) Has been cancelled
🚦 Security & Quality Gate / 🔍 Lint & Test (typecheck) (push) Has been cancelled
🛡️ Trivy Security Scan / 🔎 Filesystem scan (push) Has been cancelled
Co-authored-by: lance chant <13349722+lancechant@users.noreply.github.com> Co-authored-by: Gauvain <contact@uruk.dev>
75 lines
1.8 KiB
TypeScript
75 lines
1.8 KiB
TypeScript
import type { Api } from "@jellyfin/sdk";
|
|
import type {
|
|
BaseItemDto,
|
|
MediaSourceInfo,
|
|
} from "@jellyfin/sdk/lib/generated-client/models";
|
|
import { Bitrate } from "@/components/BitrateSelector";
|
|
import {
|
|
type AudioTranscodeModeType,
|
|
generateDeviceProfile,
|
|
} from "../../profiles/native";
|
|
import { getDownloadStreamUrl, getStreamUrl } from "./getStreamUrl";
|
|
|
|
export const getDownloadUrl = async ({
|
|
api,
|
|
item,
|
|
userId,
|
|
mediaSource,
|
|
maxBitrate,
|
|
audioStreamIndex,
|
|
subtitleStreamIndex,
|
|
deviceId,
|
|
audioMode = "auto",
|
|
}: {
|
|
api: Api;
|
|
item: BaseItemDto;
|
|
userId: string;
|
|
mediaSource: MediaSourceInfo;
|
|
maxBitrate: Bitrate;
|
|
audioStreamIndex: number;
|
|
subtitleStreamIndex: number;
|
|
deviceId: string;
|
|
audioMode?: AudioTranscodeModeType;
|
|
}): Promise<{
|
|
url: string | null;
|
|
mediaSource: MediaSourceInfo | null;
|
|
} | null> => {
|
|
const streamDetails = await getStreamUrl({
|
|
api,
|
|
item,
|
|
userId,
|
|
startTimeTicks: 0,
|
|
mediaSourceId: mediaSource.Id,
|
|
maxStreamingBitrate: maxBitrate.value,
|
|
audioStreamIndex,
|
|
subtitleStreamIndex,
|
|
deviceId,
|
|
deviceProfile: generateDeviceProfile({ audioMode }),
|
|
});
|
|
|
|
if (maxBitrate.key === "Max" && !streamDetails?.mediaSource?.TranscodingUrl) {
|
|
console.log("Downloading item directly");
|
|
return {
|
|
url: `${api.basePath}/Items/${mediaSource.Id}/Download?api_key=${api.accessToken}`,
|
|
mediaSource: streamDetails?.mediaSource ?? null,
|
|
};
|
|
}
|
|
|
|
const downloadStreamDetails = await getDownloadStreamUrl({
|
|
api,
|
|
item,
|
|
userId,
|
|
mediaSourceId: mediaSource.Id,
|
|
deviceId,
|
|
maxStreamingBitrate: maxBitrate.value,
|
|
audioStreamIndex,
|
|
subtitleStreamIndex,
|
|
audioMode,
|
|
});
|
|
|
|
return {
|
|
url: downloadStreamDetails?.url ?? null,
|
|
mediaSource: downloadStreamDetails?.mediaSource ?? null,
|
|
};
|
|
};
|