From 404cd897f3b305ace80d6acba2ee5a76c642579e Mon Sep 17 00:00:00 2001 From: frost768 Date: Fri, 3 Mar 2023 19:33:30 +0300 Subject: [PATCH 01/12] feature: subtitle uploading --- src/backend/helpers/captions.ts | 16 ++++++ src/setup/locales/en/translation.json | 2 + .../popouts/CaptionSelectionPopout.tsx | 51 ++++++++++++++++++- src/video/components/popouts/PopoutUtils.tsx | 2 +- .../state/providers/castingStateProvider.ts | 3 ++ .../state/providers/videoStateProvider.ts | 3 ++ 6 files changed, 74 insertions(+), 3 deletions(-) diff --git a/src/backend/helpers/captions.ts b/src/backend/helpers/captions.ts index ca230fa9..61adbdc9 100644 --- a/src/backend/helpers/captions.ts +++ b/src/backend/helpers/captions.ts @@ -2,6 +2,7 @@ import { mwFetch, proxiedFetch } from "@/backend/helpers/fetch"; import { MWCaption, MWCaptionType } from "@/backend/helpers/streams"; import toWebVTT from "srt-webvtt"; +export const CUSTOM_CAPTION_ID = "customCaption"; export async function getCaptionUrl(caption: MWCaption): Promise { if (caption.type === MWCaptionType.SRT) { let captionBlob: Blob; @@ -32,3 +33,18 @@ export async function getCaptionUrl(caption: MWCaption): Promise { throw new Error("invalid type"); } + +export async function convertCustomCaptionFileToWebVTT(file: File) { + const header = await file.slice(0, 6).text(); + const isWebVTT = header === "WEBVTT"; + if (!isWebVTT) { + return toWebVTT(file); + } + return URL.createObjectURL(file); +} + +export function revokeCaptionBlob(url: string | undefined) { + if (url && url.startsWith("blob:")) { + URL.revokeObjectURL(url); + } +} diff --git a/src/setup/locales/en/translation.json b/src/setup/locales/en/translation.json index 5a3fe230..78832ad1 100644 --- a/src/setup/locales/en/translation.json +++ b/src/setup/locales/en/translation.json @@ -70,6 +70,8 @@ "episode": "E{{index}} - {{title}}", "noCaptions": "No captions", "linkedCaptions": "Linked captions", + "customCaption": "Custom caption", + "uploadCustomCaption": "Upload caption (SRT, VTT)", "noEmbeds": "No embeds were found for this source", "errors": { "loadingWentWong": "Something went wrong loading the episodes for {{seasonTitle}}", diff --git a/src/video/components/popouts/CaptionSelectionPopout.tsx b/src/video/components/popouts/CaptionSelectionPopout.tsx index e5ecdaeb..2b4bf0aa 100644 --- a/src/video/components/popouts/CaptionSelectionPopout.tsx +++ b/src/video/components/popouts/CaptionSelectionPopout.tsx @@ -1,4 +1,8 @@ -import { getCaptionUrl } from "@/backend/helpers/captions"; +import { + getCaptionUrl, + convertCustomCaptionFileToWebVTT, + CUSTOM_CAPTION_ID, +} from "@/backend/helpers/captions"; import { MWCaption } from "@/backend/helpers/streams"; import { Icon, Icons } from "@/components/Icon"; import { useLoading } from "@/hooks/useLoading"; @@ -6,7 +10,7 @@ import { useVideoPlayerDescriptor } from "@/video/state/hooks"; import { useControls } from "@/video/state/logic/controls"; import { useMeta } from "@/video/state/logic/meta"; import { useSource } from "@/video/state/logic/source"; -import { useMemo, useRef } from "react"; +import { ChangeEvent, useMemo, useRef } from "react"; import { useTranslation } from "react-i18next"; import { PopoutListEntry, PopoutSection } from "./PopoutUtils"; @@ -37,6 +41,29 @@ export function CaptionSelectionPopout() { ); const currentCaption = source.source?.caption?.id; + const customCaptionUploadElement = useRef(null); + const [setCustomCaption, loadingCustomCaption, errorCustomCaption] = + useLoading(async (captionFile: File) => { + if ( + !captionFile.name.endsWith(".srt") && + !captionFile.name.endsWith(".vtt") + ) { + throw new Error("Only SRT or VTT files are allowed"); + } + controls.setCaption( + CUSTOM_CAPTION_ID, + await convertCustomCaptionFileToWebVTT(captionFile) + ); + controls.closePopout(); + }); + + async function handleUploadCaption(e: ChangeEvent) { + if (!e.target.files) { + return; + } + const captionFile = e.target.files[0]; + setCustomCaption(captionFile); + } return ( <> @@ -54,6 +81,26 @@ export function CaptionSelectionPopout() { > {t("videoPlayer.popouts.noCaptions")} + { + customCaptionUploadElement.current?.click(); + }} + > + {currentCaption === CUSTOM_CAPTION_ID + ? t("videoPlayer.popouts.customCaption") + : t("videoPlayer.popouts.uploadCustomCaption")} + +

diff --git a/src/video/components/popouts/PopoutUtils.tsx b/src/video/components/popouts/PopoutUtils.tsx index 018afb20..be5b2b38 100644 --- a/src/video/components/popouts/PopoutUtils.tsx +++ b/src/video/components/popouts/PopoutUtils.tsx @@ -96,7 +96,7 @@ export function PopoutListEntry(props: PopoutListEntryTypes) { return (

Date: Thu, 9 Mar 2023 15:34:54 -0700 Subject: [PATCH 02/12] fix(netfilm): use different cdn --- .gitattributes | 1 + .vscode/settings.json | 3 +++ src/backend/providers/netfilm.ts | 20 ++++++++------------ 3 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..6313b56c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.vscode/settings.json b/.vscode/settings.json index 279011fe..a2b8691f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,8 @@ "eslint.format.enable": true, "[json]": { "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[typescript]": { + "editor.defaultFormatter": "vscode.typescript-language-features" } } diff --git a/src/backend/providers/netfilm.ts b/src/backend/providers/netfilm.ts index 777c77cd..e979f7b6 100644 --- a/src/backend/providers/netfilm.ts +++ b/src/backend/providers/netfilm.ts @@ -1,6 +1,6 @@ import { proxiedFetch } from "../helpers/fetch"; import { registerProvider } from "../helpers/register"; -import { MWStreamQuality, MWStreamType } from "../helpers/streams"; +import { MWCaptionType, MWStreamQuality, MWStreamType } from "../helpers/streams"; import { MWMediaType } from "../metadata/types"; const netfilmBase = "https://net-film.vercel.app"; @@ -18,7 +18,6 @@ registerProvider({ displayName: "NetFilm", rank: 15, type: [MWMediaType.MOVIE, MWMediaType.SERIES], - disabled: true, // https://github.com/lamhoang1256/netfilm/issues/25 async scrape({ media, episode, progress }) { // search for relevant item @@ -41,12 +40,9 @@ registerProvider({ // get stream info from media progress(75); - const watchInfo = await proxiedFetch( - `/api/episode?id=${netfilmId}`, - { - baseURL: netfilmBase, - } - ); + const watchInfo = await proxiedFetch(`/api/episode?id=${netfilmId}`, { + baseURL: netfilmBase, + }); const { qualities } = watchInfo.data; @@ -58,7 +54,7 @@ registerProvider({ return { embeds: [], stream: { - streamUrl: source.url, + streamUrl: source.url.replace("akm-cdn", "aws-cdn").replace("gg-cdn", "aws-cdn"), quality: qualityMap[source.quality as QualityInMap], type: MWStreamType.HLS, captions: [], @@ -109,17 +105,17 @@ registerProvider({ } ); - const { qualities } = episodeStream.data; + const data = episodeStream.data; // get best quality source - const source = qualities.reduce((p: any, c: any) => + const source = data.qualities.reduce((p: any, c: any) => c.quality > p.quality ? c : p ); return { embeds: [], stream: { - streamUrl: source.url, + streamUrl: source.url.replace("akm-cdn", "aws-cdn").replace("gg-cdn", "aws-cdn"), quality: qualityMap[source.quality as QualityInMap], type: MWStreamType.HLS, captions: [], From 25e32a14b749263f22d728912daf6900be9a8f3d Mon Sep 17 00:00:00 2001 From: cloud <62519659+lem6ns@users.noreply.github.com> Date: Thu, 9 Mar 2023 15:35:39 -0700 Subject: [PATCH 03/12] feat(netfilm): add captions --- src/backend/providers/netfilm.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/backend/providers/netfilm.ts b/src/backend/providers/netfilm.ts index e979f7b6..ff25fbf8 100644 --- a/src/backend/providers/netfilm.ts +++ b/src/backend/providers/netfilm.ts @@ -44,20 +44,27 @@ registerProvider({ baseURL: netfilmBase, }); - const { qualities } = watchInfo.data; + const data = watchInfo.data; // get best quality source - const source = qualities.reduce((p: any, c: any) => + const source = data.qualities.reduce((p: any, c: any) => c.quality > p.quality ? c : p ); + const mappedCaptions = data.subtitles.map((sub: Record) => ({ + needsProxy: false, + url: sub.url.replace("https://convert-srt-to-vtt.vercel.app/?url=", ""), + type: MWCaptionType.SRT, + langIso: sub.language, + })) + return { embeds: [], stream: { streamUrl: source.url.replace("akm-cdn", "aws-cdn").replace("gg-cdn", "aws-cdn"), quality: qualityMap[source.quality as QualityInMap], type: MWStreamType.HLS, - captions: [], + captions: mappedCaptions, }, }; } @@ -112,13 +119,20 @@ registerProvider({ c.quality > p.quality ? c : p ); + const mappedCaptions = data.subtitles.map((sub: Record) => ({ + needsProxy: false, + url: sub.url.replace("https://convert-srt-to-vtt.vercel.app/?url=", ""), + type: MWCaptionType.SRT, + langIso: sub.language, + })) + return { embeds: [], stream: { streamUrl: source.url.replace("akm-cdn", "aws-cdn").replace("gg-cdn", "aws-cdn"), quality: qualityMap[source.quality as QualityInMap], type: MWStreamType.HLS, - captions: [], + captions: mappedCaptions, }, }; }, From 5e97a195d9b99d9980416bb399624a78628331c5 Mon Sep 17 00:00:00 2001 From: cloud <62519659+lem6ns@users.noreply.github.com> Date: Thu, 9 Mar 2023 15:37:06 -0700 Subject: [PATCH 04/12] fix: vscode settings file --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index a2b8691f..279011fe 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,8 +4,5 @@ "eslint.format.enable": true, "[json]": { "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "[typescript]": { - "editor.defaultFormatter": "vscode.typescript-language-features" } } From 6b9774a210aa216350ff0e4d7c34421d2c661b25 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Fri, 10 Mar 2023 19:10:08 +0100 Subject: [PATCH 05/12] update linting ci --- .github/workflows/linting_annotate.yml | 49 ++++++++++++++++++++++++++ .github/workflows/linting_testing.yml | 16 ++++----- 2 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/linting_annotate.yml diff --git a/.github/workflows/linting_annotate.yml b/.github/workflows/linting_annotate.yml new file mode 100644 index 00000000..298d73a7 --- /dev/null +++ b/.github/workflows/linting_annotate.yml @@ -0,0 +1,49 @@ +name: Annotate linting + +permissions: + actions: read # download artifact + checks: write # annotate + +# this is done as a seperate workflow so +# the annotater has access to write to checks (to annotate) +on: + workflow_run: + workflows: ["Linting and Testing"] + types: + - completed + +jobs: + annotate: + runs-on: ubuntu-latest + + steps: + - name: Download linting report + uses: actions/github-script@v3.1.0 + with: + script: | + var artifacts = await github.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{github.event.workflow_run.id }}, + }); + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { + return artifact.name == "eslint_report.zip" + })[0]; + var download = await github.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + var fs = require('fs'); + fs.writeFileSync('${{github.workspace}}/eslint_report.zip', Buffer.from(download.data)); + + - run: unzip eslint_report.zip + + - run: ls -la + + - name: Annotate linting + uses: ataylorme/eslint-annotate-action@v2 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" + report-json: "eslint_report.json" diff --git a/.github/workflows/linting_testing.yml b/.github/workflows/linting_testing.yml index e51fc630..d37f2331 100644 --- a/.github/workflows/linting_testing.yml +++ b/.github/workflows/linting_testing.yml @@ -5,8 +5,7 @@ on: branches: - master - dev - pull_request_target: - types: [opened, reopened, synchronize] + pull_request: jobs: linting: @@ -24,17 +23,16 @@ jobs: - name: Install Yarn packages run: yarn install + + - name: Build Project + run: npm run build - name: Run ESLint Report run: yarn lint:report # continue on error, so it still reports it in the next step continue-on-error: true - - name: Annotate Code Linting Results - uses: ataylorme/eslint-annotate-action@v2 + - uses: actions/upload-artifact@v2 with: - repo-token: "${{ secrets.GITHUB_TOKEN }}" - report-json: "eslint_report.json" - - - name: Build Project - run: npm run build + name: eslint_report.zip + path: eslint_report.json From b42d36c5ac51e4b72cbc7d45a578ee32d4cb46d8 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Fri, 10 Mar 2023 19:12:22 +0100 Subject: [PATCH 06/12] fix lint errors --- src/backend/providers/netfilm.ts | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/backend/providers/netfilm.ts b/src/backend/providers/netfilm.ts index ff25fbf8..9b4faafa 100644 --- a/src/backend/providers/netfilm.ts +++ b/src/backend/providers/netfilm.ts @@ -1,6 +1,10 @@ import { proxiedFetch } from "../helpers/fetch"; import { registerProvider } from "../helpers/register"; -import { MWCaptionType, MWStreamQuality, MWStreamType } from "../helpers/streams"; +import { + MWCaptionType, + MWStreamQuality, + MWStreamType, +} from "../helpers/streams"; import { MWMediaType } from "../metadata/types"; const netfilmBase = "https://net-film.vercel.app"; @@ -40,9 +44,12 @@ registerProvider({ // get stream info from media progress(75); - const watchInfo = await proxiedFetch(`/api/episode?id=${netfilmId}`, { - baseURL: netfilmBase, - }); + const watchInfo = await proxiedFetch( + `/api/episode?id=${netfilmId}`, + { + baseURL: netfilmBase, + } + ); const data = watchInfo.data; @@ -56,12 +63,14 @@ registerProvider({ url: sub.url.replace("https://convert-srt-to-vtt.vercel.app/?url=", ""), type: MWCaptionType.SRT, langIso: sub.language, - })) + })); return { embeds: [], stream: { - streamUrl: source.url.replace("akm-cdn", "aws-cdn").replace("gg-cdn", "aws-cdn"), + streamUrl: source.url + .replace("akm-cdn", "aws-cdn") + .replace("gg-cdn", "aws-cdn"), quality: qualityMap[source.quality as QualityInMap], type: MWStreamType.HLS, captions: mappedCaptions, @@ -124,12 +133,14 @@ registerProvider({ url: sub.url.replace("https://convert-srt-to-vtt.vercel.app/?url=", ""), type: MWCaptionType.SRT, langIso: sub.language, - })) + })); return { embeds: [], stream: { - streamUrl: source.url.replace("akm-cdn", "aws-cdn").replace("gg-cdn", "aws-cdn"), + streamUrl: source.url + .replace("akm-cdn", "aws-cdn") + .replace("gg-cdn", "aws-cdn"), quality: qualityMap[source.quality as QualityInMap], type: MWStreamType.HLS, captions: mappedCaptions, From 68a1470447bd03bac38f39ff2a3710c508e82e2c Mon Sep 17 00:00:00 2001 From: mrjvs Date: Fri, 10 Mar 2023 19:17:11 +0100 Subject: [PATCH 07/12] seperate building and linting --- .github/workflows/linting_testing.yml | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linting_testing.yml b/.github/workflows/linting_testing.yml index d37f2331..1538953f 100644 --- a/.github/workflows/linting_testing.yml +++ b/.github/workflows/linting_testing.yml @@ -20,12 +20,10 @@ jobs: uses: actions/setup-node@v3 with: node-version: 18 + cache: 'yarn' - name: Install Yarn packages run: yarn install - - - name: Build Project - run: npm run build - name: Run ESLint Report run: yarn lint:report @@ -36,3 +34,23 @@ jobs: with: name: eslint_report.zip path: eslint_report.json + + building: + name: Build project + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'yarn' + + - name: Install Yarn packages + run: yarn install + + - name: Build Project + run: yarn build From 900c70e36acc390c3483ee4d816e7d467674de71 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Fri, 10 Mar 2023 19:25:14 +0100 Subject: [PATCH 08/12] update ci --- .github/workflows/linting_annotate.yml | 6 +++--- .github/workflows/linting_testing.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/linting_annotate.yml b/.github/workflows/linting_annotate.yml index 298d73a7..4db5b5fc 100644 --- a/.github/workflows/linting_annotate.yml +++ b/.github/workflows/linting_annotate.yml @@ -18,7 +18,7 @@ jobs: steps: - name: Download linting report - uses: actions/github-script@v3.1.0 + uses: actions/github-script@v6 with: script: | var artifacts = await github.actions.listWorkflowRunArtifacts({ @@ -27,7 +27,7 @@ jobs: run_id: ${{github.event.workflow_run.id }}, }); var matchArtifact = artifacts.data.artifacts.filter((artifact) => { - return artifact.name == "eslint_report.zip" + return artifact.name == "eslint_report.json" })[0]; var download = await github.actions.downloadArtifact({ owner: context.repo.owner, @@ -43,7 +43,7 @@ jobs: - run: ls -la - name: Annotate linting - uses: ataylorme/eslint-annotate-action@v2 + uses: ataylorme/eslint-annotate-action@v6 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" report-json: "eslint_report.json" diff --git a/.github/workflows/linting_testing.yml b/.github/workflows/linting_testing.yml index 1538953f..53d7b5ca 100644 --- a/.github/workflows/linting_testing.yml +++ b/.github/workflows/linting_testing.yml @@ -30,9 +30,9 @@ jobs: # continue on error, so it still reports it in the next step continue-on-error: true - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: - name: eslint_report.zip + name: eslint_report.json path: eslint_report.json building: From addd8ca031f7bb05160d26baeb2a40fe7df076eb Mon Sep 17 00:00:00 2001 From: mrjvs Date: Fri, 10 Mar 2023 19:34:25 +0100 Subject: [PATCH 09/12] fix wrong version --- .github/workflows/linting_annotate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linting_annotate.yml b/.github/workflows/linting_annotate.yml index 4db5b5fc..c250fd03 100644 --- a/.github/workflows/linting_annotate.yml +++ b/.github/workflows/linting_annotate.yml @@ -43,7 +43,7 @@ jobs: - run: ls -la - name: Annotate linting - uses: ataylorme/eslint-annotate-action@v6 + uses: ataylorme/eslint-annotate-action@v2 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" report-json: "eslint_report.json" From 695ccef2b5128f0da42ab2b47917c6e38e118e16 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Fri, 10 Mar 2023 19:35:51 +0100 Subject: [PATCH 10/12] added yarn cache to deployment script --- .github/workflows/deploying.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploying.yml b/.github/workflows/deploying.yml index 182a7895..532bb67e 100644 --- a/.github/workflows/deploying.yml +++ b/.github/workflows/deploying.yml @@ -18,12 +18,13 @@ jobs: uses: actions/setup-node@v3 with: node-version: 18 + cache: 'yarn' - name: Install Yarn packages run: yarn install - name: Build project - run: npm run build + run: yarn build - name: Upload production-ready build files uses: actions/upload-artifact@v3 From 5327cbffaaec6bdc6a1a09126142289485cba44c Mon Sep 17 00:00:00 2001 From: mrjvs Date: Fri, 10 Mar 2023 19:38:59 +0100 Subject: [PATCH 11/12] update annotate download script to use v6 --- .github/workflows/linting_annotate.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/linting_annotate.yml b/.github/workflows/linting_annotate.yml index c250fd03..f0482501 100644 --- a/.github/workflows/linting_annotate.yml +++ b/.github/workflows/linting_annotate.yml @@ -21,21 +21,21 @@ jobs: uses: actions/github-script@v6 with: script: | - var artifacts = await github.actions.listWorkflowRunArtifacts({ + const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ owner: context.repo.owner, repo: context.repo.repo, run_id: ${{github.event.workflow_run.id }}, }); - var matchArtifact = artifacts.data.artifacts.filter((artifact) => { + const matchArtifact = artifacts.data.artifacts.filter((artifact) => { return artifact.name == "eslint_report.json" })[0]; - var download = await github.actions.downloadArtifact({ + const download = await github.rest.actions.downloadArtifact({ owner: context.repo.owner, repo: context.repo.repo, artifact_id: matchArtifact.id, archive_format: 'zip', }); - var fs = require('fs'); + const fs = require('fs'); fs.writeFileSync('${{github.workspace}}/eslint_report.zip', Buffer.from(download.data)); - run: unzip eslint_report.zip From 9d7ddc03a5953c44d7a2b4f7856f07e268f755ee Mon Sep 17 00:00:00 2001 From: mrjvs Date: Fri, 10 Mar 2023 19:41:32 +0100 Subject: [PATCH 12/12] name annotation jobs --- .github/workflows/linting_annotate.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/linting_annotate.yml b/.github/workflows/linting_annotate.yml index f0482501..2bc9b613 100644 --- a/.github/workflows/linting_annotate.yml +++ b/.github/workflows/linting_annotate.yml @@ -14,6 +14,7 @@ on: jobs: annotate: + name: Annotate linting runs-on: ubuntu-latest steps: @@ -39,8 +40,6 @@ jobs: fs.writeFileSync('${{github.workspace}}/eslint_report.zip', Buffer.from(download.data)); - run: unzip eslint_report.zip - - - run: ls -la - name: Annotate linting uses: ataylorme/eslint-annotate-action@v2