mirror of
https://github.com/streamyfin/streamyfin.git
synced 2025-08-20 18:37:18 +02:00
refactor: getstreamurl
This commit is contained in:
@@ -44,84 +44,43 @@ export const getStreamUrl = async ({
|
|||||||
let mediaSource: MediaSourceInfo | undefined;
|
let mediaSource: MediaSourceInfo | undefined;
|
||||||
let sessionId: string | null | undefined;
|
let sessionId: string | null | undefined;
|
||||||
|
|
||||||
if (item.Type === "Program") {
|
const res = await getMediaInfoApi(api).getPlaybackInfo(
|
||||||
console.log("Item is of type program...");
|
|
||||||
const res0 = await getMediaInfoApi(api).getPlaybackInfo(
|
|
||||||
{
|
|
||||||
userId,
|
|
||||||
itemId: item.ChannelId!,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
method: "POST",
|
|
||||||
params: {
|
|
||||||
startTimeTicks: 0,
|
|
||||||
isPlayback: true,
|
|
||||||
autoOpenLiveStream: true,
|
|
||||||
maxStreamingBitrate,
|
|
||||||
audioStreamIndex,
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
deviceProfile,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
const transcodeUrl = res0.data.MediaSources?.[0].TranscodingUrl;
|
|
||||||
sessionId = res0.data.PlaySessionId || null;
|
|
||||||
|
|
||||||
if (transcodeUrl) {
|
|
||||||
return {
|
|
||||||
url: `${api.basePath}${transcodeUrl}`,
|
|
||||||
sessionId,
|
|
||||||
mediaSource: res0.data.MediaSources?.[0],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const itemId = item.Id;
|
|
||||||
|
|
||||||
const res2 = await getMediaInfoApi(api).getPlaybackInfo(
|
|
||||||
{
|
{
|
||||||
itemId: item.Id!,
|
itemId: item.Id!,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
data: {
|
data: {
|
||||||
deviceProfile,
|
|
||||||
userId,
|
userId,
|
||||||
maxStreamingBitrate,
|
deviceProfile,
|
||||||
startTimeTicks,
|
|
||||||
autoOpenLiveStream: true,
|
|
||||||
mediaSourceId,
|
|
||||||
audioStreamIndex,
|
|
||||||
subtitleStreamIndex,
|
subtitleStreamIndex,
|
||||||
|
startTimeTicks,
|
||||||
|
isPlayback: true,
|
||||||
|
autoOpenLiveStream: true,
|
||||||
|
maxStreamingBitrate,
|
||||||
|
audioStreamIndex,
|
||||||
|
mediaSourceId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (res2.status !== 200) {
|
if (res.status !== 200) {
|
||||||
console.error("Error getting playback info:", res2.status, res2.statusText);
|
console.error("Error getting playback info:", res.status, res.statusText);
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionId = res2.data.PlaySessionId || null;
|
sessionId = res.data.PlaySessionId || null;
|
||||||
|
mediaSource = res.data.MediaSources[0];
|
||||||
|
const transcodeUrl = mediaSource.TranscodingUrl;
|
||||||
|
|
||||||
mediaSource = res2.data.MediaSources?.find(
|
if (transcodeUrl) {
|
||||||
(source: MediaSourceInfo) => source.Id === mediaSourceId,
|
console.log("Video is being transcoded:", transcodeUrl);
|
||||||
);
|
|
||||||
|
|
||||||
if (item.MediaType === "Video") {
|
|
||||||
if (mediaSource?.TranscodingUrl) {
|
|
||||||
const urlObj = new URL(api.basePath + mediaSource?.TranscodingUrl); // Create a URL object
|
|
||||||
|
|
||||||
// Get the updated URL
|
|
||||||
const transcodeUrl = urlObj.toString();
|
|
||||||
|
|
||||||
console.log("Video has transcoding URL:", `${transcodeUrl}`);
|
|
||||||
return {
|
return {
|
||||||
url: transcodeUrl,
|
url: `${api.basePath}${transcodeUrl}`,
|
||||||
sessionId: sessionId,
|
sessionId,
|
||||||
mediaSource,
|
mediaSource,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchParams = new URLSearchParams({
|
const searchParams = new URLSearchParams({
|
||||||
playSessionId: sessionData?.PlaySessionId || "",
|
playSessionId: sessionData?.PlaySessionId || "",
|
||||||
mediaSourceId: mediaSource?.Id || "",
|
mediaSourceId: mediaSource?.Id || "",
|
||||||
@@ -137,7 +96,7 @@ export const getStreamUrl = async ({
|
|||||||
|
|
||||||
const directPlayUrl = `${
|
const directPlayUrl = `${
|
||||||
api.basePath
|
api.basePath
|
||||||
}/Videos/${itemId}/stream.mp4?${searchParams.toString()}`;
|
}/Videos/${item.Id}/stream.mp4?${searchParams.toString()}`;
|
||||||
|
|
||||||
console.log("Video is being direct played:", directPlayUrl);
|
console.log("Video is being direct played:", directPlayUrl);
|
||||||
|
|
||||||
@@ -146,9 +105,4 @@ export const getStreamUrl = async ({
|
|||||||
sessionId: sessionId,
|
sessionId: sessionId,
|
||||||
mediaSource,
|
mediaSource,
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
Alert.alert("Error", "Could not play this item");
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user