-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
227 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,23 @@ | ||
export type SummarizeParams = { | ||
bvId: string; | ||
videoConfig: VideoConfig; | ||
userConfig: UserConfig; | ||
}; | ||
export type UserConfig = { | ||
userKey?: string; | ||
shouldShowTimestamp?: boolean; | ||
}; | ||
export type VideoConfig = { | ||
videoId: string; | ||
service?: VideoService; | ||
}; | ||
|
||
export enum VideoService { | ||
Bilibili = "bilibili", | ||
Youtube = "youtube", | ||
// todo: integrate with whisper API | ||
Podcast = "podcast", | ||
Meeting = "meeting", | ||
LocalVideo = "local-video", | ||
LocalAudio = "local-audio", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export const SUBTITLE_DOWNLOADER_URL = "https://savesubs.com"; | ||
export async function fetchYoutubeSubtitle(videoId: string) { | ||
const response = await fetch(SUBTITLE_DOWNLOADER_URL + "/action/extract", { | ||
method: "POST", | ||
body: JSON.stringify({ | ||
data: { url: `https://www.youtube.com/watch?v=${videoId}` }, | ||
}), | ||
headers: { | ||
"Content-Type": "text/plain", | ||
"User-Agent": | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36", | ||
"X-Auth-Token": `${process.env.SAVESUBS_X_AUTH_TOKEN}` || "", | ||
"X-Requested-Domain": "savesubs.com", | ||
"X-Requested-With": "xmlhttprequest", | ||
}, | ||
}); | ||
const { response: json = {} } = await response.json(); | ||
// console.log("========json========", json); | ||
/* | ||
* "title": "Microsoft vs Google: AI War Explained | tech", | ||
"duration": "13 minutes and 15 seconds", | ||
"duration_raw": "795", | ||
"uploader": "Joma Tech / 2023-02-20", | ||
"thumbnail": "//i.ytimg.com/vi/BdHaeczStRA/mqdefault.jpg", | ||
* */ | ||
return { title: json.title, subtitleList: json.formats }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { find } from "lodash"; | ||
// import { VideoService } from "~/lib/types"; | ||
|
||
type CaptionSnippet = { | ||
videoId: string; | ||
language: string; | ||
trackKind: "asr" | "standard" | "forced"; | ||
}; | ||
type YouTubeCaptionType = { | ||
id: string; | ||
snippet: CaptionSnippet; | ||
}; | ||
|
||
export async function fetchYoutubeSubtitleOfficially(videoId: string) { | ||
// https://github.com/adamrichardson14/youtubestatistics/blob/completed/pages/videos.jsx#L37 | ||
// https://developers.google.com/youtube/v3/docs/captions/list?hl=zh-cn0拍;、*IK《0拍;、3edc | ||
/* | ||
* ASR – A caption track generated using automatic speech recognition. | ||
forced – A caption track that plays when no other track is selected in the player. For example, a video that shows aliens speaking in an alien language might have a forced caption track to only show subtitles for the alien language. | ||
standard – A regular caption track. This is the default value. | ||
* */ | ||
const subtitleListUrl = `https://www.googleapis.com/youtube/v3/captions?part=snippet&videoId=${videoId}`; | ||
const response = await fetch( | ||
`${subtitleListUrl}&key=${process.env.YOUTUBE_DATA_API_TOKEN}` | ||
); | ||
const json = await response.json(); | ||
const subtitles = json.items; | ||
console.log("========response========", subtitles); | ||
if (subtitles?.length > 0) { | ||
/* | ||
* trackKind: 'standard', language: 'en', | ||
* trackKind: 'asr', language: 'en', | ||
* */ | ||
const betterSubtitle = | ||
find(subtitles, { trackKind: "standard" }) || | ||
find(subtitles, { language: "zh-CN" }) || | ||
find(subtitles, { language: "en" }) || | ||
subtitles[0]; | ||
const subtitleUrl = `https://www.googleapis.com/youtube/v3/captions/${betterSubtitle.id}`; | ||
const response = await fetch( | ||
`${subtitleUrl}&key=${process.env.YOUTUBE_DATA_API_TOKEN}` | ||
); | ||
// throw oauth2 error | ||
console.log("========subtitleUrl response========", await response.json()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.