Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ytb sponsorblock #735

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/components/miniplayer/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ export default () => {
};
const onArtworkPress = () => {
if (artworkOpacity.value === 1) {
return (artworkOpacity.value = withTiming(0, { duration: 100 }, () => {
artworkOpacity.value = withTiming(0, { duration: 100 }, () => {
runOnJS(setLrcVisible)(true);
}));
});
return;
}
if (artworkOpacity.value === 0) {
setLrcVisible(false);
return (artworkOpacity.value = withTiming(1, { duration: 100 }));
artworkOpacity.value = withTiming(1, { duration: 100 });
return;
}
};

Expand All @@ -89,9 +91,10 @@ export default () => {
if (translationY < -height * SnapToRatio) {
return expand();
}
return (miniplayerHeight.value = withTiming(initHeight.value, {
miniplayerHeight.value = withTiming(initHeight.value, {
duration: 250,
}));
});
return;
};

const scrollDragGesture = React.useMemo(
Expand Down
4 changes: 2 additions & 2 deletions src/components/player/controls/useSponsorBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default () => {
const { sponsorBlockEnabled, sponsorBlockCat } = useNoxSetting(
state => state.playerSetting,
);
const [sponsorblock, setSponsorBlock] = useState<SponsorBlockBili[]>([]);
const [sponsorBlock, setSponsorBlock] = useState<SponsorBlockBili[]>([]);

const initSponsorBlock = (song: NoxMedia.Song) => {
if (sponsorBlockEnabled) {
Expand All @@ -21,7 +21,7 @@ export default () => {
};

const checkSponsorBlock = (position: number) => {
for (const sb of sponsorblock) {
for (const sb of sponsorBlock) {
if (
sponsorBlockCat.includes(sb.category) &&
sb.actionType === ActionType.Skip &&
Expand Down
10 changes: 5 additions & 5 deletions src/components/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ export const createStyle = (
alignItems: 'center',
height: 148,
},
gifs: (customStyle.gifs || []) as any,
bkgrdImg: randomChoice(customStyle.backgroundImages || []) as any,
gifs: (customStyle.gifs ?? []) as any,
bkgrdImg: randomChoice(customStyle.backgroundImages ?? []) as any,
bkgrdImgLandscape: randomChoice(
customStyle.backgroundImagesLandscape || [],
customStyle.backgroundImagesLandscape ?? [],
) as any,
loadingIcon: customStyle.loadingIcon as any,
progressThumbImage: customStyle.progressThumbImage as any,
progressThumbImageLeftDrag: (customStyle.progressThumbImageLeftDrag ||
progressThumbImageLeftDrag: (customStyle.progressThumbImageLeftDrag ??
customStyle.progressThumbImage) as any,
progressThumbImageRightDrag: (customStyle.progressThumbImageRightDrag ||
progressThumbImageRightDrag: (customStyle.progressThumbImageRightDrag ??
customStyle.progressThumbImage) as any,
biliGarbCard: customStyle.biliGarbCard as any,
thumbupSVGA: customStyle.thumbupSVGA as any,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/mediafetch/acfunvideo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const export2URL = (song: NoxMedia.Song) =>
`https://www.youtube.com/watch?v=${song.bvid}`;

export default {
regexSearchMatch: /acfun\.cn\/v\/(ac[0-9]+)/,
regexSearchMatch: /acfun\.cn\/v\/(ac\d+)/,
regexFetch,
regexResolveURLMatch: /^acfun-/,
resolveURL,
Expand Down
3 changes: 3 additions & 0 deletions src/utils/sponsorblock/parser.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Source } from '@enums/MediaFetch';
import { getSponsorBlock as getSponsorBlockBili } from './bilibili';
import { getSponsorBlock as getSponsorYtb } from './ytb';

export const getSponsorBlock = async (song: NoxMedia.Song) => {
switch (song.source) {
case Source.bilivideo:
return getSponsorBlockBili(song);
case Source.ytbvideo:
return getSponsorYtb(song);
}
return [];
};
26 changes: 26 additions & 0 deletions src/utils/sponsorblock/ytb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import bfetch from '@utils/BiliFetch';
import logger from '../Logger';
import { SponsorBlockBili } from './Constants';

// https://wiki.sponsor.ajay.app/w/API_Docs
const API = 'https://sponsor.ajay.app/api/skipSegments?videoID={bvid}';

const _getSponsorBlock = async (bvid: string): Promise<SponsorBlockBili[]> => {
try {
const res = await bfetch(API.replace('{bvid}', bvid));
if (res.status !== 200) {
logger.info(
`[sponsorblock.ytb] ${bvid}: ${res.status} ${res.statusText}`,
);
return [];
}
const json = (await res.json()) as SponsorBlockBili[];
return json;
} catch {
return [];
}
};

export const getSponsorBlock = (
song: NoxMedia.Song,
): Promise<SponsorBlockBili[]> => _getSponsorBlock(song.bvid);
Loading