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

fix: local album art #568

Merged
merged 3 commits into from
Oct 11, 2024
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
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"deepmerge": "^4.3.1",
"dropbox": "git+https://lovegaoshi@github.com/lovegaoshi/dropbox-sdk-js.git",
"event-target-polyfill": "^0.0.4",
"expo": "^51.0.36",
"expo": "^51.0.37",
"expo-auth-session": "~5.5.2",
"expo-clipboard": "~6.0.3",
"expo-crypto": "~13.0.2",
Expand Down Expand Up @@ -103,7 +103,7 @@
"react-native-svga-player": "https://lovegaoshi@github.com/lovegaoshi/react-native-svga-player.git#commit=f8c6303fddb528a1a94d2ab4696c9318c0002cfd",
"react-native-tab-view": "^3.5.2",
"react-native-text-ticker": "https://lovegaoshi@github.com/lovegaoshi/react-native-text-ticker.git#commit=2e7306a4b8d3014b852629a0afe675a35b3de1b1",
"react-native-track-player": "https://github.com/lovegaoshi/react-native-track-player.git#commit=867775edd2d0e063ff4b25432fbc44f8331590f4",
"react-native-track-player": "https://github.com/lovegaoshi/react-native-track-player.git#commit=609f992c743615fbe46e3673b8441e5da13b157b",
"react-native-url-polyfill": "^2.0.0",
"react-native-vector-icons": "^10.2.0",
"react-native-video": "^6.6.4",
Expand All @@ -114,18 +114,18 @@
"uuid": "^10.0.0",
"web-streams-polyfill": "^4.0.0",
"youtubei.js": "^10.5.0",
"ytdl-core": "https://lovegaoshi@github.com/lovegaoshi/node-ytdl-core.git#commit=04425b36337705124202ed193703aea67fa26e97",
"ytdl-core": "https://lovegaoshi@github.com/lovegaoshi/node-ytdl-core.git#commit=1a69dda4058682d1f10dd37803d6b920533735e5",
"zustand": "^5.0.0-rc.2"
},
"resolutions": {
"metro": "^0.80.12"
},
"devDependencies": {
"@babel/core": "^7.25.7",
"@babel/core": "^7.25.8",
"@babel/plugin-syntax-import-attributes": "^7.25.7",
"@babel/plugin-transform-export-namespace-from": "^7.25.7",
"@babel/plugin-transform-export-namespace-from": "^7.25.8",
"@babel/plugin-transform-private-methods": "^7.25.7",
"@babel/preset-env": "^7.25.7",
"@babel/preset-env": "^7.25.8",
"@babel/preset-typescript": "^7.25.7",
"@babel/runtime": "^7.25.7",
"@react-native-community/eslint-config": "^3.2.0",
Expand All @@ -135,7 +135,7 @@
"@types/he": "^1.2.3",
"@types/jest": "^29.5.13",
"@types/md5": "^2.3.5",
"@types/node": "^22.7.4",
"@types/node": "^22.7.5",
"@types/react": "~18.3.11",
"@types/react-native": "^0.73.0",
"@types/react-native-background-timer": "^2.0.2",
Expand Down Expand Up @@ -169,7 +169,7 @@
"react-test-renderer": "18.3.1",
"reactotron-react-native": "^5.1.9",
"rimraf": "^6.0.1",
"typescript": "~5.6.2"
"typescript": "~5.6.3"
},
"engines": {
"node": ">=18.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/components/player/TrackInfo/AlbumArt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const AlbumArt: React.FC<Props> = ({
const playerSetting = useNoxSetting(state => state.playerSetting);
const [isImageVisible, setIsImageVisible] = useState(true);
const [isLrcVisible, setIsLrcVisible] = useState(false);
const [overwriteAlbumArt, setOverwriteAlbumArt] = useState<string>();
const [overwriteAlbumArt, setOverwriteAlbumArt] = useState<string | void>();
const opacity = useRef(new Animated.Value(1)).current;
const dimension = Dimensions.get('window');
const coverStyle = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/styles/steriaGarb.json
Original file line number Diff line number Diff line change
Expand Up @@ -3071,4 +3071,4 @@
"backdrop": "rgba(49, 49, 37, 0.4)"
}
}
]
]
49 changes: 28 additions & 21 deletions src/hooks/usePlaybackAA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,44 @@ import { Platform } from 'react-native';
import { useEffect } from 'react';
import TrackPlayer, { Event } from 'react-native-track-player';
import { useTranslation } from 'react-i18next';
import { PLAYLIST_MEDIAID } from '@enums/Playlist';
import i18n from 'i18next';

import { PLAYLIST_MEDIAID } from '@enums/Playlist';
import usePlayback from './usePlayback';
import { useNoxSetting } from '@stores/useApp';
import { IntentData } from '@enums/Intent';
import usePlaybackCarplay from './usePlaybackCarplay';

export const buildBrowseTree = (
playlists: {
[key: string]: NoxMedia.Playlist;
},
t = i18n.t
) => {
if (Platform.OS !== 'android') return;
TrackPlayer.setBrowseTree({
'/': [
{
mediaId: 'PlaylistTab',
title: t('AndroidAuto.PlaylistTab'),
playable: '1',
},
],
PlaylistTab: Object.keys(playlists).map(key => {
return {
mediaId: `${PLAYLIST_MEDIAID}${key}`,
title: playlists[key].title,
playable: '0',
};
}),
});
};

export const useAndroidAuto = () => {
const { t } = useTranslation();
const playlists = useNoxSetting(state => state.playlists);

const buildBrowseTree = () => {
if (Platform.OS !== 'android') return;
TrackPlayer.setBrowseTree({
'/': [
{
mediaId: 'PlaylistTab',
title: t('AndroidAuto.PlaylistTab'),
playable: '1',
},
],
PlaylistTab: Object.keys(playlists).map(key => {
return {
mediaId: `${PLAYLIST_MEDIAID}${key}`,
title: playlists[key].title,
playable: '0',
};
}),
});
};
return { buildBrowseTree };
return { buildBrowseTree: () => buildBrowseTree(playlists, t) };
};

const useAndroidAutoListener = () => {
Expand Down
7 changes: 5 additions & 2 deletions src/hooks/useSetupPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
import TrackPlayer from 'react-native-track-player';
import { NativeModules, Platform } from 'react-native';

import { SetupService, AdditionalPlaybackService } from 'services';
import { SetupService, additionalPlaybackService } from 'services';
import { initPlayerObject } from '@utils/ChromeStorage';
import { getCurrentTPQueue, initializePlaybackMode } from '@stores/playingList';
import useVersionCheck from '@hooks/useVersionCheck';
Expand All @@ -11,16 +11,19 @@ import { initializeStores } from '@stores/initializeStores';
import { IntentData } from '@enums/Intent';
import { useNoxSetting } from '@stores/useApp';
import usePlayStore from './usePlayStore';
import { buildBrowseTree } from './usePlaybackAA';

const { NoxAndroidAutoModule } = NativeModules;

const initializePlayer = async (safeMode = false) => {
const {
playlists,
currentPlayingID,
storedPlayerSetting,
lastPlayDuration,
playbackMode,
} = await initializeStores({ val: await initPlayerObject(safeMode) });
buildBrowseTree(playlists);
const serviceOptions = {
noInterruption: storedPlayerSetting.noInterruption,
keepForeground: storedPlayerSetting.keepForeground,
Expand All @@ -39,7 +42,7 @@ const initializePlayer = async (safeMode = false) => {
(await TrackPlayer.add(await songlistToTracklist([currentQueue[0]])));
serviceOptions.lastPlayDuration = 0;
}
await AdditionalPlaybackService(serviceOptions);
await additionalPlaybackService(serviceOptions);
return storedPlayerSetting;
};

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useTanakaAmazingCommodities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { fetchVideoPlayUrl } from '../utils/mediafetch/bilivideo';
import { customReqHeader } from '@utils/BiliFetch';
import { StorageKeys } from '@enums/Storage';
import { getFileSize, validateFile } from '../utils/RNUtils';
import { WeightedChoice } from '../utils/Utils';
import { weightedChoice } from '../utils/Utils';

const TanakaSrc = WeightedChoice([
const TanakaSrc = weightedChoice([
['BV1cK42187AE', 99],
['BV1kf421q7jK', 1],
]);
Expand Down
2 changes: 1 addition & 1 deletion src/services/PlaybackService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const getPlayerSetting = playerSettingStore.getState;
let lastBiliHeartBeat: string[] = ['', ''];
const lastPlayedDuration: { val?: number } = { val: 0 };

export async function AdditionalPlaybackService({
export async function additionalPlaybackService({
noInterruption = false,
lastPlayDuration,
currentPlayingID,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/BiliFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const parseBodyParams = (body: any) => {
return formBody.join('&');
};

export default async function BiliFetch(
export default async function biliFetch(
url: string,
paramsProp: NoxNetwork.RequestInit | RequestInit = {
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const randomChoice = <T>(list: T[]) => {
return list[randomNumber(list.length)];
};

export const WeightedChoice = <T>(list: [T, number][]) => {
export const weightedChoice = <T>(list: [T, number][]) => {
const sum = list.reduce((a, b) => a + b[1], 0);
const random = Math.random() * sum;
let current = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ffmpeg/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const base64AlbumArt = (path = tempArtPath) =>
RNFetchBlob.fs
.readFile(path, 'base64')
.then(v => `data:image/png;base64,${v}`)
.catch(() => undefined);
.catch(logger.error);

export const cacheAlbumArt = async (fpath: string) =>
singleLimiter.schedule(async () => {
Expand Down
6 changes: 1 addition & 5 deletions src/utils/mediafetch/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const songFetch = async (
nameRaw: v.title,
singer: v.artist,
singerId: v.artist,
cover: '',
cover: `file://${v.realPath}`,
lyric: '',
page: 0,
duration: v.duration / 1000,
Expand Down Expand Up @@ -67,10 +67,6 @@ const resolveURL = async (song: NoxMedia.Song) => {

const resolveArtwork = async (song: NoxMedia.Song) => {
try {
if (Platform.OS === 'android') {
const APMCacheUri = await NoxAndroidAutoModule.getAPMCacheUri();
if (APMCacheUri !== null) return APMCacheUri;
}
const artworkUri = await cacheAlbumArt(song.bvid);
if (artworkUri) {
return base64AlbumArt(artworkUri);
Expand Down
5 changes: 2 additions & 3 deletions src/utils/mediafetch/resolveURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ export const songExport2URL = (v: NoxMedia.Song): string => {
});
};

const regexResolveArtworks: NoxUtils.RegexMatchResolve<
Promise<string | undefined>
> = [[localFetch.regexResolveURLMatch, localFetch.resolveArtwork]];
const regexResolveArtworks: NoxUtils.RegexMatchResolve<Promise<string | void>> =
[[localFetch.regexResolveURLMatch, localFetch.resolveArtwork]];

export const songResolveArtwork = (v?: NoxMedia.Song) => {
if (!v) return;
Expand Down
Loading
Loading