mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-06-01 03:28:27 +01:00
wip
This commit is contained in:
@@ -70,28 +70,28 @@ const downloads: React.FC = () => {
|
|||||||
if (info.exists) {
|
if (info.exists) {
|
||||||
if (info.isDirectory) {
|
if (info.isDirectory) {
|
||||||
// List items in the directory
|
// List items in the directory
|
||||||
const subItems = await FileSystem.readDirectoryAsync(fullPath);
|
// const subItems = await FileSystem.readDirectoryAsync(fullPath);
|
||||||
if (subItems.length === 0) {
|
// if (subItems.length === 0) {
|
||||||
console.log(`Directory ${item} is empty.`);
|
// console.log(`Directory ${item} is empty.`);
|
||||||
} else {
|
// } else {
|
||||||
console.log(`Items in ${item}:`, subItems);
|
// console.log(`Items in ${item}:`, subItems);
|
||||||
// If item ends in m3u8, print the content of the file
|
// // If item ends in m3u8, print the content of the file
|
||||||
const m3u8Files = subItems.filter((subItem) =>
|
// const m3u8Files = subItems.filter((subItem) =>
|
||||||
subItem.endsWith(".m3u8")
|
// subItem.endsWith(".m3u8")
|
||||||
);
|
// );
|
||||||
if (m3u8Files.length === 0) {
|
// if (m3u8Files.length === 0) {
|
||||||
console.log(`No .m3u8 files found in ${item}.`);
|
// console.log(`No .m3u8 files found in ${item}.`);
|
||||||
} else {
|
// } else {
|
||||||
for (let subItem of m3u8Files) {
|
// for (let subItem of m3u8Files) {
|
||||||
console.log(
|
// console.log(
|
||||||
`Content of ${subItem}:`,
|
// `Content of ${subItem}:`,
|
||||||
await FileSystem.readAsStringAsync(
|
// await FileSystem.readAsStringAsync(
|
||||||
`${fullPath}/${subItem}`
|
// `${fullPath}/${subItem}`
|
||||||
)
|
// )
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
} else {
|
} else {
|
||||||
console.log(`${item} is a file`);
|
console.log(`${item} is a file`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import { MediaSourceSelector } from "./MediaSourceSelector";
|
|||||||
import ProgressCircle from "./ProgressCircle";
|
import ProgressCircle from "./ProgressCircle";
|
||||||
import { SubtitleTrackSelector } from "./SubtitleTrackSelector";
|
import { SubtitleTrackSelector } from "./SubtitleTrackSelector";
|
||||||
import { useDownloadM3U8Files } from "@/hooks/useDownloadM3U8Files";
|
import { useDownloadM3U8Files } from "@/hooks/useDownloadM3U8Files";
|
||||||
|
import * as FileSystem from "expo-file-system";
|
||||||
|
|
||||||
interface DownloadProps extends ViewProps {
|
interface DownloadProps extends ViewProps {
|
||||||
item: BaseItemDto;
|
item: BaseItemDto;
|
||||||
@@ -45,8 +46,7 @@ export const DownloadItem: React.FC<DownloadProps> = ({ item, ...props }) => {
|
|||||||
const [settings] = useSettings();
|
const [settings] = useSettings();
|
||||||
// const { startRemuxing } = useRemuxHlsToMp4(item);
|
// const { startRemuxing } = useRemuxHlsToMp4(item);
|
||||||
|
|
||||||
const { cancelDownload, startBackgroundDownload } =
|
const { startBackgroundDownload } = useDownloadM3U8Files(item);
|
||||||
useDownloadM3U8Files(item);
|
|
||||||
|
|
||||||
const [selectedMediaSource, setSelectedMediaSource] =
|
const [selectedMediaSource, setSelectedMediaSource] =
|
||||||
useState<MediaSourceInfo | null>(null);
|
useState<MediaSourceInfo | null>(null);
|
||||||
@@ -175,13 +175,36 @@ export const DownloadItem: React.FC<DownloadProps> = ({ item, ...props }) => {
|
|||||||
const { data: downloaded, isFetching } = useQuery({
|
const { data: downloaded, isFetching } = useQuery({
|
||||||
queryKey: ["downloaded", item.Id],
|
queryKey: ["downloaded", item.Id],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
if (!item.Id) return false;
|
if (!item.Id) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const data: BaseItemDto[] = JSON.parse(
|
try {
|
||||||
(await AsyncStorage.getItem("downloaded_files")) || "[]"
|
// Check if the item exists in AsyncStorage
|
||||||
);
|
const downloadedItems = await AsyncStorage.getItem("downloadedItems");
|
||||||
|
const items: BaseItemDto[] = downloadedItems
|
||||||
|
? JSON.parse(downloadedItems)
|
||||||
|
: [];
|
||||||
|
const isInStorage = items.some(
|
||||||
|
(storedItem) => storedItem.Id === item.Id
|
||||||
|
);
|
||||||
|
|
||||||
return data.some((d) => d.Id === item.Id);
|
if (!isInStorage) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the directory and m3u8 file exist
|
||||||
|
const directoryPath = `${FileSystem.documentDirectory}${item.Id}`;
|
||||||
|
const m3u8FilePath = `${directoryPath}/local.m3u8`;
|
||||||
|
|
||||||
|
const dirInfo = await FileSystem.getInfoAsync(directoryPath);
|
||||||
|
const fileInfo = await FileSystem.getInfoAsync(m3u8FilePath);
|
||||||
|
|
||||||
|
return dirInfo.exists && fileInfo.exists;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error checking download status:", error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
enabled: !!item.Id,
|
enabled: !!item.Id,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,9 +28,18 @@ export const EpisodeCard: React.FC<EpisodeCardProps> = ({ item }) => {
|
|||||||
const { startDownloadedFilePlayback } = usePlayback();
|
const { startDownloadedFilePlayback } = usePlayback();
|
||||||
|
|
||||||
const handleOpenFile = useCallback(async () => {
|
const handleOpenFile = useCallback(async () => {
|
||||||
|
const url = `${FileSystem.documentDirectory}${item.Id}/0.ts`;
|
||||||
|
console.log(url);
|
||||||
|
|
||||||
|
const fileInfo = await FileSystem.getInfoAsync(url);
|
||||||
|
|
||||||
|
if (!fileInfo.exists) {
|
||||||
|
console.warn("m3u8 file does not exist:", url);
|
||||||
|
}
|
||||||
|
|
||||||
startDownloadedFilePlayback({
|
startDownloadedFilePlayback({
|
||||||
item,
|
item,
|
||||||
url: `${FileSystem.documentDirectory}/${item.Id}.mp4`,
|
url,
|
||||||
});
|
});
|
||||||
router.push("/play");
|
router.push("/play");
|
||||||
}, [item, startDownloadedFilePlayback]);
|
}, [item, startDownloadedFilePlayback]);
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ async function createLocalM3U8File(segments: Segment[], directoryPath: string) {
|
|||||||
localM3U8Content += "#EXT-X-MEDIA-SEQUENCE:0\n";
|
localM3U8Content += "#EXT-X-MEDIA-SEQUENCE:0\n";
|
||||||
|
|
||||||
segments.forEach((segment, index) => {
|
segments.forEach((segment, index) => {
|
||||||
|
console.log(segment.path.split(".")[1]);
|
||||||
localM3U8Content += `#EXTINF:${segment.duration.toFixed(3)},\n`;
|
localM3U8Content += `#EXTINF:${segment.duration.toFixed(3)},\n`;
|
||||||
localM3U8Content += `${directoryPath}/${index}.ts\n`;
|
localM3U8Content += `${directoryPath}/${index}.ts\n`;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user