Skip to content

Commit

Permalink
Merge pull request #611 from lovegaoshi/dev
Browse files Browse the repository at this point in the history
fix: yt suggest
  • Loading branch information
lovegaoshi authored Oct 28, 2024
2 parents 00ed160 + eb9f77a commit fd42a15
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 326 deletions.
20 changes: 5 additions & 15 deletions __tests__/mediafetch/ytbvideo.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import fetcher from '../../src/utils/mediafetch/ytbvideo';
import { resolveURL as resolveURLNode } from '../../src/utils/mediafetch/ytbvideo.node';
import { resolveURL as resolveURLMuse } from '../../src/utils/mediafetch/ytbvideo.muse';
import { resolveURL as resolveURLYtbi } from '../../src/utils/mediafetch/ytbvideo.ytbi';

test.only('dummy fetch', () => {
expect('dummy').toBe('dummy');
});

// HACK: ghactions cant connect to ytbi
import {
resolveURL as resolveURLYtbi,
suggest,
} from '../../src/utils/mediafetch/ytbvideo.ytbi';

test('test ytbvideo', async () => {
const content = await fetcher.regexFetch({
reExtracted: fetcher.regexSearchMatch.exec(
'https://www.youtube.com/watch?v=VtXTFi8edyE'
'https://www.youtube.com/watch?v=VtXTFi8edyE',
),
});
//console.log(content);
Expand All @@ -32,9 +28,3 @@ test('test ytbi', async () => {
//console.log(content);
expect(content).not.toBeNull();
}, 2201000);

test('test ytdl-core', async () => {
const content = await resolveURLNode(dummySong);
console.log(content);
expect(content).not.toBeNull();
}, 220000);
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const esModules = [
'ytdl-core',
'query-string',
'split-on-first',
'filter-obj',
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"react-native-blob-jsi-helper": "^0.3.1",
"react-native-blob-util": "^0.19.11",
"react-native-carplay": "2.4.1-beta.0",
"react-native-device-info": "^13.2.0",
"react-native-device-info": "^14.0.0",
"react-native-draggable-flatlist": "^4.0.1",
"react-native-gesture-handler": "2.20.2",
"react-native-get-random-values": "^1.11.0",
Expand All @@ -96,9 +96,9 @@
"react-native-paper": "^5.12.5",
"react-native-qrcode-svg": "^6.3.12",
"react-native-reanimated": "3.16.1",
"react-native-safe-area-context": "^4.11.1",
"react-native-safe-area-context": "^4.12.0",
"react-native-screens": "3.35.0",
"react-native-shadow-2": "^7.1.0",
"react-native-shadow-2": "^7.1.1",
"react-native-share-menu": "git+https://github.com/Expensify/react-native-share-menu.git",
"react-native-svg": "15.8.0",
"react-native-svga-player": "https://lovegaoshi@github.com/lovegaoshi/react-native-svga-player.git#commit=f8c6303fddb528a1a94d2ab4696c9318c0002cfd",
Expand All @@ -112,10 +112,9 @@
"sp-react-native-in-app-updates": "^1.4.0",
"text-encoding-polyfill": "^0.6.7",
"use-debounce": "^10.0.4",
"uuid": "^10.0.0",
"uuid": "^11.0.1",
"web-streams-polyfill": "^4.0.0",
"youtubei.js": "^10.5.0",
"ytdl-core": "https://lovegaoshi@github.com/lovegaoshi/rn-ytdl-core.git#commit=04425b36337705124202ed193703aea67fa26e97",
"zustand": "^5.0.0"
},
"resolutions": {
Expand All @@ -136,7 +135,7 @@
"@types/he": "^1.2.3",
"@types/jest": "^29.5.14",
"@types/md5": "^2.3.5",
"@types/node": "^22.8.0",
"@types/node": "^22.8.1",
"@types/react": "~18.3.12",
"@types/react-native": "^0.73.0",
"@types/react-native-background-timer": "^2.0.2",
Expand Down
10 changes: 9 additions & 1 deletion src/components/explore/ytmusic/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import { Button } from 'react-native-paper';
import { WebView } from 'react-native-webview';
import { useFocusEffect } from '@react-navigation/native';
import CookieManager from '@react-native-cookies/cookies';
import { get_option } from 'libmuse';

import useGoogleTVOauth from '@components/login/google/useGoogleTVOauth';

const jsCode = 'window.ReactNativeWebView.postMessage(document.cookie)';
const auth = get_option('auth');

const Explore = () => {
const [webView, setWebView] = React.useState(false);
const [cookies, setCookies] = React.useState<string[]>([]);
const { userURL, getNewLoginCode } = useGoogleTVOauth({ setWebView });
const { userURL, loginCodes, getNewLoginCode } = useGoogleTVOauth({
setWebView,
});

const onMessage = (event: any) => {
const { data } = event.nativeEvent;
Expand All @@ -31,6 +35,10 @@ const Explore = () => {
value,
});
});
auth.load_token_with_code(
loginCodes!.deviceCode,
loginCodes!.interval,
);
return true;
}
return false;
Expand Down
9 changes: 8 additions & 1 deletion src/components/login/google/useGoogleTVOauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ interface Props {
setWebView: (val: boolean) => void;
}

interface LoginCode {
userCode: string;
deviceCode: string;
userUrl: string;
expiresIn: number;
interval: number;
}
const useGoogleTVOauth = ({ setWebView }: Props) => {
const [loginCodes, setLoginCodes] = useState({});
const [loginCodes, setLoginCodes] = useState<LoginCode>();
const [userURL, setUserURL] = useState('');
//www.google.com/device?user_code=LNQJ-HZCV

Expand Down
1 change: 1 addition & 0 deletions src/hooks/useTPControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import logger from '@utils/Logger';
const setAppStore = appStore.setState;
const regexResolveURLs: NoxUtils.RegexMatchSuggest<NoxMedia.Song> = [
[ytbvideoFetch.regexResolveURLMatch, ytbvideoFetch.suggest],
[ytbvideoFetch.regexResolveURLMatch2, ytbvideoFetch.suggest],
];
// 130,音乐综合 29,音乐现场 59,演奏 31,翻唱 193,MV 30,VOCALOID·UTAU 194,电音 28,原创音乐
const musicTids = [130, 29, 59, 31, 193, 30, 194, 28];
Expand Down
231 changes: 0 additions & 231 deletions src/utils/mediafetch/ytbvideo.node.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/utils/mediafetch/ytbvideo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { biliApiLimiter } from './throttle';

import { suggest as suggestNode } from './ytbvideo.node';
import {
resolveURL as resolveURLYtbi,
fetchAudioInfo as fetchAudioInfoYtbi,
suggest as suggestYtbi,
} from './ytbvideo.ytbi';
import {
resolveURL as resolveURLMuse,
Expand Down Expand Up @@ -40,6 +40,6 @@ export default {
regexResolveURLMatch2: /^ytbvideo-/,
resolveURL,
refreshSong,
suggest: suggestNode,
suggest: suggestYtbi,
export2URL,
};
Loading

0 comments on commit fd42a15

Please sign in to comment.