Spaces:
Paused
Paused
Update use-cases/stream.js
Browse files- use-cases/stream.js +33 -20
use-cases/stream.js
CHANGED
|
@@ -1,38 +1,51 @@
|
|
| 1 |
const Stream = (dependencies) => {
|
| 2 |
-
const { httpClient, env } = dependencies
|
| 3 |
|
| 4 |
const getStreams = async (request) => {
|
| 5 |
-
const { id } = request
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
//
|
| 13 |
const extractStreams = ({ id, result }) => {
|
| 14 |
-
const streams = []
|
| 15 |
-
const subtitles = []
|
| 16 |
|
| 17 |
for (const file of result) {
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
}
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
}
|
| 25 |
}
|
| 26 |
|
| 27 |
-
return {
|
| 28 |
-
|
| 29 |
-
subtitles,
|
| 30 |
-
}
|
| 31 |
-
}
|
| 32 |
|
| 33 |
return {
|
| 34 |
getStreams,
|
| 35 |
-
}
|
| 36 |
-
}
|
| 37 |
|
| 38 |
-
module.exports = Stream
|
|
|
|
| 1 |
const Stream = (dependencies) => {
|
| 2 |
+
const { httpClient, env } = dependencies;
|
| 3 |
|
| 4 |
const getStreams = async (request) => {
|
| 5 |
+
const { id } = request;
|
| 6 |
|
| 7 |
+
try {
|
| 8 |
+
// Fetch file list from Archive.org for the specific item
|
| 9 |
+
const response = await httpClient.get(`${env.url.metadata}/${id}/files`);
|
| 10 |
+
const streams = extractStreams({ id, result: response.data.files });
|
| 11 |
|
| 12 |
+
return streams;
|
| 13 |
+
} catch (error) {
|
| 14 |
+
console.error("Error in getStreams:", error.message);
|
| 15 |
+
return { streams: [], subtitles: [] };
|
| 16 |
+
}
|
| 17 |
+
};
|
| 18 |
|
| 19 |
+
// Filters and formats the streams and subtitles
|
| 20 |
const extractStreams = ({ id, result }) => {
|
| 21 |
+
const streams = [];
|
| 22 |
+
const subtitles = [];
|
| 23 |
|
| 24 |
for (const file of result) {
|
| 25 |
+
// Identify supported video streams (e.g., .mp4)
|
| 26 |
+
if (file.format === 'h.264' && file.name.endsWith('.mp4')) {
|
| 27 |
+
streams.push({
|
| 28 |
+
title: "Watch Now",
|
| 29 |
+
url: `${env.url.stream}/${id}/${file.name}`,
|
| 30 |
+
});
|
| 31 |
}
|
| 32 |
|
| 33 |
+
// Identify subtitle files (e.g., .srt)
|
| 34 |
+
if (file.name.endsWith('.srt')) {
|
| 35 |
+
subtitles.push({
|
| 36 |
+
id: file.name,
|
| 37 |
+
lang: file.language || "en",
|
| 38 |
+
url: `${env.url.stream}/${id}/${file.name}`,
|
| 39 |
+
});
|
| 40 |
}
|
| 41 |
}
|
| 42 |
|
| 43 |
+
return { streams, subtitles };
|
| 44 |
+
};
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
return {
|
| 47 |
getStreams,
|
| 48 |
+
};
|
| 49 |
+
};
|
| 50 |
|
| 51 |
+
module.exports = Stream;
|