Add basic download support on the web

This commit is contained in:
Zoe Roux 2023-12-19 14:09:21 +01:00
parent 213d5b74b5
commit 883f39e4b5
4 changed files with 50 additions and 2 deletions

View File

@ -27,7 +27,7 @@ import Download from "@material-symbols/svg-400/rounded/download.svg";
import { WatchStatusV, queryFn, useAccount } from "@kyoo/models";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { watchListIcon } from "./watchlist-info";
import { useDownloader } from "../downloads/state";
import { useDownloader } from "../downloads";
import { Platform } from "react-native";
import { useYoshiki } from "yoshiki/native";

View File

@ -19,4 +19,4 @@
*/
export { DownloadPage } from "./page";
export { DownloadProvider } from "./state";
export { DownloadProvider, useDownloader } from "./state";

View File

@ -0,0 +1,48 @@
/*
* Kyoo - A portable and vast media library solution.
* Copyright (c) Kyoo.
*
* See AUTHORS.md and LICENSE file in the project root for full license information.
*
* Kyoo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Kyoo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
*/
import { WatchInfo, kyooApiUrl, queryFn, toQueryKey } from "@kyoo/models";
import { Player } from "../player";
import { getCurrentAccount } from "@kyoo/models/src/account-internal";
export const useDownloader = () => {
return async (type: "episode" | "movie", slug: string) => {
const account = getCurrentAccount();
const query = Player.infoQuery(type, slug);
const info: WatchInfo = await queryFn(
{
queryKey: toQueryKey(query),
signal: undefined as any,
meta: undefined,
apiUrl: account?.apiUrl,
},
query.parser,
account?.token.access_token,
);
// TODO: This methods does not work with auth.
const a = document.createElement("a");
a.style.display = "none";
a.href = `${kyooApiUrl}/video/${type}/${slug}/direct`;
a.download = `${slug}.${info.extension}`;
document.body.appendChild(a);
a.click();
};
};