Skip to content

Commit

Permalink
fix: don't show undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 8, 2023
1 parent 38f1e56 commit 6c8f0bc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions lib/bilibili/fetchBilibiliSubtitle.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { fetchBilibiliSubtitleUrls } from "~/lib/bilibili/fetchBilibiliSubtitleUrls";
import { reduceBilibiliSubtitleTimestamp } from "~/utils/reduceSubtitleTimestamp";

export async function fetchBilibiliSubtitle(videoId: string, shouldShowTimestamp?: boolean) {
export async function fetchBilibiliSubtitle(
videoId: string,
shouldShowTimestamp?: boolean
) {
const res = await fetchBilibiliSubtitleUrls(videoId);
const { title, desc, dynamic } = res || {};
const descriptionText = desc + "\n" + dynamic;
const descriptionText = desc && dynamic ? `${desc} ${dynamic}` : undefined;
const subtitleList = res?.subtitle?.list;
if (!subtitleList || subtitleList?.length < 1) {
return { title, subtitlesArray: null, descriptionText };
Expand All @@ -18,7 +21,10 @@ export async function fetchBilibiliSubtitle(videoId: string, shouldShowTimestamp

const subtitleResponse = await fetch(subtitleUrl);
const subtitles = await subtitleResponse.json();
const transcripts = reduceBilibiliSubtitleTimestamp(subtitles?.body, shouldShowTimestamp);
const transcripts = reduceBilibiliSubtitleTimestamp(
subtitles?.body,
shouldShowTimestamp
);
return { title, subtitlesArray: transcripts, descriptionText };
}

Expand Down
2 changes: 1 addition & 1 deletion lib/bilibili/fetchBilibiliSubtitleUrls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export const fetchBilibiliSubtitleUrls = async (bvId: string) => {
});
const json = await response.json();
// return json.data.View;
console.log('========response========', json)
// { code: -404, message: '啥都木有', ttl: 1 }
return json.data;
};
2 changes: 1 addition & 1 deletion lib/youtube/fetchYoutubeSubtitle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fetchYoutubeSubtitleUrls, SUBTITLE_DOWNLOADER_URL } from "~/lib/youtube/fetchYoutubeSubtitleUrls";
import { find } from "~/utils/fp";
import { reduceSubtitleTimestamp, reduceYoutubeSubtitleTimestamp } from "~/utils/reduceSubtitleTimestamp";
import { reduceYoutubeSubtitleTimestamp } from "~/utils/reduceSubtitleTimestamp";

export async function fetchYoutubeSubtitle(
videoId: string,
Expand Down

1 comment on commit 6c8f0bc

@vercel
Copy link

@vercel vercel bot commented on 6c8f0bc Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.