diff --git a/src/stores/appStore.ts b/src/stores/appStore.ts index 7c839155..3a6a1e21 100644 --- a/src/stores/appStore.ts +++ b/src/stores/appStore.ts @@ -11,6 +11,7 @@ import { import { logger } from '@utils/Logger'; import rejson from '../utils/rejson.json'; import { LoadJSONRegExtractors } from '../utils/re'; +import { SOURCE } from '@enums/MediaFetch'; interface AppStore { pipMode: boolean; @@ -180,9 +181,12 @@ export const cacheResolvedURL = async ( ) { logger.debug(`[CacheResolveURL] ${song.parsedName} needs to be refetched.`); const result = await resolveURL(song); - appStore.setState({ - cachedResolveURLMap: { ...cachedResolveURLMap, [song.id]: result }, - }); + // HACK: do not cache any local source files + if (song.source !== SOURCE.local) { + appStore.setState({ + cachedResolveURLMap: { ...cachedResolveURLMap, [song.id]: result }, + }); + } return result; } return cachedResolvedURL; diff --git a/src/utils/SongOperations.ts b/src/utils/SongOperations.ts index 21274c27..2055a331 100644 --- a/src/utils/SongOperations.ts +++ b/src/utils/SongOperations.ts @@ -60,6 +60,7 @@ export const resolveUrl = async (song: NoxMedia.Song, iOS = true) => { logger.debug( `[SongResolveURL] cache ${cachedUrl ? 'found' : 'missed'}, ${song.id}` ); + const cacheWrapper = async ( song: NoxMedia.Song ): Promise => { diff --git a/src/utils/ffmpeg/ffmpeg.ts b/src/utils/ffmpeg/ffmpeg.ts index 1026140f..cbaf675b 100644 --- a/src/utils/ffmpeg/ffmpeg.ts +++ b/src/utils/ffmpeg/ffmpeg.ts @@ -5,6 +5,14 @@ import TrackPlayer from 'react-native-track-player'; import { logger } from '../Logger'; import { r128gain2Volume } from '../Utils'; +export const cacheAlbumArt = async (fpath: string) => { + // HACK: exoplayer handles embedded art but I also need this for the UI... + await FFmpegKit.execute( + `-i '${fpath}' -an -vcodec copy ${RNFetchBlob.fs.dirs.CacheDir}/tempCover.jpg` + ); + return `${RNFetchBlob.fs.dirs.CacheDir}/tempCover.jpg`; +}; + export const probeMetadata = async (fspath: string) => { const session = await FFprobeKit.execute( `-v quiet -print_format json -show_format '${fspath}'` diff --git a/src/utils/mediafetch/local.ts b/src/utils/mediafetch/local.ts index bd5a0845..fc5a283f 100644 --- a/src/utils/mediafetch/local.ts +++ b/src/utils/mediafetch/local.ts @@ -8,9 +8,9 @@ * steps to refactor: * each site needs a fetch to parse regex extracted, a videoinfo fetcher and a song fetcher. */ -import { Platform, NativeModules } from 'react-native'; +import { NativeModules } from 'react-native'; -import { probeMetadata } from '@utils/ffmpeg/ffmpeg'; +import { probeMetadata, cacheAlbumArt } from '@utils/ffmpeg/ffmpeg'; import { SOURCE } from '@enums/MediaFetch'; import { regexFetchProps } from './generic'; import SongTS from '@objects/Song'; @@ -35,8 +35,7 @@ const songFetch = async ( nameRaw: probedMetadata.tags?.title || v.fileName, singer: probedMetadata.tags?.artist || '', singerId: probedMetadata.tags?.artist || '', - cover: - 'https://i2.hdslb.com/bfs/face/b70f6e62e4582d4fa5d48d86047e64eb57d7504e.jpg', + cover: '', lyric: '', page: 0, duration: Number(probedMetadata.duration) || 0, @@ -55,7 +54,7 @@ const regexFetch = async ({ }); const resolveURL = async (song: NoxMedia.Song) => { - return { url: song.bvid }; + return { url: song.bvid, cover: await cacheAlbumArt(song.bvid) }; }; const refreshSong = (song: NoxMedia.Song) => song;