diff --git a/src/AzusaPlayer.tsx b/src/AzusaPlayer.tsx index a65c87be9..b45f054dc 100644 --- a/src/AzusaPlayer.tsx +++ b/src/AzusaPlayer.tsx @@ -26,10 +26,12 @@ import Playlist from './components/playlist/View'; import PlayerBottomPanel from './components/player/controls/PlayerProgressControls'; import { useNoxSetting } from '@stores/useApp'; import PlaylistDrawer from './components/playlists/View'; +import { ViewEnum } from './enums/View'; import Settings from './components/setting/View'; import Explore from './components/explore/View'; import './localization/i18n'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; +import { ICONS } from '@enums/Icons'; import NoxBottomTab from './components/bottomtab/NoxBottomTab'; const { LightTheme, DarkTheme } = adaptNavigationTheme({ @@ -53,12 +55,12 @@ const NoxPlayer = ({ navigation, setNavigation = () => undefined }: Props) => { <View style={{ flex: 1, justifyContent: 'flex-end' }}> <Tab.Navigator style={PlayerStyle}> <Tab.Screen - name={NoxEnum.View.View.PLAYER_COVER} + name={ViewEnum.PLAYER_COVER} component={Player} options={{ tabBarStyle: { display: 'none' } }} /> <Tab.Screen - name={NoxEnum.View.View.PLAYER_PLAYLIST} + name={ViewEnum.PLAYER_PLAYLIST} component={Playlist} options={{ tabBarStyle: { display: 'none' } }} /> @@ -111,36 +113,30 @@ const AzusaPlayer = () => { }} > <Drawer.Navigator - initialRouteName={NoxEnum.View.View.PLAYER_HOME} + initialRouteName={ViewEnum.PLAYER_HOME} drawerContent={PlaylistDrawer} > <Drawer.Screen - name={NoxEnum.View.View.PLAYER_HOME} + name={ViewEnum.PLAYER_HOME} options={{ - drawerIcon: () => ( - <IconButton icon={NoxEnum.Icons.ScreenIcons.HomeScreen} /> - ), + drawerIcon: () => <IconButton icon={ICONS.homeScreen} />, title: String(t('appDrawer.homeScreenName')), header: () => null, }} component={NoxPlayerWrapper} /> <Drawer.Screen - name={NoxEnum.View.View.EXPORE} + name={ViewEnum.EXPORE} options={{ - drawerIcon: () => ( - <IconButton icon={NoxEnum.Icons.ScreenIcons.ExploreScreen} /> - ), + drawerIcon: () => <IconButton icon={ICONS.exploreScreen} />, title: String(t('appDrawer.exploreScreenName')), }} component={Explore} /> <Drawer.Screen - name={NoxEnum.View.View.SETTINGS} + name={ViewEnum.SETTINGS} options={{ - drawerIcon: () => ( - <IconButton icon={NoxEnum.Icons.ScreenIcons.SettingScreen} /> - ), + drawerIcon: () => <IconButton icon={ICONS.settingScreen} />, title: String(t('appDrawer.settingScreenName')), header: () => null, }} diff --git a/src/components/bottomtab/NoxBottomTab.tsx b/src/components/bottomtab/NoxBottomTab.tsx index 229ab288b..23b94a0cc 100644 --- a/src/components/bottomtab/NoxBottomTab.tsx +++ b/src/components/bottomtab/NoxBottomTab.tsx @@ -4,6 +4,7 @@ import { IconButton } from 'react-native-paper'; import { useNavigation } from '@react-navigation/native'; import { getDrawerStatusFromState } from '@react-navigation/drawer'; +import { ViewEnum } from '@enums/View'; import { useNoxSetting } from '@stores/useApp'; interface IconProps { @@ -68,21 +69,21 @@ const NoxAndroidBottomTab = ({ navigation }: NoxComponent.NavigationProps2) => { <BottomIconButton icon={renderIcon(Routes.music)} onPress={() => { - navigationGlobal.navigate(NoxEnum.View.View.PLAYER_HOME as never); + navigationGlobal.navigate(ViewEnum.PLAYER_HOME as never); setRoute(Routes.music); }} /> <BottomIconButton icon={renderIcon(Routes.explore)} onPress={() => { - navigationGlobal.navigate(NoxEnum.View.View.EXPORE as never); + navigationGlobal.navigate(ViewEnum.EXPORE as never); setRoute(Routes.explore); }} /> <BottomIconButton icon={renderIcon(Routes.setting)} onPress={() => { - navigationGlobal.navigate(NoxEnum.View.View.SETTINGS as never); + navigationGlobal.navigate(ViewEnum.SETTINGS as never); setRoute(Routes.setting); }} /> diff --git a/src/components/dialogs/CopiedPlaylistDialog.tsx b/src/components/dialogs/CopiedPlaylistDialog.tsx index 59a4f8b36..3af1df86a 100644 --- a/src/components/dialogs/CopiedPlaylistDialog.tsx +++ b/src/components/dialogs/CopiedPlaylistDialog.tsx @@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next'; import { useNoxSetting } from '@stores/useApp'; import logger from '@utils/Logger'; import noxPlayingList from '@stores/playingList'; +import { NoxRepeatMode } from '@enums/RepeatMode'; const { getState } = noxPlayingList; @@ -49,7 +50,7 @@ export default ({ const playlistList = () => { const filteredPlaylists = - getState().playmode === NoxEnum.RNTP.NoxRepeatMode.SUGGEST + getState().playmode === NoxRepeatMode.SUGGEST ? playlistIds : playlistIds.filter(val => val !== fromList.id); return filteredPlaylists.map(val => [val, playlists[val].title]); @@ -57,7 +58,7 @@ export default ({ React.useEffect(() => { // TODO: this is not scrolling? - if (visible && getState().playmode === NoxEnum.RNTP.NoxRepeatMode.SUGGEST) { + if (visible && getState().playmode === NoxRepeatMode.SUGGEST) { playlistRef.current?.scrollToIndex({ index: playlistIds.indexOf(fromList.id), }); diff --git a/src/components/explore/bilibili/View.tsx b/src/components/explore/bilibili/View.tsx index 0d739b591..7c2554b29 100644 --- a/src/components/explore/bilibili/View.tsx +++ b/src/components/explore/bilibili/View.tsx @@ -17,6 +17,7 @@ import { fetchRanking } from '@utils/mediafetch/biliRanking'; import { styles } from '@components/style'; import { useNoxSetting } from '@stores/useApp'; import usePlayback from '@hooks/usePlayback'; +import { ViewEnum } from '@enums/View'; interface BiliCatSongs { [key: number]: NoxMedia.Song[]; @@ -55,9 +56,7 @@ const BiliSongCard = ({ <TouchableOpacity style={{ height: 70, flexDirection: 'row' }} onPress={() => { - navigationGlobal.navigate( - NoxEnum.View.View.PLAYER_PLAYLIST as never - ); + navigationGlobal.navigate(ViewEnum.PLAYER_PLAYLIST as never); playAsSearchList({ songs, song: item }); }} > diff --git a/src/components/landscape/LandscapeActions.tsx b/src/components/landscape/LandscapeActions.tsx index 10577665b..89d71408a 100644 --- a/src/components/landscape/LandscapeActions.tsx +++ b/src/components/landscape/LandscapeActions.tsx @@ -3,8 +3,10 @@ import { Linking, StyleSheet, View } from 'react-native'; import { IconButton } from 'react-native-paper'; import { useNavigation } from '@react-navigation/native'; +import { ICONS } from '@enums/Icons'; import RandomGIFButton from '../buttons/RandomGIF'; import { useNoxSetting } from '@stores/useApp'; +import { ViewEnum } from '@enums/View'; import { logger } from '@utils/Logger'; interface Props { @@ -19,9 +21,9 @@ export default ({ panelWidth = 110 }: Props) => { const onPlaylistPress = () => { navigationGlobal.navigate( navigationGlobal.getState()?.routes?.at(-1)?.name === - NoxEnum.View.View.PLAYER_PLAYLIST - ? (NoxEnum.View.View.PLAYER_PLAYLISTS as never) - : (NoxEnum.View.View.PLAYER_PLAYLIST as never) + ViewEnum.PLAYER_PLAYLIST + ? (ViewEnum.PLAYER_PLAYLISTS as never) + : (ViewEnum.PLAYER_PLAYLIST as never) ); }; @@ -29,7 +31,7 @@ export default ({ panelWidth = 110 }: Props) => { function deepLinkHandler(data: { url: string }) { if (data.url === 'trackplayer://notification.click') { logger.debug('[Drawer] click from notification; navigate to home'); - navigationGlobal.navigate(NoxEnum.View.View.PLAYER_HOME as never); + navigationGlobal.navigate(ViewEnum.PLAYER_HOME as never); } } // This event will be fired when the app is already open and the notification is clicked @@ -60,30 +62,24 @@ export default ({ panelWidth = 110 }: Props) => { /> </View> <IconButton - icon={NoxEnum.Icons.ScreenIcons.HomeScreen} + icon={ICONS.homeScreen} size={iconSize} - onPress={() => - navigationGlobal.navigate(NoxEnum.View.View.LYRICS as never) - } + onPress={() => navigationGlobal.navigate(ViewEnum.LYRICS as never)} /> <IconButton - icon={NoxEnum.Icons.ScreenIcons.PlaylistScreen} + icon={ICONS.playlistScreen} size={iconSize} onPress={onPlaylistPress} /> <IconButton - icon={NoxEnum.Icons.ScreenIcons.ExploreScreen} + icon={ICONS.exploreScreen} size={iconSize} - onPress={() => - navigationGlobal.navigate(NoxEnum.View.View.EXPORE as never) - } + onPress={() => navigationGlobal.navigate(ViewEnum.EXPORE as never)} /> <IconButton - icon={NoxEnum.Icons.ScreenIcons.SettingScreen} + icon={ICONS.settingScreen} size={iconSize} - onPress={() => - navigationGlobal.navigate(NoxEnum.View.View.SETTINGS as never) - } + onPress={() => navigationGlobal.navigate(ViewEnum.SETTINGS as never)} /> </View> ); diff --git a/src/components/landscape/LandscapePlaylistPanel.tsx b/src/components/landscape/LandscapePlaylistPanel.tsx index 2f1ff81b3..2c804b209 100644 --- a/src/components/landscape/LandscapePlaylistPanel.tsx +++ b/src/components/landscape/LandscapePlaylistPanel.tsx @@ -1,6 +1,7 @@ import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { Dimensions, View } from 'react-native'; +import { ViewEnum } from '@enums/View'; import DummySettings from '../setting/DummySettings'; import LandscapeLyricView from './LandscapeLyric'; import { SettingsLandscape as Settings } from '../setting/View'; @@ -25,27 +26,27 @@ export default ({ panelWidth }: Props) => { <View style={panelStyle}> <Stack.Navigator> <Stack.Screen - name={NoxEnum.View.View.LYRICS} + name={ViewEnum.LYRICS} component={WrappedLyricView} options={{ headerShown: false }} /> <Stack.Screen - name={NoxEnum.View.View.PLAYER_PLAYLIST} + name={ViewEnum.PLAYER_PLAYLIST} component={Playlist} options={{ headerShown: false }} /> <Stack.Screen - name={NoxEnum.View.View.PLAYER_PLAYLISTS} + name={ViewEnum.PLAYER_PLAYLISTS} component={Playlists} options={{ headerShown: false }} /> <Stack.Screen - name={NoxEnum.View.View.EXPORE} + name={ViewEnum.EXPORE} component={DummySettings} options={{ headerShown: false }} /> <Stack.Screen - name={NoxEnum.View.View.SETTINGS} + name={ViewEnum.SETTINGS} component={Settings} options={{ headerShown: false }} /> diff --git a/src/components/player/PlayerTopInfo.tsx b/src/components/player/PlayerTopInfo.tsx index a6ebb98d3..c4b285c58 100644 --- a/src/components/player/PlayerTopInfo.tsx +++ b/src/components/player/PlayerTopInfo.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { View, StyleSheet } from 'react-native'; import { IconButton } from 'react-native-paper'; import { useNavigation } from '@react-navigation/native'; +import { ViewEnum } from '@enums/View'; import { useNoxSetting } from '@stores/useApp'; import RandomGIFButton from '../buttons/RandomGIF'; @@ -30,9 +31,7 @@ export default ({ navigation }: NoxComponent.NavigationProps) => { <IconButton icon="playlist-music" onPress={() => - navigationGlobal.navigate( - NoxEnum.View.View.PLAYER_PLAYLIST as never - ) + navigationGlobal.navigate(ViewEnum.PLAYER_PLAYLIST as never) } size={40} /> diff --git a/src/components/player/controls/usePlayerControls.ts b/src/components/player/controls/usePlayerControls.ts index 17f0d459e..631b1d47b 100644 --- a/src/components/player/controls/usePlayerControls.ts +++ b/src/components/player/controls/usePlayerControls.ts @@ -11,6 +11,7 @@ import { saveLastPlayDuration } from '@utils/ChromeStorage'; import { logger } from '@utils/Logger'; import appStore, { getABRepeatRaw, setCurrentPlaying } from '@stores/appStore'; import noxPlayingList from '@stores/playingList'; +import { NoxRepeatMode } from '@enums/RepeatMode'; import { fadePlay } from '@utils/RNTPUtils'; import usePlaylistCRUD from '@hooks/usePlaylistCRUD'; @@ -50,7 +51,7 @@ export default () => { event.position > Math.min(bRepeatDuration, event.duration) - fadeIntervalSec ) { - if (getState().playmode !== NoxEnum.RNTP.NoxRepeatMode.REPEAT_TRACK) { + if (getState().playmode !== NoxRepeatMode.REPEAT_TRACK) { logger.debug( `[FADEOUT] fading out....${event.position} / ${event.duration}` ); @@ -62,7 +63,7 @@ export default () => { } if (abRepeat[1] === 1) return; if (event.position > bRepeatDuration) { - if (getState().playmode === NoxEnum.RNTP.NoxRepeatMode.REPEAT_TRACK) { + if (getState().playmode === NoxRepeatMode.REPEAT_TRACK) { TrackPlayer.seekTo(abRepeat[0] * event.duration); return; } diff --git a/src/components/playlist/BiliSearch/BiliSearchbar.tsx b/src/components/playlist/BiliSearch/BiliSearchbar.tsx index ac7a7b8c8..aaf1e2904 100644 --- a/src/components/playlist/BiliSearch/BiliSearchbar.tsx +++ b/src/components/playlist/BiliSearch/BiliSearchbar.tsx @@ -11,6 +11,7 @@ import { useTranslation } from 'react-i18next'; import ShareMenu, { ShareCallback } from 'react-native-share-menu'; import { useNavigation } from '@react-navigation/native'; +import { ViewEnum } from '@enums/View'; import { useNoxSetting } from '@stores/useApp'; import usePlayback from '@hooks/usePlayback'; import useBiliSearch from '@hooks/useBiliSearch'; @@ -69,7 +70,7 @@ export default ({ }; const handleExternalSearch = (data: string) => { - navigationGlobal.navigate(NoxEnum.View.View.PLAYER_PLAYLIST as never); + navigationGlobal.navigate(ViewEnum.PLAYER_PLAYLIST as never); return handleSearch(data); }; diff --git a/src/components/playlist/BiliSearch/Icons.tsx b/src/components/playlist/BiliSearch/Icons.tsx index 64086d4c6..ff9be1722 100644 --- a/src/components/playlist/BiliSearch/Icons.tsx +++ b/src/components/playlist/BiliSearch/Icons.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import Svg, { Path } from 'react-native-svg'; import { Image } from 'expo-image'; import { StyleSheet } from 'react-native'; +import { SEARCH_OPTIONS } from '@enums/Storage'; const ICONS = { BILIBILI: () => ( @@ -38,9 +39,9 @@ const ICONS = { export const getIcon = (icon: string) => { switch (icon) { - case NoxEnum.Storage.SearchOptions.BILIBILI: + case SEARCH_OPTIONS.BILIBILI: return ICONS.BILIBILI; - case NoxEnum.Storage.SearchOptions.YOUTUBE: + case SEARCH_OPTIONS.YOUTUBE: return ICONS.YOUTUBE; default: return ICONS.MUSICFREE; diff --git a/src/components/playlist/BiliSearch/SearchMenu.tsx b/src/components/playlist/BiliSearch/SearchMenu.tsx index 35b32610e..3a24a73de 100644 --- a/src/components/playlist/BiliSearch/SearchMenu.tsx +++ b/src/components/playlist/BiliSearch/SearchMenu.tsx @@ -4,6 +4,7 @@ import * as DocumentPicker from 'expo-document-picker'; import { Platform, NativeModules, PermissionsAndroid } from 'react-native'; import { useTranslation } from 'react-i18next'; +import { SEARCH_OPTIONS } from '@enums/Storage'; import useAlert from '@components/dialogs/useAlert'; import { MUSICFREE } from '@utils/mediafetch/musicfree'; import ICONS from './Icons'; @@ -31,9 +32,7 @@ export default ({ const { OneWayAlert } = useAlert(); const playerStyle = useNoxSetting(state => state.playerStyle); const setSearchOption = useNoxSetting(state => state.setSearchOption); - const setDefaultSearch = ( - defaultSearch: NoxEnum.Storage.SearchOptions | MUSICFREE - ) => { + const setDefaultSearch = (defaultSearch: SEARCH_OPTIONS | MUSICFREE) => { toggleVisible(); setSearchOption(defaultSearch); }; @@ -73,12 +72,12 @@ export default ({ <Menu visible={visible} onDismiss={toggleVisible} anchor={menuCoords}> <Menu.Item leadingIcon={ICONS.BILIBILI} - onPress={() => setDefaultSearch(NoxEnum.Storage.SearchOptions.BILIBILI)} + onPress={() => setDefaultSearch(SEARCH_OPTIONS.BILIBILI)} title={'Bilibili'} /> <Menu.Item leadingIcon={ICONS.YOUTUBE} - onPress={() => setDefaultSearch(NoxEnum.Storage.SearchOptions.YOUTUBE)} + onPress={() => setDefaultSearch(SEARCH_OPTIONS.YOUTUBE)} title={'Youtube'} /> {showMusicFree && ( diff --git a/src/components/playlist/Info/PlaylistSearchMenu.tsx b/src/components/playlist/Info/PlaylistSearchMenu.tsx index d683df776..fbd23992e 100644 --- a/src/components/playlist/Info/PlaylistSearchMenu.tsx +++ b/src/components/playlist/Info/PlaylistSearchMenu.tsx @@ -2,6 +2,8 @@ import * as React from 'react'; import { Menu } from 'react-native-paper'; import { useTranslation } from 'react-i18next'; +import { SearchRegex } from '@enums/Playlist'; + interface Props { visible?: boolean; toggleVisible?: () => void; @@ -19,10 +21,10 @@ export default ({ return ( <Menu visible={visible} onDismiss={toggleVisible} anchor={menuCoords}> - {Object.keys(NoxEnum.Playlist.SearchRegex).map((entry, index) => ( + {Object.keys(SearchRegex).map((entry, index) => ( <Menu.Item onPress={() => { - setSearchCategory(NoxEnum.Playlist.SearchRegex[entry]?.text); + setSearchCategory(SearchRegex[entry]?.text); toggleVisible(); }} title={String(t(`PlaylistRegex.${entry}`))} diff --git a/src/components/playlist/Menu/PlaylistMenu.tsx b/src/components/playlist/Menu/PlaylistMenu.tsx index 87f767b53..6cc26d810 100644 --- a/src/components/playlist/Menu/PlaylistMenu.tsx +++ b/src/components/playlist/Menu/PlaylistMenu.tsx @@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next'; import usePlaylist from './usePlaylistMenu'; import PlaylistSettingsButton from './PlaylistSettingsButton'; +import { PLAYLIST_ENUMS } from '@enums/Playlist'; import { CopiedPlaylistMenuItem } from '@components/buttons/CopiedPlaylistButton'; import PlaylistSortButton from './PlaylistSortButton'; @@ -47,7 +48,7 @@ export default ({ sortPlaylist, } = usePlaylist({ callback: toggleVisible }); const limitedPlaylistFeatures = - playlist.type !== NoxEnum.Playlist.PlaylistEnums.TYPE_TYPICA_PLAYLIST; + playlist.type !== PLAYLIST_ENUMS.TYPE_TYPICA_PLAYLIST; return ( <Menu visible={visible} onDismiss={toggleVisible} anchor={menuCoords}> diff --git a/src/components/playlist/Menu/PlaylistSortButton.tsx b/src/components/playlist/Menu/PlaylistSortButton.tsx index ee30b545c..541ad0c21 100644 --- a/src/components/playlist/Menu/PlaylistSortButton.tsx +++ b/src/components/playlist/Menu/PlaylistSortButton.tsx @@ -3,6 +3,7 @@ import { Menu, Checkbox, Text } from 'react-native-paper'; import { useTranslation } from 'react-i18next'; import Dialog from '@components/dialogs/GenericSelectDialog'; +import { SORT_OPTIONS } from '@enums/Playlist'; import { StyleSheet } from 'react-native-windows'; import { View } from 'react-native'; @@ -11,7 +12,7 @@ const ICON = 'sort'; interface Props { onCancel?: () => void; sortPlaylist: ( - sortOptions: NoxEnum.Playlist.SortOptions, + sortOptions: SORT_OPTIONS, ascending: boolean, playlist: NoxMedia.Playlist ) => void; @@ -26,7 +27,7 @@ export default ({ const { t } = useTranslation(); const [dialogOpen, setDialogOpen] = useState(false); const [ascending, setAscending] = useState(false); - const sortOptions = Object.entries(NoxEnum.Playlist.SortOptions); + const sortOptions = Object.entries(SORT_OPTIONS); const handleClose = () => { setDialogOpen(false); diff --git a/src/components/playlist/SongList/SongInfo.tsx b/src/components/playlist/SongList/SongInfo.tsx index 2331ff077..c77399038 100644 --- a/src/components/playlist/SongList/SongInfo.tsx +++ b/src/components/playlist/SongList/SongInfo.tsx @@ -8,6 +8,7 @@ import { import { View, GestureResponderEvent, StyleSheet } from 'react-native'; import { useNoxSetting } from '@stores/useApp'; import { seconds2MMSS } from '@utils/Utils'; +import { PLAYLIST_ENUMS } from '@enums/Playlist'; import NoxCache from '@utils/Cache'; interface UsePlaylist { @@ -47,7 +48,7 @@ const SongInfo = ({ const title = playerSetting.parseSongName && - currentPlaylist.type !== NoxEnum.Playlist.PlaylistEnums.TYPE_SEARCH_PLAYLIST + currentPlaylist.type !== PLAYLIST_ENUMS.TYPE_SEARCH_PLAYLIST ? item.parsedName : item.name; const id = item.id; diff --git a/src/components/playlist/SongList/SongMenu.tsx b/src/components/playlist/SongList/SongMenu.tsx index 382acfc39..dce7f29ca 100644 --- a/src/components/playlist/SongList/SongMenu.tsx +++ b/src/components/playlist/SongList/SongMenu.tsx @@ -7,6 +7,8 @@ import usePlaylistCRUD from '@hooks/usePlaylistCRUD'; import { CopiedPlaylistMenuItem } from '@components/buttons/CopiedPlaylistButton'; import RenameSongButton from '@components/player/TrackInfo/RenameSong/RenameSongButton'; import useSongOperations from '@hooks/useSongOperations'; +import { SearchRegex } from '@enums/Playlist'; +import { SOURCE } from '@enums/MediaFetch'; import useBiliSearch from '@hooks/useBiliSearch'; enum ICONS { @@ -118,7 +120,7 @@ export default ({ usePlaylist, prepareForLayoutAnimationRender }: Props) => { leadingIcon={ICONS.SEARCH_IN_PLAYLIST} onPress={() => { searchAndEnableSearch( - `${NoxEnum.Playlist.SearchRegex.absoluteMatch.text}${ + `${SearchRegex.absoluteMatch.text}${ currentPlaylist.songList[songMenuSongIndexes[0]].parsedName }` ); @@ -128,7 +130,7 @@ export default ({ usePlaylist, prepareForLayoutAnimationRender }: Props) => { disabled={checking} title={t('SongOperations.songSearchInPlaylistTitle')} /> - {selectedSongs()[0]?.source === NoxEnum.MediaFetch.Source.Bilivideo && ( + {selectedSongs()[0]?.source === SOURCE.bilivideo && ( <Menu.Item leadingIcon={ICONS.SEARCH_BVID} onPress={() => { diff --git a/src/components/playlist/usePlaylistRN.ts b/src/components/playlist/usePlaylistRN.ts index 87f6f8c92..0cdec4f6e 100644 --- a/src/components/playlist/usePlaylistRN.ts +++ b/src/components/playlist/usePlaylistRN.ts @@ -7,6 +7,7 @@ import { useNetInfo } from '@react-native-community/netinfo'; import { activateKeepAwakeAsync, deactivateKeepAwake } from 'expo-keep-awake'; import { useNoxSetting } from '@stores/useApp'; +import { PLAYLIST_ENUMS, SearchRegex } from '@enums/Playlist'; import usePlaylist from '@hooks/usePlaylist'; import logger from '@utils/Logger'; import noxCache, { noxCacheKey } from '@utils/Cache'; @@ -73,7 +74,7 @@ export default (playlist: NoxMedia.Playlist) => { const reParseSearch = (searchStr: string, rows: Array<NoxMedia.Song>) => { const extraReExtract = [ { - regex: NoxEnum.Playlist.SearchRegex.cachedMatch.regex, + regex: SearchRegex.cachedMatch.regex, process: (val: RegExpExecArray, someRows: Array<NoxMedia.Song>) => someRows.filter( row => @@ -146,7 +147,7 @@ export default (playlist: NoxMedia.Playlist) => { useEffect(() => { if ( playerSetting.autoRSSUpdate && - playlist.type === NoxEnum.Playlist.PlaylistEnums.TYPE_TYPICA_PLAYLIST && + playlist.type === PLAYLIST_ENUMS.TYPE_TYPICA_PLAYLIST && playlist.subscribeUrl.length > 0 && playlist.subscribeUrl[0].length > 0 && new Date().getTime() - playlist.lastSubscribed > 86400000 @@ -158,8 +159,8 @@ export default (playlist: NoxMedia.Playlist) => { }); } if (playerSetting.dataSaver && netInfo.type === 'cellular') { - searchAndEnableSearch(NoxEnum.Playlist.SearchRegex.cachedMatch.text); - handleSearch(NoxEnum.Playlist.SearchRegex.cachedMatch.text); + searchAndEnableSearch(SearchRegex.cachedMatch.text); + handleSearch(SearchRegex.cachedMatch.text); setPlaylistSearchAutoFocus(false); } }, [playlist]); diff --git a/src/components/playlists/Playlists.tsx b/src/components/playlists/Playlists.tsx index e119cf3f9..ee8331545 100644 --- a/src/components/playlists/Playlists.tsx +++ b/src/components/playlists/Playlists.tsx @@ -8,9 +8,11 @@ import DraggableFlatList, { } from 'react-native-draggable-flatlist'; import { useNoxSetting } from '@stores/useApp'; +import { ViewEnum } from '@enums/View'; import AddPlaylistButton, { AddPlaylistButtonRef, } from '../buttons/AddPlaylistButton'; +import { STORAGE_KEYS } from '@enums/Storage'; import NewPlaylistDialog from '../dialogs/NewPlaylistDialog'; import useAlert from '../dialogs/useAlert'; import ShuffleAllButton from '@components/playlists/ShuffleAllButton'; @@ -49,7 +51,7 @@ export default () => { const goToPlaylist = (playlistId: string) => { setCurrentPlaylist(playlists[playlistId]); - navigation.navigate(NoxEnum.View.View.PLAYER_PLAYLIST as never); + navigation.navigate(ViewEnum.PLAYER_PLAYLIST as never); }; const SearchPlaylistAsNewButton = () => ( @@ -107,9 +109,7 @@ export default () => { <View style={styles.addPlaylistButtonContent}> <IconButton icon={'cards-heart'} - onPress={() => - goToPlaylist(NoxEnum.Storage.StorageKeys.FAVORITE_PLAYLIST_KEY) - } + onPress={() => goToPlaylist(STORAGE_KEYS.FAVORITE_PLAYLIST_KEY)} /> <ShuffleAllButton /> <AddPlaylistButton ref={addPlaylistButtonRef} /> @@ -118,33 +118,29 @@ export default () => { {false && ( <IconButton icon={'cog'} - onPress={() => - navigation.navigate(NoxEnum.View.View.SETTINGS as never) - } + onPress={() => navigation.navigate(ViewEnum.SETTINGS as never)} /> )} </View> </TouchableRipple> <TouchableRipple - onPress={() => - goToPlaylist(NoxEnum.Storage.StorageKeys.SEARCH_PLAYLIST_KEY) - } + onPress={() => goToPlaylist(STORAGE_KEYS.SEARCH_PLAYLIST_KEY)} style={[ { backgroundColor: currentPlaylist.id === - playlists[NoxEnum.Storage.StorageKeys.SEARCH_PLAYLIST_KEY]?.id + playlists[STORAGE_KEYS.SEARCH_PLAYLIST_KEY]?.id ? playerStyle.customColors.playlistDrawerBackgroundColor : undefined, }, ]} > <PlaylistItem - item={playlists[NoxEnum.Storage.StorageKeys.SEARCH_PLAYLIST_KEY]} + item={playlists[STORAGE_KEYS.SEARCH_PLAYLIST_KEY]} icon={SearchPlaylistAsNewButton()} leadColor={ currentPlayingList.id === - playlists[NoxEnum.Storage.StorageKeys.SEARCH_PLAYLIST_KEY].id + playlists[STORAGE_KEYS.SEARCH_PLAYLIST_KEY].id ? playerStyle.colors.primary //customColors.playlistDrawerBackgroundColor : undefined } @@ -152,7 +148,7 @@ export default () => { </TouchableRipple> <NewPlaylistDialog visible={newPlaylistDialogOpen} - fromList={playlists[NoxEnum.Storage.StorageKeys.SEARCH_PLAYLIST_KEY]} + fromList={playlists[STORAGE_KEYS.SEARCH_PLAYLIST_KEY]} onClose={() => setNewPlaylistDialogOpen(false)} onSubmit={() => setNewPlaylistDialogOpen(false)} /> diff --git a/src/components/playlists/ShuffleAllButton.tsx b/src/components/playlists/ShuffleAllButton.tsx index 70d4d8cf2..1895739b4 100644 --- a/src/components/playlists/ShuffleAllButton.tsx +++ b/src/components/playlists/ShuffleAllButton.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { IconButton } from 'react-native-paper'; import { useNavigation } from '@react-navigation/native'; +import { ViewEnum } from '@enums/View'; import usePlayback from '@hooks/usePlayback'; export default () => { @@ -8,7 +9,7 @@ export default () => { const { shuffleAll } = usePlayback(); const onPressed = async () => { await shuffleAll(); - navigation.navigate(NoxEnum.View.View.PLAYER_HOME as never); + navigation.navigate(ViewEnum.PLAYER_HOME as never); }; return <IconButton icon="shuffle" onPress={onPressed} />; diff --git a/src/components/playlists/View.tsx b/src/components/playlists/View.tsx index 05fb42eb3..1f4467e14 100644 --- a/src/components/playlists/View.tsx +++ b/src/components/playlists/View.tsx @@ -7,6 +7,7 @@ import { useTranslation } from 'react-i18next'; import { useNoxSetting } from '@stores/useApp'; import useAAPlayback from '@hooks/useAAPlayback'; +import { ViewEnum } from '@enums/View'; import { logger } from '@utils/Logger'; import Playlists from './Playlists'; @@ -60,7 +61,7 @@ export default (props: any) => { function deepLinkHandler(data: { url: string }) { if (data.url === 'trackplayer://notification.click') { logger.debug('[Drawer] click from notification; navigate to home'); - navigation.navigate(NoxEnum.View.View.PLAYER_HOME as never); + navigation.navigate(ViewEnum.PLAYER_HOME as never); } } @@ -78,18 +79,18 @@ export default (props: any) => { <BiliCard backgroundURI={playerStyle.biliGarbCard}> <RenderDrawerItem icon={'home-outline'} - view={NoxEnum.View.View.PLAYER_HOME} + view={ViewEnum.PLAYER_HOME} text={'appDrawer.homeScreenName'} /> </BiliCard> <RenderDrawerItem icon={'compass'} - view={NoxEnum.View.View.EXPORE} + view={ViewEnum.EXPORE} text={'appDrawer.exploreScreenName'} /> <RenderDrawerItem icon={'cog'} - view={NoxEnum.View.View.SETTINGS} + view={ViewEnum.SETTINGS} text={'appDrawer.settingScreenName'} /> <Divider /> diff --git a/src/components/setting/SyncSettings.tsx b/src/components/setting/SyncSettings.tsx index 011ae35a7..962e31b4e 100644 --- a/src/components/setting/SyncSettings.tsx +++ b/src/components/setting/SyncSettings.tsx @@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next'; import { useNoxSetting } from '@stores/useApp'; import GenericSelectDialog from '../dialogs/GenericSelectDialog'; import GenericCheckDialog from '../dialogs/GenericCheckDialog'; +import { EXPORT_OPTIONS } from '@enums/Sync'; import PersonalSyncButton from './sync/PersonalSyncButton'; import DropboxSyncButton from './sync/DropboxAuth'; import GiteeSyncButton from './sync/GiteeAuth'; @@ -14,28 +15,28 @@ import useSync from './sync/useSync'; const EXPORT_OPTIONS_LIST = [ // T // EXPORT_OPTIONS.LOCAL, - NoxEnum.Sync.ExportOptions.DROPBOX, - NoxEnum.Sync.ExportOptions.PERSONAL, - NoxEnum.Sync.ExportOptions.GITEE, + EXPORT_OPTIONS.DROPBOX, + EXPORT_OPTIONS.PERSONAL, + EXPORT_OPTIONS.GITEE, ]; interface SyncInterface { - location: NoxEnum.Sync.ExportOptions; + location: EXPORT_OPTIONS; restoreFromUint8Array: (data: Uint8Array) => Promise<void>; } const SyncButton = ({ location, restoreFromUint8Array }: SyncInterface) => { switch (location) { - case NoxEnum.Sync.ExportOptions.LOCAL: + case EXPORT_OPTIONS.LOCAL: return <></>; - case NoxEnum.Sync.ExportOptions.DROPBOX: + case EXPORT_OPTIONS.DROPBOX: return ( <DropboxSyncButton restoreFromUint8Array={restoreFromUint8Array} /> ); - case NoxEnum.Sync.ExportOptions.PERSONAL: + case EXPORT_OPTIONS.PERSONAL: return ( <PersonalSyncButton restoreFromUint8Array={restoreFromUint8Array} /> ); - case NoxEnum.Sync.ExportOptions.GITEE: + case EXPORT_OPTIONS.GITEE: return <GiteeSyncButton restoreFromUint8Array={restoreFromUint8Array} />; default: return <></>; @@ -58,13 +59,13 @@ export default () => { const renderOption = (option = playerSetting.settingExportLocation) => { switch (option) { - case NoxEnum.Sync.ExportOptions.LOCAL: + case EXPORT_OPTIONS.LOCAL: return t('Sync.Local'); - case NoxEnum.Sync.ExportOptions.DROPBOX: + case EXPORT_OPTIONS.DROPBOX: return t('Sync.Dropbox'); - case NoxEnum.Sync.ExportOptions.PERSONAL: + case EXPORT_OPTIONS.PERSONAL: return t('Sync.PersonalCloud'); - case NoxEnum.Sync.ExportOptions.GITEE: + case EXPORT_OPTIONS.GITEE: return t('Sync.Gitee'); default: return 'ERROR'; diff --git a/src/components/setting/sync/useSync.ts b/src/components/setting/sync/useSync.ts index b78ac3ca2..5ebbe3893 100644 --- a/src/components/setting/sync/useSync.ts +++ b/src/components/setting/sync/useSync.ts @@ -13,6 +13,7 @@ import { addImportedPlaylist, } from '@utils/ChromeStorage'; import useInitializeStore from '@stores/initializeStores'; +import { STORAGE_KEYS } from '@enums/Storage'; /** * this hook will handle all sync back from file operations. it will @@ -53,7 +54,7 @@ const useSync = () => { onPress: async () => { setSyncCheckVisible(true); setNoxExtensionContent( - parsedContent[NoxEnum.Storage.StorageKeys.MY_FAV_LIST_KEY].map( + parsedContent[STORAGE_KEYS.MY_FAV_LIST_KEY].map( (val: any) => parsedContent[val].title || parsedContent[val].info.title ) diff --git a/src/enums/Icons.ts b/src/enums/Icons.ts new file mode 100644 index 000000000..7deb6f731 --- /dev/null +++ b/src/enums/Icons.ts @@ -0,0 +1,6 @@ +export enum ICONS { + homeScreen = 'home', + exploreScreen = 'compass', + settingScreen = 'cog', + playlistScreen = 'playlist-music', +} diff --git a/src/enums/Intent.ts b/src/enums/Intent.ts new file mode 100644 index 000000000..b46b03afd --- /dev/null +++ b/src/enums/Intent.ts @@ -0,0 +1,4 @@ +export enum INTENT_DATA { + resume = 'resume', + playAll = 'play_all', +} diff --git a/src/enums/MediaFetch.ts b/src/enums/MediaFetch.ts new file mode 100644 index 000000000..1721c79f8 --- /dev/null +++ b/src/enums/MediaFetch.ts @@ -0,0 +1,25 @@ +export enum SOURCE { + biliaudio = 'biliaudio', + bilivideo = 'bilivideo', + steriatk = 'steriatk', + ytbvideo = 'ytbvideo', + biliBangumi = 'biliBangumi', + biliLive = 'bililive', + local = 'local', +} + +// https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/video/video_zone.md#%E8%A7%86%E9%A2%91%E5%88%86%E5%8C%BA%E4%B8%80%E8%A7%88 +/** +音乐(主分区) music 3 /v/music +原创音乐 original 28 原创歌曲及纯音乐,包括改编、重编曲及remix /v/music/original +翻唱 cover 31 对曲目的人声再演绎视频 /v/music/cover +VOCALOID·UTAU vocaloid 30 以VOCALOID等歌声合成引擎为基础,运用各类音源进行的创作 /v/music/vocaloid +演奏 perform 59 乐器和非传统乐器器材的演奏作品。 /v/music/perform +MV mv 193 为音乐作品配合拍摄或制作的音乐录影带(Music Video),以及自制拍摄、剪辑、翻拍MV /v/music/mv +音乐现场 live 29 音乐表演的实况视频,包括官方/个人拍摄的综艺节目、音乐剧、音乐节、演唱会等 /v/music/live +音乐综合 other 130 所有无法被收纳到其他音乐二级分区的音乐类视频 /v/music/other +乐评盘点 commentary 243 音乐类新闻、盘点、点评、reaction、榜单、采访、幕后故事、唱片开箱等 /v/music/commentary +音乐教学 tutorial 244 以音乐教学为目的的内容 /v/music/tutorial +电音(已下线) electronic 194 以电子合成器、音乐软体等产生的电子声响制作的音乐 /v/music/electronic +*/ +export const BiliMusicTid = [28, 31, 59, 193, 29]; diff --git a/src/enums/Playlist.ts b/src/enums/Playlist.ts new file mode 100644 index 000000000..4b6ae4fd8 --- /dev/null +++ b/src/enums/Playlist.ts @@ -0,0 +1,20 @@ +export enum PLAYLIST_ENUMS { + TYPE_TYPICA_PLAYLIST = 'typical', + TYPE_SEARCH_PLAYLIST = 'search', + TYPE_FAVORI_PLAYLIST = 'favorite', +} + +export const SearchRegex: { [key: string]: { regex: RegExp; text: string } } = { + absoluteMatch: { regex: /Parsed:(.+)/, text: 'Parsed:' }, + artistMatch: { regex: /Artist:(.+)/, text: 'Artist:' }, + albumMatch: { regex: /Album:(.+)/, text: 'Album:' }, + cachedMatch: { regex: /Cached:/, text: 'Cached:' }, +}; + +export enum SORT_OPTIONS { + TITLE = 'title', + ARTIST = 'artist', + ALBUM = 'album', + DATE = 'date', + PREVIOUS_ORDER = 'previous', +} diff --git a/src/enums/RepeatMode.ts b/src/enums/RepeatMode.ts new file mode 100644 index 000000000..de1cc7bf5 --- /dev/null +++ b/src/enums/RepeatMode.ts @@ -0,0 +1,9 @@ +/** + * these values are also react-native-vector-icon names. + */ +export enum NoxRepeatMode { + SHUFFLE = 'shuffle', + REPEAT = 'repeat', + REPEAT_TRACK = 'repeat-once', + SUGGEST = 'dice-multiple', +} diff --git a/src/enums/Storage.ts b/src/enums/Storage.ts new file mode 100644 index 000000000..0a5be9866 --- /dev/null +++ b/src/enums/Storage.ts @@ -0,0 +1,74 @@ +import { NoxRepeatMode } from './RepeatMode'; +import { VERSIONS } from './Version'; +import { EXPORT_OPTIONS } from './Sync'; + +export { EXPORT_OPTIONS } from './Sync'; + +export enum STORAGE_KEYS { + PLAYER_SETTING_KEY = 'PlayerSetting', + FAVORITE_PLAYLIST_KEY = 'FavFavList-Special', + SEARCH_PLAYLIST_KEY = 'SearchPlaylist-Special', + LAST_PLAY_LIST = 'LastPlayList', + FAVLIST_AUTO_UPDATE_TIMESTAMP = 'favListAutoUpdateTimestamp', + MY_FAV_LIST_KEY = 'MyFavList', + PLAYMODE_KEY = 'Playmode', + SKIN = 'PlayerSkin', + SKINSTORAGE = 'PlayerSkinStorage', + COOKIES = 'Cookies', + LYRIC_MAPPING = 'NewLyricMapping', + LAST_PLAY_DURATION = 'LastPlayDuration', + CACHED_MEDIA_MAPPING = 'CachedMediaMapping', + DEFAULT_SEARCH = 'defaultSearch', + R128GAIN_MAPPING = 'R128GainMapping', + ABREPEAT_MAPPING = 'ABREPEATMapping', + FADE_INTERVAL = 'fadeInterval', + COLORTHEME = 'ColorTheme', + REGEXTRACT_MAPPING = 'RegexExtract', + MUSICFREE_PLUGIN = 'MusicFreePlugin', +} + +export enum SEARCH_OPTIONS { + BILIBILI = 'bilibili', + YOUTUBE = 'youtube', +} + +export const appID = 'NoxPlayerMobile'; + +export const DEFAULT_SETTING: NoxStorage.PlayerSettingDict = { + playMode: 'shufflePlay', + defaultPlayMode: 'shufflePlay', + defaultVolume: 1, + + autoRSSUpdate: true, + skin: '诺莺nox', + parseSongName: true, + keepSearchedSongListWhenPlaying: false, + settingExportLocation: EXPORT_OPTIONS.DROPBOX, + personalCloudIP: '', + personalCloudID: 'azusamobile', + noxVersion: VERSIONS.latest, + noxCheckedVersion: VERSIONS.latest, + + hideCoverInMobile: false, + loadPlaylistAsArtist: false, + sendBiliHeartbeat: false, + noCookieBiliSearch: false, + playbackMode: NoxRepeatMode.SHUFFLE, + dataSaver: false, + fastBiliSearch: true, + noInterruption: false, + updateLoadedTrack: false, + r128gain: false, + prefetchTrack: false, + chatGPTResolveSongName: false, + trackCoverArtCard: false, + suggestedSkipLongVideo: true, + wavyProgressBar: false, + screenAlwaysWake: false, + biliEditAPI: false, + keepForeground: false, + + appID, + language: undefined, + cacheSize: 1, +}; diff --git a/src/enums/Sync.ts b/src/enums/Sync.ts new file mode 100644 index 000000000..b10fac459 --- /dev/null +++ b/src/enums/Sync.ts @@ -0,0 +1,6 @@ +export enum EXPORT_OPTIONS { + LOCAL = '本地', + DROPBOX = 'Dropbox', + PERSONAL = '私有云', + GITEE = 'Gitee', +} diff --git a/src/enums/Utils.ts b/src/enums/Utils.ts new file mode 100644 index 000000000..49ae5b971 --- /dev/null +++ b/src/enums/Utils.ts @@ -0,0 +1,4 @@ +export enum REOPERATIONTYPE { + extractWith = 1, + extractParenthesis = 2, +} diff --git a/src/enums/View.ts b/src/enums/View.ts new file mode 100644 index 000000000..4b90ab240 --- /dev/null +++ b/src/enums/View.ts @@ -0,0 +1,10 @@ +export enum ViewEnum { + PLAYER_HOME = 'NoxHome', + SETTINGS = 'NoxSettings', + PLAYER_COVER = 'NoxCover', + PLAYER_PLAYLIST = 'NoxPlaylist', + PLAYER_PLAYLISTS = 'NoxPlaylists', + USER_LOGIN = 'NoxLogin', + EXPORE = 'NoxExplore', + LYRICS = 'NoxLyrics', +} diff --git a/src/enums/noxEnum.d.ts b/src/enums/noxEnum.d.ts deleted file mode 100644 index ed0738053..000000000 --- a/src/enums/noxEnum.d.ts +++ /dev/null @@ -1,169 +0,0 @@ -import { VERSIONS } from './Version'; - -declare global { - declare namespace NoxEnum { - declare namespace Icons { - export enum ScreenIcons { - HomeScreen = 'home', - ExploreScreen = 'compass', - SettingScreen = 'cog', - PlaylistScreen = 'playlist-music', - } - } - - declare namespace Intent { - export enum IntentData { - Resume = 'resume', - PlayAll = 'play_all', - } - } - - declare namespace MediaFetch { - export enum Source { - Biliaudio = 'biliaudio', - Bilivideo = 'bilivideo', - Steriatk = 'steriatk', - Ytbvideo = 'ytbvideo', - BiliBangumi = 'biliBangumi', - BiliLive = 'bililive', - Local = 'local', - } - - export const BiliMusicTid = [28, 31, 59, 193, 29]; - } - - declare namespace RNTP { - export enum NoxRepeatMode { - SHUFFLE = 'shuffle', - REPEAT = 'repeat', - REPEAT_TRACK = 'repeat-once', - SUGGEST = 'dice-multiple', - } - } - - declare namespace View { - export enum View { - PLAYER_HOME = 'NoxHome', - SETTINGS = 'NoxSettings', - PLAYER_COVER = 'NoxCover', - PLAYER_PLAYLIST = 'NoxPlaylist', - PLAYER_PLAYLISTS = 'NoxPlaylists', - USER_LOGIN = 'NoxLogin', - EXPORE = 'NoxExplore', - LYRICS = 'NoxLyrics', - } - } - - declare namespace Util { - export enum RegexType { - extractWith = 1, - extractParenthesis = 2, - } - } - - declare namespace Sync { - export enum ExportOptions { - LOCAL = '本地', - DROPBOX = 'Dropbox', - PERSONAL = '私有云', - GITEE = 'Gitee', - } - } - - declare namespace Storage { - export enum StorageKeys { - PLAYER_SETTING_KEY = 'PlayerSetting', - FAVORITE_PLAYLIST_KEY = 'FavFavList-Special', - SEARCH_PLAYLIST_KEY = 'SearchPlaylist-Special', - LAST_PLAY_LIST = 'LastPlayList', - FAVLIST_AUTO_UPDATE_TIMESTAMP = 'favListAutoUpdateTimestamp', - MY_FAV_LIST_KEY = 'MyFavList', - PLAYMODE_KEY = 'Playmode', - SKIN = 'PlayerSkin', - SKINSTORAGE = 'PlayerSkinStorage', - COOKIES = 'Cookies', - LYRIC_MAPPING = 'NewLyricMapping', - LAST_PLAY_DURATION = 'LastPlayDuration', - CACHED_MEDIA_MAPPING = 'CachedMediaMapping', - DEFAULT_SEARCH = 'defaultSearch', - R128GAIN_MAPPING = 'R128GainMapping', - ABREPEAT_MAPPING = 'ABREPEATMapping', - FADE_INTERVAL = 'fadeInterval', - COLORTHEME = 'ColorTheme', - REGEXTRACT_MAPPING = 'RegexExtract', - MUSICFREE_PLUGIN = 'MusicFreePlugin', - } - - export enum SearchOptions { - BILIBILI = 'bilibili', - YOUTUBE = 'youtube', - } - - export const AppID = 'NoxPlayerMobile'; - - export const DefaultSetting: NoxStorage.PlayerSettingDict = { - playMode: 'shufflePlay', - defaultPlayMode: 'shufflePlay', - defaultVolume: 1, - - autoRSSUpdate: true, - skin: '诺莺nox', - parseSongName: true, - keepSearchedSongListWhenPlaying: false, - settingExportLocation: EXPORT_OPTIONS.DROPBOX, - personalCloudIP: '', - personalCloudID: 'azusamobile', - noxVersion: VERSIONS.latest, - noxCheckedVersion: VERSIONS.latest, - - hideCoverInMobile: false, - loadPlaylistAsArtist: false, - sendBiliHeartbeat: false, - noCookieBiliSearch: false, - playbackMode: NoxEnum.RNTP.NoxRepeatMode.SHUFFLE, - dataSaver: false, - fastBiliSearch: true, - noInterruption: false, - updateLoadedTrack: false, - r128gain: false, - prefetchTrack: false, - chatGPTResolveSongName: false, - trackCoverArtCard: false, - suggestedSkipLongVideo: true, - wavyProgressBar: false, - screenAlwaysWake: false, - biliEditAPI: false, - keepForeground: false, - - appID, - language: undefined, - cacheSize: 1, - }; - } - - declare namespace Playlist { - export enum PlaylistEnums { - TYPE_TYPICA_PLAYLIST = 'typical', - TYPE_SEARCH_PLAYLIST = 'search', - TYPE_FAVORI_PLAYLIST = 'favorite', - } - - export const SearchRegex: { - [key: string]: { regex: RegExp; text: string }; - } = { - absoluteMatch: { regex: /Parsed:(.+)/, text: 'Parsed:' }, - artistMatch: { regex: /Artist:(.+)/, text: 'Artist:' }, - albumMatch: { regex: /Album:(.+)/, text: 'Album:' }, - cachedMatch: { regex: /Cached:/, text: 'Cached:' }, - }; - - export enum SortOptions { - TITLE = 'title', - ARTIST = 'artist', - ALBUM = 'album', - DATE = 'date', - PREVIOUS_ORDER = 'previous', - } - } - } -} diff --git a/src/hooks/useAAPlayback.ts b/src/hooks/useAAPlayback.ts index 243487f8c..7871ceaad 100644 --- a/src/hooks/useAAPlayback.ts +++ b/src/hooks/useAAPlayback.ts @@ -3,6 +3,7 @@ import { useEffect } from 'react'; import TrackPlayer, { Event } from 'react-native-track-player'; import usePlayback from './usePlayback'; import { useNoxSetting } from '@stores/useApp'; +import { INTENT_DATA } from '@enums/Intent'; const useAAPlayback = () => { const { buildBrowseTree, playFromMediaId, playFromSearch, shuffleAll } = @@ -26,7 +27,7 @@ const useAAPlayback = () => { // HACK: for some reason I decided to register AA related listeners here. // I need the intent shuffleall handling somewhere it only runs once, which // is here... but this looks BAD. - if (intentData === NoxEnum.Intent.IntentData.PlayAll) { + if (intentData === INTENT_DATA.playAll) { shuffleAll(); setIntentData(); } diff --git a/src/hooks/usePlayback.ts b/src/hooks/usePlayback.ts index 7cc4f0be4..4fe6c2b84 100644 --- a/src/hooks/usePlayback.ts +++ b/src/hooks/usePlayback.ts @@ -10,6 +10,7 @@ import { playSongUninterrupted, playSongInterrupted, } from '@utils/RNTPUtils'; +import { NoxRepeatMode } from '@enums/RepeatMode'; import noxPlayingList, { setPlayingIndex } from '@stores/playingList'; import noxCache, { noxCacheKey } from '@utils/Cache'; import useDataSaver from './useDataSaver'; @@ -56,7 +57,7 @@ const usePlayback = () => { }: PlayFromPlaylist) => { playlist = playlistParser(playlist); setCurrentPlayingList(playlist); - if (getState().playmode === NoxEnum.RNTP.NoxRepeatMode.REPEAT_TRACK) { + if (getState().playmode === NoxRepeatMode.REPEAT_TRACK) { await TrackPlayer.setRepeatMode(RepeatMode.Off); } if (song === undefined) { diff --git a/src/hooks/usePlaylist.ts b/src/hooks/usePlaylist.ts index 3197b4438..a6566e373 100644 --- a/src/hooks/usePlaylist.ts +++ b/src/hooks/usePlaylist.ts @@ -3,6 +3,7 @@ import React, { useState, useRef, useCallback, useEffect } from 'react'; import { reParseSearch } from '../utils/re'; import { useNoxSetting } from '../stores/useApp'; import usePlaylistCRUD from './usePlaylistCRUD'; +import { SORT_OPTIONS } from '@enums/Playlist'; export interface UsePlaylist { playlist: NoxMedia.Playlist; @@ -38,7 +39,7 @@ export interface UsePlaylist { onBackPress: () => boolean; getSelectedSongs: () => NoxMedia.Song[] | undefined; sortPlaylist: ( - sort?: NoxEnum.Playlist.SortOptions, + sort?: SORT_OPTIONS, ascend?: boolean, playlist?: NoxMedia.Playlist ) => void; diff --git a/src/hooks/usePlaylistCRUD.ts b/src/hooks/usePlaylistCRUD.ts index b63ed1d17..06ee3f674 100644 --- a/src/hooks/usePlaylistCRUD.ts +++ b/src/hooks/usePlaylistCRUD.ts @@ -9,6 +9,7 @@ import { biliShazamOnSonglist } from '../utils/mediafetch/bilishazam'; import { syncFavlist } from '@utils/Bilibili/bilifavOperate'; import { updateSubscribeFavList } from '../utils/BiliSubscribe'; import { sortPlaylist as sortPlaylistR } from '../utils/playlistOperations'; +import { SORT_OPTIONS } from '../enums/Playlist'; const usePlaylistCRUD = (mPlaylist?: NoxMedia.Playlist) => { const { playlistAnalyze } = useAnalytics(); @@ -213,7 +214,7 @@ const usePlaylistCRUD = (mPlaylist?: NoxMedia.Playlist) => { }; const sortPlaylist = ( - sort = NoxEnum.Playlist.SortOptions.PREVIOUS_ORDER, + sort = SORT_OPTIONS.PREVIOUS_ORDER, ascend = false, playlist = getPlaylist() ) => { diff --git a/src/hooks/useSetupPlayer.ts b/src/hooks/useSetupPlayer.ts index 8bf117e5e..5f3f5c615 100644 --- a/src/hooks/useSetupPlayer.ts +++ b/src/hooks/useSetupPlayer.ts @@ -10,6 +10,7 @@ import { getCurrentTPQueue, initializePlaybackMode } from '@stores/playingList'; import useVersionCheck from '@hooks/useVersionCheck'; import { songlistToTracklist } from '@utils/RNTPUtils'; import useInitializeStore from '@stores/initializeStores'; +import { INTENT_DATA } from '@enums/Intent'; import { useNoxSetting } from '@stores/useApp'; const { NoxAndroidAutoModule } = NativeModules; @@ -64,10 +65,10 @@ export default ({ intentData }: NoxComponent.AppProps) => { await AdditionalPlaybackService(serviceOptions); setIntentData(intentData); switch (intentData) { - case NoxEnum.Intent.IntentData.Resume: + case INTENT_DATA.resume: await TrackPlayer.play(); break; - case NoxEnum.Intent.IntentData.PlayAll: + case INTENT_DATA.playAll: // this hook cannot use usePlayback bc of rerendering. default: await TrackPlayer.pause(); diff --git a/src/hooks/useSongOperations.ts b/src/hooks/useSongOperations.ts index 56eef3bbd..e258ea8bb 100644 --- a/src/hooks/useSongOperations.ts +++ b/src/hooks/useSongOperations.ts @@ -1,5 +1,6 @@ import { useNoxSetting } from '@stores/useApp'; import { logger } from '@utils/Logger'; +import { SOURCE } from '@enums/MediaFetch'; const useSongOperations = () => { const setExternalSearchText = useNoxSetting( @@ -9,10 +10,10 @@ const useSongOperations = () => { const startRadio = (song: NoxMedia.Song) => { switch (song.source) { - case NoxEnum.MediaFetch.Source.Ytbvideo: + case SOURCE.ytbvideo: setExternalSearchText(`youtu.be/${song.bvid}`); break; - case NoxEnum.MediaFetch.Source.Bilivideo: + case SOURCE.bilivideo: setExternalSearchText(`bilibili.com/video/similarvideo/${song.bvid}`); default: logger.warn( @@ -23,10 +24,7 @@ const useSongOperations = () => { }; const radioAvailable = (song?: NoxMedia.Song) => - [ - NoxEnum.MediaFetch.Source.Ytbvideo, - NoxEnum.MediaFetch.Source.Bilivideo, - ].includes(song?.source as NoxEnum.MediaFetch.Source); + [SOURCE.ytbvideo, SOURCE.bilivideo].includes(song?.source as SOURCE); return { startRadio, radioAvailable }; }; diff --git a/src/hooks/useTPControls.ts b/src/hooks/useTPControls.ts index f23d95a8f..19a536c11 100644 --- a/src/hooks/useTPControls.ts +++ b/src/hooks/useTPControls.ts @@ -6,6 +6,7 @@ import { useNoxSetting } from '@stores/useApp'; import noxPlayingList, { playNextSong } from '@stores/playingList'; import biliavideo from '@utils/mediafetch/biliavideo'; import { randomChoice, regexMatchOperations } from '@utils/Utils'; +import { NoxRepeatMode } from '@enums/RepeatMode'; import { songlistToTracklist } from '@utils/RNTPUtils'; import appStore from '@stores/appStore'; import ytbvideoFetch from '@utils/mediafetch/ytbvideo'; @@ -67,9 +68,7 @@ export default () => { }; const skipToBiliSuggest = async (next = true) => { - if ( - noxPlayingList.getState().playmode !== NoxEnum.RNTP.NoxRepeatMode.SUGGEST - ) { + if (noxPlayingList.getState().playmode !== NoxRepeatMode.SUGGEST) { throw new Error('playmode is not bilisuggest.'); } const suggestedSong = [await getBiliSuggest()]; diff --git a/src/objects/Playlist.ts b/src/objects/Playlist.ts index 778c70e49..ee1346346 100644 --- a/src/objects/Playlist.ts +++ b/src/objects/Playlist.ts @@ -1,9 +1,11 @@ import { v4 as uuidv4 } from 'uuid'; import i18n from 'i18next'; +import { PLAYLIST_ENUMS } from '../enums/Playlist'; + export const dummyPlaylist = ( title = i18n.t('PlaylistOperations.searchListName'), - type = NoxEnum.Playlist.PlaylistEnums.TYPE_TYPICA_PLAYLIST + type = PLAYLIST_ENUMS.TYPE_TYPICA_PLAYLIST ): NoxMedia.Playlist => { return { songList: [], diff --git a/src/objects/Song.ts b/src/objects/Song.ts index 6901c370f..d97869bd6 100644 --- a/src/objects/Song.ts +++ b/src/objects/Song.ts @@ -3,6 +3,7 @@ import he from 'he'; import { extractParenthesis } from '../utils/re'; import { reExtractSongName } from '@stores/appStore'; +import { SOURCE } from '@enums/MediaFetch'; import { MUSICFREE } from '@utils/mediafetch/musicfree'; import { i0hdslbHTTPResolve } from '@utils/Utils'; @@ -25,7 +26,7 @@ interface SongProps { duration?: number; album?: string; addedDate?: number; - source?: NoxEnum.MediaFetch.Source | MUSICFREE; + source?: SOURCE | MUSICFREE; isLive?: boolean; liveStatus?: boolean; metadataOnLoad?: boolean; diff --git a/src/services/PlaybackService.ts b/src/services/PlaybackService.ts index 838cf0ea3..dabef26c5 100644 --- a/src/services/PlaybackService.ts +++ b/src/services/PlaybackService.ts @@ -10,6 +10,7 @@ import { parseSongR128gain } from '../utils/SongOperations'; import { initBiliHeartbeat } from '../utils/Bilibili/BiliOperate'; import { logger } from '../utils/Logger'; import noxPlayingList, { getNextSong } from '../stores/playingList'; +import { NoxRepeatMode } from '../enums/RepeatMode'; import playerSettingStore from '@stores/playerSettingStore'; import appStore, { resetResolvedURL } from '@stores/appStore'; import { @@ -151,7 +152,7 @@ export async function PlaybackService() { console.error('resolveURL failed', event.track, e); } } - if (getState().playmode === NoxEnum.RNTP.NoxRepeatMode.REPEAT_TRACK) { + if (getState().playmode === NoxRepeatMode.REPEAT_TRACK) { TrackPlayer.setRepeatMode(RepeatMode.Track); } } diff --git a/src/stores/playerSettingStore.ts b/src/stores/playerSettingStore.ts index 283c16718..51f7e9ada 100644 --- a/src/stores/playerSettingStore.ts +++ b/src/stores/playerSettingStore.ts @@ -1,5 +1,7 @@ // vanilla store of zustand serving playbackServices. import { createStore } from 'zustand/vanilla'; + +import { DEFAULT_SETTING } from '@enums/Storage'; import { saveSettings, getSettings } from '@utils/ChromeStorage'; interface AppStore { @@ -8,7 +10,7 @@ interface AppStore { } const playerSettingStore = createStore<AppStore>((set, get) => ({ - playerSetting: NoxEnum.Storage.DefaultSetting, + playerSetting: DEFAULT_SETTING, setPlayerSetting: (val: Partial<NoxStorage.PlayerSettingDict>) => { const newPlayerSetting = { ...get().playerSetting, ...val }; set({ playerSetting: newPlayerSetting }); diff --git a/src/stores/playingList.ts b/src/stores/playingList.ts index e6c77d1e6..86a4b5590 100644 --- a/src/stores/playingList.ts +++ b/src/stores/playingList.ts @@ -3,6 +3,7 @@ import { createStore } from 'zustand/vanilla'; import TrackPlayer, { RepeatMode } from 'react-native-track-player'; import { clearPlaylistUninterrupted } from '@utils/RNTPUtils'; +import { NoxRepeatMode } from '../enums/RepeatMode'; import { savePlayMode } from '@utils/ChromeStorage'; import logger from '@utils/Logger'; @@ -14,7 +15,7 @@ interface NoxPlaylistStore { // watch out for the things needed to be added like // saveLastPlayedSongId, etc set in useApp. currentPlayingId: string; - playmode: NoxEnum.RNTP.NoxRepeatMode; + playmode: NoxRepeatMode; } const playlistStore = createStore<NoxPlaylistStore>(() => ({ @@ -22,7 +23,7 @@ const playlistStore = createStore<NoxPlaylistStore>(() => ({ playingListShuffled: [], currentPlayingIndex: -1, currentPlayingId: '', - playmode: NoxEnum.RNTP.NoxRepeatMode.SHUFFLE, + playmode: NoxRepeatMode.SHUFFLE, })); export const setPlayingIndex = (index = 0, songId?: string) => { @@ -71,10 +72,10 @@ export const setPlayingList = (list: Array<NoxMedia.Song>) => { }); }; -export const getCurrentTPQueue = (playmode?: NoxEnum.RNTP.NoxRepeatMode) => { +export const getCurrentTPQueue = (playmode?: NoxRepeatMode) => { const state = playlistStore.getState(); if (!playmode) playmode = state.playmode; - if (playmode === NoxEnum.RNTP.NoxRepeatMode.SHUFFLE) { + if (playmode === NoxRepeatMode.SHUFFLE) { return state.playingListShuffled; } return state.playingList; @@ -107,17 +108,17 @@ export const getPlaybackModeNotifIcon = ( // RepeatMode.Off. let TPRepeatMode = RepeatMode.Off; switch (state) { - case NoxEnum.RNTP.NoxRepeatMode.REPEAT: + case NoxRepeatMode.REPEAT: nextIcon = 2; break; - case NoxEnum.RNTP.NoxRepeatMode.REPEAT_TRACK: + case NoxRepeatMode.REPEAT_TRACK: nextIcon = 3; TPRepeatMode = RepeatMode.Track; break; - case NoxEnum.RNTP.NoxRepeatMode.SUGGEST: + case NoxRepeatMode.SUGGEST: nextIcon = 5; break; - case NoxEnum.RNTP.NoxRepeatMode.SHUFFLE: + case NoxRepeatMode.SHUFFLE: nextIcon = 4; break; default: @@ -126,15 +127,12 @@ export const getPlaybackModeNotifIcon = ( return [nextIcon, TPRepeatMode]; }; -const RefreshPlayingIndex = [ - NoxEnum.RNTP.NoxRepeatMode.SHUFFLE, - NoxEnum.RNTP.NoxRepeatMode.REPEAT, -]; +const RefreshPlayingIndex = [NoxRepeatMode.SHUFFLE, NoxRepeatMode.REPEAT]; /** * calls TP.setRepeatMode by the input repeat mode, saves repeat mode into asnycStorage, then * returns the icon associated with the repeat mode (for notification bar). */ -export const initializePlaybackMode = (state: NoxEnum.RNTP.NoxRepeatMode) => { +export const initializePlaybackMode = (state: NoxRepeatMode) => { const [nextIcon, TPRepeatMode] = getPlaybackModeNotifIcon(state); playlistStore.setState({ playmode: state }); if (RefreshPlayingIndex.includes(state)) { @@ -151,14 +149,14 @@ export const initializePlaybackMode = (state: NoxEnum.RNTP.NoxRepeatMode) => { */ export const cycleThroughPlaymode = () => { switch (playlistStore.getState().playmode) { - case NoxEnum.RNTP.NoxRepeatMode.SHUFFLE: - return initializePlaybackMode(NoxEnum.RNTP.NoxRepeatMode.REPEAT); - case NoxEnum.RNTP.NoxRepeatMode.REPEAT: - return initializePlaybackMode(NoxEnum.RNTP.NoxRepeatMode.REPEAT_TRACK); - case NoxEnum.RNTP.NoxRepeatMode.REPEAT_TRACK: - return initializePlaybackMode(NoxEnum.RNTP.NoxRepeatMode.SUGGEST); - case NoxEnum.RNTP.NoxRepeatMode.SUGGEST: - return initializePlaybackMode(NoxEnum.RNTP.NoxRepeatMode.SHUFFLE); + case NoxRepeatMode.SHUFFLE: + return initializePlaybackMode(NoxRepeatMode.REPEAT); + case NoxRepeatMode.REPEAT: + return initializePlaybackMode(NoxRepeatMode.REPEAT_TRACK); + case NoxRepeatMode.REPEAT_TRACK: + return initializePlaybackMode(NoxRepeatMode.SUGGEST); + case NoxRepeatMode.SUGGEST: + return initializePlaybackMode(NoxRepeatMode.SHUFFLE); default: return undefined; } diff --git a/src/stores/useApp.ts b/src/stores/useApp.ts index c17361ff5..5ed62e18c 100644 --- a/src/stores/useApp.ts +++ b/src/stores/useApp.ts @@ -15,6 +15,7 @@ import { saveLyricMapping, saveDefaultSearch, } from '@utils/ChromeStorage'; +import { DEFAULT_SETTING, STORAGE_KEYS, SEARCH_OPTIONS } from '@enums/Storage'; import { setPlayerSetting as setPlayerSettingVanilla } from './playerSettingStore'; import { savePlayerStyle } from '@utils/StyleStorage'; import { createStyle } from '@components/style'; @@ -22,13 +23,14 @@ import { getABRepeatRaw } from './appStore'; import { setPlayingList, setPlayingIndex } from '@stores/playingList'; import DummyLyricDetail from '../objects/LyricDetail'; import { MUSICFREE } from '../utils/mediafetch/musicfree'; +import { INTENT_DATA } from '@enums/Intent'; interface NoxSetting { - intentData?: NoxEnum.Intent.IntentData; - setIntentData: (val?: NoxEnum.Intent.IntentData) => void; + intentData?: INTENT_DATA; + setIntentData: (val?: INTENT_DATA) => void; - searchOption: NoxEnum.Storage.SearchOptions | MUSICFREE; - setSearchOption: (val: NoxEnum.Storage.SearchOptions | MUSICFREE) => void; + searchOption: SEARCH_OPTIONS | MUSICFREE; + setSearchOption: (val: SEARCH_OPTIONS | MUSICFREE) => void; gestureMode: boolean; setGestureMode: (val: boolean) => void; @@ -130,7 +132,7 @@ interface NoxSetting { export const useNoxSetting = create<NoxSetting>((set, get) => ({ setIntentData: intentData => set({ intentData }), - searchOption: NoxEnum.Storage.SearchOptions.BILIBILI, + searchOption: SEARCH_OPTIONS.BILIBILI, setSearchOption: v => { set({ searchOption: v }); saveDefaultSearch(v); @@ -208,18 +210,18 @@ export const useNoxSetting = create<NoxSetting>((set, get) => ({ searchPlaylist: dummyPlaylist(), setSearchPlaylist: val => { let playlists = get().playlists; - playlists[NoxEnum.Storage.StorageKeys.SEARCH_PLAYLIST_KEY] = val; + playlists[STORAGE_KEYS.SEARCH_PLAYLIST_KEY] = val; set({ searchPlaylist: val, playlists }); }, favoritePlaylist: dummyPlaylist(), setFavoritePlaylist: val => { let playlists = get().playlists; - playlists[NoxEnum.Storage.StorageKeys.FAVORITE_PLAYLIST_KEY] = val; + playlists[STORAGE_KEYS.FAVORITE_PLAYLIST_KEY] = val; saveFavPlaylist(val); set({ favoritePlaylist: val, playlists }); }, - playerSetting: NoxEnum.Storage.DefaultSetting, + playerSetting: DEFAULT_SETTING, setPlayerSetting: val => { const newPlayerSetting = { ...get().playerSetting, ...val }; set({ playerSetting: newPlayerSetting }); @@ -241,10 +243,7 @@ export const useNoxSetting = create<NoxSetting>((set, get) => ({ let playlists = get().playlists; const currentPlaylist = get().currentPlaylist; if (currentPlaylist.id === playlistId) { - set({ - currentPlaylist: - playlists[NoxEnum.Storage.StorageKeys.SEARCH_PLAYLIST_KEY], - }); + set({ currentPlaylist: playlists[STORAGE_KEYS.SEARCH_PLAYLIST_KEY] }); } delPlaylist(playlists[playlistId], playlistIds); delete playlists[playlistId]; @@ -316,7 +315,7 @@ export const useNoxSetting = create<NoxSetting>((set, get) => ({ playlists: val.playlists, currentPlayingList: playingList, currentPlayingID: val.lastPlaylistId[1], - storedPlayerSetting: val.settings || NoxEnum.Storage.DefaultSetting, + storedPlayerSetting: val.settings || DEFAULT_SETTING, cookies: val.cookies, language: val.settings.language, lastPlayDuration: val.lastPlayDuration, diff --git a/src/types/component.d.ts b/src/types/component.d.ts index dfad4be76..618782b1d 100644 --- a/src/types/component.d.ts +++ b/src/types/component.d.ts @@ -3,10 +3,12 @@ import { ParamListBase } from '@react-navigation/native'; import { DrawerNavigationProp } from '@react-navigation/drawer'; import { Track } from 'react-native-track-player'; +import { INTENT_DATA } from '@enums/Intent'; + declare global { namespace NoxComponent { interface AppProps { - intentData?: NoxEnum.Intent.IntentData; + intentData?: INTENT_DATA; } interface NavigationProps { navigation: DrawerNavigationProp<ParamListBase>; diff --git a/src/types/media.d.ts b/src/types/media.d.ts index 3ccbe220f..18f27c380 100644 --- a/src/types/media.d.ts +++ b/src/types/media.d.ts @@ -1,3 +1,5 @@ +import { SORT_OPTIONS, PLAYLIST_ENUMS } from '@enums/Playlist'; +import { SOURCE } from '@enums/MediaFetch'; import { MUSICFREE } from '@utils/mediafetch/musicfree'; declare global { @@ -18,7 +20,7 @@ declare global { duration: number; album?: string; addedDate?: number; - source?: NoxEnum.MediaFetch.Source | MUSICFREE; + source?: SOURCE | MUSICFREE; isLive?: boolean; liveStatus?: boolean; metadataOnLoad?: boolean; @@ -28,7 +30,7 @@ declare global { export interface Playlist { title: string; id: string; - type: NoxEnum.Playlist.PlaylistEnums; + type: PLAYLIST_ENUMS; songList: Array<Song>; @@ -40,7 +42,7 @@ declare global { biliSync: boolean; newSongOverwrite?: boolean; - sort?: NoxEnum.Playlist.SortOptions; + sort?: SORT_OPTIONS; // function to support infinite loading; only applicable to // search playlists. bc we stringify playlists, this will be // lost upon loading from storage diff --git a/src/types/storage.d.ts b/src/types/storage.d.ts index 0d6f76d40..621e416dc 100644 --- a/src/types/storage.d.ts +++ b/src/types/storage.d.ts @@ -1,6 +1,10 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { ColorSchemeName } from 'react-native'; +import { EXPORT_OPTIONS } from '../enums/Sync'; +import { NoxRepeatMode } from '../enums/RepeatMode'; +import { SEARCH_OPTIONS } from '../enums/Storage'; + declare global { namespace NoxStorage { export interface PlayerSettingDict { @@ -12,7 +16,7 @@ declare global { skin: string; parseSongName: boolean; keepSearchedSongListWhenPlaying: boolean; - settingExportLocation: NoxEnum.Sync.ExportOptions; + settingExportLocation: EXPORT_OPTIONS; personalCloudIP: string; personalCloudID: string; noxVersion: string; @@ -49,7 +53,7 @@ declare global { lastPlaylistId: [string, string]; searchPlaylist: NoxMedia.Playlist; favoriPlaylist: NoxMedia.Playlist; - playbackMode: NoxEnum.RNTP.NoxRepeatMode; + playbackMode: NoxRepeatMode; skin: NoxTheme.Style; skins: any[]; // site: set-cookie header @@ -58,7 +62,7 @@ declare global { language?: string; lastPlayDuration: number; colorScheme: ColorSchemeName; - defaultSearchOptions?: NoxEnum.Storage.SearchOptions; + defaultSearchOptions?: SEARCH_OPTIONS; } export interface initializedResults { @@ -69,7 +73,7 @@ declare global { cookies: { [key: string]: string }; language?: string; lastPlayDuration: number; - playbackMode: NoxEnum.RNTP.NoxRepeatMode; + playbackMode: NoxRepeatMode; } export interface R128Dict { diff --git a/src/utils/BiliSearch.ts b/src/utils/BiliSearch.ts index b46317e20..d59374dfd 100644 --- a/src/utils/BiliSearch.ts +++ b/src/utils/BiliSearch.ts @@ -1,5 +1,6 @@ import { logger } from './Logger'; +import { SEARCH_OPTIONS } from '@enums/Storage'; import steriatkFetch from './mediafetch/steriatk'; import biliVideoSimilarFetch from './mediafetch/biliVideoSimilar'; import biliBangumiFetch from './mediafetch/biliBangumi'; @@ -44,7 +45,7 @@ interface Props { useBiliTag?: boolean; fastSearch?: boolean; cookiedSearch?: boolean; - defaultSearch?: NoxEnum.Storage.SearchOptions | MUSICFREE; + defaultSearch?: SEARCH_OPTIONS | MUSICFREE; } export const matchBiliURL = <T>( @@ -71,7 +72,7 @@ export const searchBiliURLs = async ({ useBiliTag = false, fastSearch = true, cookiedSearch = false, - defaultSearch = NoxEnum.Storage.SearchOptions.BILIBILI, + defaultSearch = SEARCH_OPTIONS.BILIBILI, }: Props) => { let results: NoxMedia.SearchPlaylist = { songList: [], @@ -97,7 +98,7 @@ export const searchBiliURLs = async ({ return results; } // bilisearchFetch switch (defaultSearch) { - case NoxEnum.Storage.SearchOptions.YOUTUBE: + case SEARCH_OPTIONS.YOUTUBE: results = await ytbsearchFetch.regexFetch({ url: input, progressEmitter, diff --git a/src/utils/BiliSubscribe.ts b/src/utils/BiliSubscribe.ts index 7a77c2c13..2ff56aa9a 100644 --- a/src/utils/BiliSubscribe.ts +++ b/src/utils/BiliSubscribe.ts @@ -1,4 +1,5 @@ import { searchBiliURLs } from './BiliSearch'; +import { PLAYLIST_ENUMS } from '../enums/Playlist'; import { parseSongName } from '@stores/appStore'; interface Props { @@ -23,13 +24,9 @@ export const updateSubscribeFavList = async ({ callback = () => undefined, }: Props): Promise<NoxMedia.Playlist> => { let newPlaylist = { ...playlist, lastSubscribed: new Date().getTime() }; - if ( - [NoxEnum.Playlist.PlaylistEnums.TYPE_FAVORI_PLAYLIST].includes( - playlist.type - ) - ) + if ([PLAYLIST_ENUMS.TYPE_FAVORI_PLAYLIST].includes(playlist.type)) throw new Error('[biliSubscribe] incorrect playlist type for subscription'); - if (playlist.type === NoxEnum.Playlist.PlaylistEnums.TYPE_SEARCH_PLAYLIST) { + if (playlist.type === PLAYLIST_ENUMS.TYPE_SEARCH_PLAYLIST) { if (!playlist.refresh) throw new Error('[biliSubscribe] nothing to subscribe'); newPlaylist = { ...newPlaylist, ...(await playlist.refresh(newPlaylist)) }; diff --git a/src/utils/Cache.ts b/src/utils/Cache.ts index 6292dce39..6766cb809 100644 --- a/src/utils/Cache.ts +++ b/src/utils/Cache.ts @@ -11,6 +11,7 @@ import playerSettingStore from '@stores/playerSettingStore'; import { getCachedMediaMapping, saveCachedMediaMapping } from './ChromeStorage'; import { logger } from './Logger'; import { customReqHeader } from './BiliFetch'; +import { SOURCE } from '@enums/MediaFetch'; const { getState } = playerSettingStore; @@ -126,7 +127,7 @@ class NoxMediaCache { loadCacheMedia = (song: NoxMedia.Song, prefix = 'file://') => { // HACK: return song.source if song is local. - if (song.source === NoxEnum.MediaFetch.Source.Local) { + if (song.source === SOURCE.local) { // return song.bvid; } return this.loadCacheObject(noxCacheKey(song), prefix); @@ -160,7 +161,7 @@ class NoxMediaCache { }; peekCache = (song: NoxMedia.Song) => { - if (song.source === NoxEnum.MediaFetch.Source.Local) return true; + if (song.source === SOURCE.local) return true; return this.cache.peek(noxCacheKey(song)); }; diff --git a/src/utils/ChromeStorage.ts b/src/utils/ChromeStorage.ts index 24da11127..3b44d1398 100644 --- a/src/utils/ChromeStorage.ts +++ b/src/utils/ChromeStorage.ts @@ -6,8 +6,16 @@ import { Appearance, ColorSchemeName } from 'react-native'; import i18n from 'i18next'; import { dummyPlaylist, dummyPlaylistList } from '../objects/Playlist'; +import { NoxRepeatMode } from '../enums/RepeatMode'; +import { PLAYLIST_ENUMS } from '../enums/Playlist'; import AzusaTheme from '../components/styles/AzusaTheme'; import { chunkArray as chunkArrayRaw, arrayToObject } from '../utils/Utils'; +import { + STORAGE_KEYS, + appID, + DEFAULT_SETTING, + SEARCH_OPTIONS, +} from '@enums/Storage'; import { MUSICFREE } from './mediafetch/musicfree'; /** * noxplayer's storage handler. @@ -56,22 +64,22 @@ export const removeItem = async (key: string) => { }; export const setMusicFreePlugin = (val: MUSICFREE[]) => - saveItem(NoxEnum.Storage.StorageKeys.MUSICFREE_PLUGIN, val); + saveItem(STORAGE_KEYS.MUSICFREE_PLUGIN, val); export const getMusicFreePlugin = (): Promise<MUSICFREE[]> => - getItem(NoxEnum.Storage.StorageKeys.MUSICFREE_PLUGIN, []); + getItem(STORAGE_KEYS.MUSICFREE_PLUGIN, []); export const getFadeInterval = async () => - Number(await getItem(NoxEnum.Storage.StorageKeys.FADE_INTERVAL)) || 0; + Number(await getItem(STORAGE_KEYS.FADE_INTERVAL)) || 0; export const saveFadeInterval = async (val: number) => - await saveItem(NoxEnum.Storage.StorageKeys.FADE_INTERVAL, val); + await saveItem(STORAGE_KEYS.FADE_INTERVAL, val); /** * a save helper function for mapping types ({string: val}). * @returns the mapping object */ const getMapping = async ( - key: NoxEnum.Storage.StorageKeys, + key: STORAGE_KEYS, transform: (val: any) => any = arrayToObject ) => { try { @@ -87,70 +95,56 @@ const getMapping = async ( }; export const getRegExtractMapping = (): Promise<NoxRegExt.JSONExtractor[]> => - getItem(NoxEnum.Storage.StorageKeys.REGEXTRACT_MAPPING, []); + getItem(STORAGE_KEYS.REGEXTRACT_MAPPING, []); export const saveRegextractMapping = (val: NoxRegExt.JSONExtractor[]) => - saveItem(NoxEnum.Storage.StorageKeys.REGEXTRACT_MAPPING, val); + saveItem(STORAGE_KEYS.REGEXTRACT_MAPPING, val); export const getR128GainMapping = (): Promise<NoxStorage.R128Dict> => - getMapping(NoxEnum.Storage.StorageKeys.R128GAIN_MAPPING); + getMapping(STORAGE_KEYS.R128GAIN_MAPPING); export const saveR128GainMapping = (val: NoxStorage.R128Dict) => - saveChucked( - NoxEnum.Storage.StorageKeys.R128GAIN_MAPPING, - Object.entries(val) - ); + saveChucked(STORAGE_KEYS.R128GAIN_MAPPING, Object.entries(val)); export const getABMapping = (): Promise<NoxStorage.ABDict> => - getMapping(NoxEnum.Storage.StorageKeys.ABREPEAT_MAPPING); + getMapping(STORAGE_KEYS.ABREPEAT_MAPPING); export const saveABMapping = async (val: NoxStorage.ABDict) => - saveChucked( - NoxEnum.Storage.StorageKeys.ABREPEAT_MAPPING, - Object.entries(val) - ); + saveChucked(STORAGE_KEYS.ABREPEAT_MAPPING, Object.entries(val)); -export const getDefaultSearch = (): Promise<NoxEnum.Storage.SearchOptions> => - getItem( - NoxEnum.Storage.StorageKeys.DEFAULT_SEARCH, - NoxEnum.Storage.SearchOptions.BILIBILI - ); +export const getDefaultSearch = (): Promise<SEARCH_OPTIONS> => + getItem(STORAGE_KEYS.DEFAULT_SEARCH, SEARCH_OPTIONS.BILIBILI); -export const saveDefaultSearch = ( - val: NoxEnum.Storage.SearchOptions | MUSICFREE -) => saveItem(NoxEnum.Storage.StorageKeys.DEFAULT_SEARCH, val); +export const saveDefaultSearch = (val: SEARCH_OPTIONS | MUSICFREE) => + saveItem(STORAGE_KEYS.DEFAULT_SEARCH, val); export const getCachedMediaMapping = () => - getItem(NoxEnum.Storage.StorageKeys.CACHED_MEDIA_MAPPING, []); + getItem(STORAGE_KEYS.CACHED_MEDIA_MAPPING, []); export const saveCachedMediaMapping = (val: any[]) => - saveItem(NoxEnum.Storage.StorageKeys.CACHED_MEDIA_MAPPING, val); + saveItem(STORAGE_KEYS.CACHED_MEDIA_MAPPING, val); export const getColorScheme = async () => { - const colorScheme = - (await getItem(NoxEnum.Storage.StorageKeys.COLORTHEME)) || null; + const colorScheme = (await getItem(STORAGE_KEYS.COLORTHEME)) || null; Appearance.setColorScheme(colorScheme); return colorScheme; }; export const saveColorScheme = (val: ColorSchemeName) => - saveItem(NoxEnum.Storage.StorageKeys.COLORTHEME, val); + saveItem(STORAGE_KEYS.COLORTHEME, val); // we keep the set-cookie header for noxplayer's remove personal search option // TODO: security risk. move this to an encrypted storage. export const addCookie = async (site: string, setHeader: string) => { return; - const cookies = (await getItem(NoxEnum.Storage.StorageKeys.COOKIES)) || {}; - saveItem(NoxEnum.Storage.StorageKeys.COOKIES, { - ...cookies, - [site]: setHeader, - }); + const cookies = (await getItem(STORAGE_KEYS.COOKIES)) || {}; + saveItem(STORAGE_KEYS.COOKIES, { ...cookies, [site]: setHeader }); }; export const removeCookie = async (site: string) => { - const cookies = (await getItem(NoxEnum.Storage.StorageKeys.COOKIES)) || {}; + const cookies = (await getItem(STORAGE_KEYS.COOKIES)) || {}; cookies[site] = []; - saveItem(NoxEnum.Storage.StorageKeys.COOKIES, cookies); + saveItem(STORAGE_KEYS.COOKIES, cookies); }; /** @@ -237,43 +231,37 @@ export const getPlaylist = async ( }; export const savePlayerSkins = async (skins: Array<any>) => - saveChucked(NoxEnum.Storage.StorageKeys.SKINSTORAGE, skins); + saveChucked(STORAGE_KEYS.SKINSTORAGE, skins); export const getPlayerSkins = async () => - await loadChucked(await getItem(NoxEnum.Storage.StorageKeys.SKINSTORAGE, [])); + await loadChucked(await getItem(STORAGE_KEYS.SKINSTORAGE, [])); export const saveLyricMapping = async ( lyricMapping: Map<string, NoxMedia.LyricDetail> ) => - saveChucked( - NoxEnum.Storage.StorageKeys.LYRIC_MAPPING, - Array.from(lyricMapping.entries()) - ); + saveChucked(STORAGE_KEYS.LYRIC_MAPPING, Array.from(lyricMapping.entries())); export const getLyricMapping = () => - getMapping( - NoxEnum.Storage.StorageKeys.LYRIC_MAPPING, - (val: any) => new Map(val) - ); + getMapping(STORAGE_KEYS.LYRIC_MAPPING, (val: any) => new Map(val)); // no point to provide getters, as states are managed by zustand. // unlike azusaplayer which the storage context still reads localstorage, instaed // of keeping them as states. export const saveSettings = (setting: NoxStorage.PlayerSettingDict) => - saveItem(NoxEnum.Storage.StorageKeys.PLAYER_SETTING_KEY, setting); + saveItem(STORAGE_KEYS.PLAYER_SETTING_KEY, setting); export const getSettings = async () => ({ - ...NoxEnum.Storage.DefaultSetting, - ...(await getItem(NoxEnum.Storage.StorageKeys.PLAYER_SETTING_KEY, {})), + ...DEFAULT_SETTING, + ...(await getItem(STORAGE_KEYS.PLAYER_SETTING_KEY, {})), }); export const savePlaylistIds = (val: string[]) => - saveItem(NoxEnum.Storage.StorageKeys.MY_FAV_LIST_KEY, val); + saveItem(STORAGE_KEYS.MY_FAV_LIST_KEY, val); export const savePlayerSkin = (val: NoxTheme.Style | NoxTheme.AdaptiveStyle) => - saveItem(NoxEnum.Storage.StorageKeys.SKIN, val); + saveItem(STORAGE_KEYS.SKIN, val); -export const getPlayerSkin = () => getItem(NoxEnum.Storage.StorageKeys.SKIN); +export const getPlayerSkin = () => getItem(STORAGE_KEYS.SKIN); export const addPlaylist = ( playlist: NoxMedia.Playlist, @@ -305,63 +293,55 @@ export const delPlaylist = ( }; export const saveFavPlaylist = (playlist: NoxMedia.Playlist) => - savePlaylist(playlist, NoxEnum.Storage.StorageKeys.FAVORITE_PLAYLIST_KEY); + savePlaylist(playlist, STORAGE_KEYS.FAVORITE_PLAYLIST_KEY); export const savelastPlaylistId = (val: [string, string]) => - saveItem(NoxEnum.Storage.StorageKeys.LAST_PLAY_LIST, val); + saveItem(STORAGE_KEYS.LAST_PLAY_LIST, val); export const savePlayMode = (val: string) => - saveItem(NoxEnum.Storage.StorageKeys.PLAYMODE_KEY, val); + saveItem(STORAGE_KEYS.PLAYMODE_KEY, val); export const saveLastPlayDuration = (val: number) => - saveItem(NoxEnum.Storage.StorageKeys.LAST_PLAY_DURATION, val); + saveItem(STORAGE_KEYS.LAST_PLAY_DURATION, val); export const initPlayerObject = async (): Promise<NoxStorage.PlayerStorageObject> => { const lyricMapping = (await getLyricMapping()) || {}; const playerObject = { settings: { - ...NoxEnum.Storage.DefaultSetting, - ...((await getItem(NoxEnum.Storage.StorageKeys.PLAYER_SETTING_KEY)) || - {}), + ...DEFAULT_SETTING, + ...((await getItem(STORAGE_KEYS.PLAYER_SETTING_KEY)) || {}), }, - playlistIds: - (await getItem(NoxEnum.Storage.StorageKeys.MY_FAV_LIST_KEY)) || [], + playlistIds: (await getItem(STORAGE_KEYS.MY_FAV_LIST_KEY)) || [], playlists: {}, - lastPlaylistId: (await getItem( - NoxEnum.Storage.StorageKeys.LAST_PLAY_LIST - )) || ['NULL', 'NULL'], + lastPlaylistId: (await getItem(STORAGE_KEYS.LAST_PLAY_LIST)) || [ + 'NULL', + 'NULL', + ], searchPlaylist: dummyPlaylist( i18n.t('PlaylistOperations.searchListName'), - NoxEnum.Playlist.PlaylistEnums.TYPE_SEARCH_PLAYLIST + PLAYLIST_ENUMS.TYPE_SEARCH_PLAYLIST ), favoriPlaylist: await getPlaylist( - NoxEnum.Storage.StorageKeys.FAVORITE_PLAYLIST_KEY, - () => - dummyPlaylist( - 'Favorite', - NoxEnum.Playlist.PlaylistEnums.TYPE_FAVORI_PLAYLIST - ) + STORAGE_KEYS.FAVORITE_PLAYLIST_KEY, + () => dummyPlaylist('Favorite', PLAYLIST_ENUMS.TYPE_FAVORI_PLAYLIST) ), playbackMode: await getItem( - NoxEnum.Storage.StorageKeys.PLAYMODE_KEY, - NoxEnum.RNTP.NoxRepeatMode.SHUFFLE + STORAGE_KEYS.PLAYMODE_KEY, + NoxRepeatMode.SHUFFLE ), - skin: await getItem(NoxEnum.Storage.StorageKeys.SKIN, AzusaTheme), + skin: await getItem(STORAGE_KEYS.SKIN, AzusaTheme), skins: (await getPlayerSkins()) || [], - cookies: await getItem(NoxEnum.Storage.StorageKeys.COOKIES, {}), + cookies: await getItem(STORAGE_KEYS.COOKIES, {}), lyricMapping, - lastPlayDuration: await getItem( - NoxEnum.Storage.StorageKeys.LAST_PLAY_DURATION, - 0 - ), + lastPlayDuration: await getItem(STORAGE_KEYS.LAST_PLAY_DURATION, 0), colorScheme: await getColorScheme(), defaultSearchOptions: await getDefaultSearch(), } as NoxStorage.PlayerStorageObject; - playerObject.playlists[NoxEnum.Storage.StorageKeys.SEARCH_PLAYLIST_KEY] = + playerObject.playlists[STORAGE_KEYS.SEARCH_PLAYLIST_KEY] = playerObject.searchPlaylist; - playerObject.playlists[NoxEnum.Storage.StorageKeys.FAVORITE_PLAYLIST_KEY] = + playerObject.playlists[STORAGE_KEYS.FAVORITE_PLAYLIST_KEY] = playerObject.favoriPlaylist; await Promise.all( @@ -385,8 +365,7 @@ export const exportPlayerContent = async (content?: any) => { }; const clearPlaylists = async () => { - const playlistIds = - (await getItem(NoxEnum.Storage.StorageKeys.MY_FAV_LIST_KEY)) || []; + const playlistIds = (await getItem(STORAGE_KEYS.MY_FAV_LIST_KEY)) || []; for (const playlistId of playlistIds) { delPlaylistRaw(await getPlaylist(playlistId)); } @@ -410,19 +389,17 @@ const saveImportedPlaylist = async (playlists: any[]) => { export const clearPlaylistNImport = async (parsedContent: any) => { await clearPlaylists(); await saveImportedPlaylist( - parsedContent[NoxEnum.Storage.StorageKeys.MY_FAV_LIST_KEY].map( + parsedContent[STORAGE_KEYS.MY_FAV_LIST_KEY].map( (val: string) => parsedContent[val] ) ); - await savePlaylistIds( - parsedContent[NoxEnum.Storage.StorageKeys.MY_FAV_LIST_KEY] - ); + await savePlaylistIds(parsedContent[STORAGE_KEYS.MY_FAV_LIST_KEY]); }; export const addImportedPlaylist = async (playlists: any[]) => { await saveImportedPlaylist(playlists); await savePlaylistIds( - (await getItem(NoxEnum.Storage.StorageKeys.MY_FAV_LIST_KEY)).concat( + (await getItem(STORAGE_KEYS.MY_FAV_LIST_KEY)).concat( playlists.map(val => val.info.id) ) ); @@ -439,10 +416,10 @@ const parseImportedPartial = ( export const importPlayerContentRaw = async (parsedContent: any) => { const importedAppID = parseImportedPartial( - NoxEnum.Storage.StorageKeys.PLAYER_SETTING_KEY, + STORAGE_KEYS.PLAYER_SETTING_KEY, parsedContent ).appID; - if (importedAppID !== NoxEnum.Storage.AppID) { + if (importedAppID !== appID) { throw new Error(`${importedAppID} is not valid appID`); } else { const oldCache = await getCachedMediaMapping(); diff --git a/src/utils/mediafetch/biliAudioAM.ts b/src/utils/mediafetch/biliAudioAM.ts index 08546812b..dccaed807 100644 --- a/src/utils/mediafetch/biliAudioAM.ts +++ b/src/utils/mediafetch/biliAudioAM.ts @@ -3,6 +3,7 @@ import { logger } from '../Logger'; import { regexFetchProps } from './generic'; import { fetchBiliPaginatedAPI } from './paginatedbili'; +import { SOURCE } from '@enums/MediaFetch'; import SongTS from '@objects/Song'; /** @@ -77,7 +78,7 @@ const fetchBiliAudioColleList = async ( resolveBiliBVID: async v => v.map((data: any) => SongTS({ - cid: `${NoxEnum.MediaFetch.Source.Biliaudio}-${data.id}`, + cid: `${SOURCE.biliaudio}-${data.id}`, bvid: data.id, name: data.title, nameRaw: data.title, @@ -88,7 +89,7 @@ const fetchBiliAudioColleList = async ( page: 1, duration: data.duration, album: data.title, - source: NoxEnum.MediaFetch.Source.Biliaudio, + source: SOURCE.biliaudio, }) ), }); diff --git a/src/utils/mediafetch/biliAudioColle.ts b/src/utils/mediafetch/biliAudioColle.ts index b7e0bb344..28bebbc3d 100644 --- a/src/utils/mediafetch/biliAudioColle.ts +++ b/src/utils/mediafetch/biliAudioColle.ts @@ -4,6 +4,7 @@ import { logger } from '../Logger'; import { regexFetchProps } from './generic'; import { fetchBiliPaginatedAPI } from './paginatedbili'; import { getBiliCookie } from '@utils/Bilibili/biliCookies'; +import { SOURCE } from '@enums/MediaFetch'; import SongTS from '@objects/Song'; /** @@ -78,7 +79,7 @@ const fetchBiliAudioColleList = async ( resolveBiliBVID: async v => v.map((data: any) => SongTS({ - cid: `${NoxEnum.MediaFetch.Source.Biliaudio}-${data.id}`, + cid: `${SOURCE.biliaudio}-${data.id}`, bvid: data.id, name: data.title, nameRaw: data.title, @@ -89,7 +90,7 @@ const fetchBiliAudioColleList = async ( page: 1, duration: data.duration, album: data.title, - source: NoxEnum.MediaFetch.Source.Biliaudio, + source: SOURCE.biliaudio, }) ), params: { diff --git a/src/utils/mediafetch/biliAudioSimilar.ts b/src/utils/mediafetch/biliAudioSimilar.ts index f1bd23d63..e44d4f202 100644 --- a/src/utils/mediafetch/biliAudioSimilar.ts +++ b/src/utils/mediafetch/biliAudioSimilar.ts @@ -12,6 +12,7 @@ import { logger } from '../Logger'; import { regexFetchProps } from './generic'; import bfetch from '@utils/BiliFetch'; +import { SOURCE } from '@enums/MediaFetch'; import SongTS from '@objects/Song'; /** @@ -69,7 +70,7 @@ const fetchBiliAudioSimilarList = async ( const json = await res.json(); return json.data.map((data: any) => SongTS({ - cid: `${NoxEnum.MediaFetch.Source.Biliaudio}-${data.id}`, + cid: `${SOURCE.biliaudio}-${data.id}`, bvid: data.id, name: data.title, nameRaw: data.title, @@ -80,7 +81,7 @@ const fetchBiliAudioSimilarList = async ( page: 1, duration: data.duration, album: data.title, - source: NoxEnum.MediaFetch.Source.Biliaudio, + source: SOURCE.biliaudio, }) ); }; diff --git a/src/utils/mediafetch/biliBangumi.ts b/src/utils/mediafetch/biliBangumi.ts index 48db807a7..7b34ec4fa 100644 --- a/src/utils/mediafetch/biliBangumi.ts +++ b/src/utils/mediafetch/biliBangumi.ts @@ -13,11 +13,12 @@ import { regexFetchProps } from './generic'; import SongTS from '@objects/Song'; import { logger } from '../Logger'; import bfetch from '@utils/BiliFetch'; +import { SOURCE } from '@enums/MediaFetch'; const API = 'https://api.bilibili.com/pgc/view/web/season?ep_id={ep}'; const API_PLAY = 'https://api.bilibili.com/pgc/player/web/playurl?cid={cid}&ep_id={ep}'; -const CIDPREFIX = `${NoxEnum.MediaFetch.Source.BiliBangumi}-`; +const CIDPREFIX = `${SOURCE.biliBangumi}-`; const fetchPlayUrlPromise = async (cid: string, epid: string) => { try { @@ -54,7 +55,7 @@ const regexFetch = async ({ page: 1, duration: ep.duration, album: ep.share_copy, - source: NoxEnum.MediaFetch.Source.BiliBangumi, + source: SOURCE.biliBangumi, }) ), }; diff --git a/src/utils/mediafetch/biliDynamic.ts b/src/utils/mediafetch/biliDynamic.ts index 7b737f9a4..52edbec69 100644 --- a/src/utils/mediafetch/biliDynamic.ts +++ b/src/utils/mediafetch/biliDynamic.ts @@ -1,6 +1,7 @@ import { logger } from '../Logger'; import SongTS from '@objects/Song'; import bfetch from '@utils/BiliFetch'; +import { BiliMusicTid, SOURCE } from '@enums/MediaFetch'; import { biliApiLimiter } from './throttle'; const API = @@ -19,7 +20,7 @@ const dynamicToSong = (data: any) => page: 1, duration: data.duration, album: data.title, - source: NoxEnum.MediaFetch.Source.Bilivideo, + source: SOURCE.bilivideo, }); export const fetchDynamic = async (rid = '3', page = 1) => { @@ -31,7 +32,7 @@ export const fetchDynamic = async (rid = '3', page = 1) => { const json = await res.json(); const results = {} as { [key: number]: NoxMedia.Song[] }; json.data.archives.forEach((v: any) => { - if (!NoxEnum.MediaFetch.BiliMusicTid.includes(v.tid)) return; + if (!BiliMusicTid.includes(v.tid)) return; if (results[v.tid]) { results[v.tid].push(dynamicToSong(v)); } else { diff --git a/src/utils/mediafetch/biliRanking.ts b/src/utils/mediafetch/biliRanking.ts index f0109d45e..42244908d 100644 --- a/src/utils/mediafetch/biliRanking.ts +++ b/src/utils/mediafetch/biliRanking.ts @@ -1,6 +1,7 @@ import { logger } from '../Logger'; import SongTS from '@objects/Song'; import bfetch from '@utils/BiliFetch'; +import { SOURCE, BiliMusicTid } from '@enums/MediaFetch'; import { biliApiLimiter } from './throttle'; const API = 'https://api.bilibili.com/x/web-interface/ranking/v2?rid={rid}'; @@ -18,7 +19,7 @@ const rankingToSong = (data: any) => page: 1, duration: data.duration, album: data.title, - source: NoxEnum.MediaFetch.Source.Bilivideo, + source: SOURCE.bilivideo, }); export const fetchRanking = async (rid = '3') => { @@ -30,7 +31,7 @@ export const fetchRanking = async (rid = '3') => { const json = await res.json(); const results = {} as { [key: number]: NoxMedia.Song[] }; json.data.list.forEach((v: any) => { - if (!NoxEnum.MediaFetch.BiliMusicTid.includes(v.tid)) return; + if (!BiliMusicTid.includes(v.tid)) return; if (results[v.tid]) { results[v.tid].push(rankingToSong(v)); } else { diff --git a/src/utils/mediafetch/biliVideoSimilar.ts b/src/utils/mediafetch/biliVideoSimilar.ts index b839377d9..e6c1b6d64 100644 --- a/src/utils/mediafetch/biliVideoSimilar.ts +++ b/src/utils/mediafetch/biliVideoSimilar.ts @@ -3,6 +3,7 @@ import { logger } from '../Logger'; import { regexFetchProps } from './generic'; import bfetch from '@utils/BiliFetch'; +import { SOURCE, BiliMusicTid } from '@enums/MediaFetch'; import SongTS from '@objects/Song'; import { fetchBVID } from './bilivideo'; @@ -19,7 +20,7 @@ const fetchBiliVideoSimilarList = async (bvid: string) => { return (await fetchBVID(bvid)).concat( json.data // limit similar videos to music only. - .filter((v: any) => NoxEnum.MediaFetch.BiliMusicTid.includes(v.tid)) + .filter((v: any) => BiliMusicTid.includes(v.tid)) .map((data: any) => SongTS({ cid: data.cid, @@ -33,7 +34,7 @@ const fetchBiliVideoSimilarList = async (bvid: string) => { page: 1, duration: data.duration, album: data.title, - source: NoxEnum.MediaFetch.Source.Bilivideo, + source: SOURCE.bilivideo, }) ) ); diff --git a/src/utils/mediafetch/biliaudio.ts b/src/utils/mediafetch/biliaudio.ts index b69c7b0f3..5c5b73734 100644 --- a/src/utils/mediafetch/biliaudio.ts +++ b/src/utils/mediafetch/biliaudio.ts @@ -13,13 +13,14 @@ import { regexFetchProps } from './generic'; import SongTS from '@objects/Song'; import { logger } from '../Logger'; import bfetch from '@utils/BiliFetch'; +import { SOURCE } from '@enums/MediaFetch'; import { biliApiLimiter } from './throttle'; const URL_AUDIO_INFO = 'https://www.bilibili.com/audio/music-service-c/web/song/info?sid={sid}'; const URL_AUDIO_PLAY_URL = 'https://www.bilibili.com/audio/music-service-c/web/url?sid={sid}'; -const CIDPREFIX = `${NoxEnum.MediaFetch.Source.Biliaudio}-`; +const CIDPREFIX = `${SOURCE.biliaudio}-`; const fetchPlayUrlPromise = async (sid: string) => { try { @@ -56,7 +57,7 @@ export const baFetch = async (auids: string[]) => { page: 1, duration: data.duration, album: data.title, - source: NoxEnum.MediaFetch.Source.Biliaudio, + source: SOURCE.biliaudio, }); }) ) diff --git a/src/utils/mediafetch/biliavideo.ts b/src/utils/mediafetch/biliavideo.ts index 487810861..2a5f58689 100644 --- a/src/utils/mediafetch/biliavideo.ts +++ b/src/utils/mediafetch/biliavideo.ts @@ -4,6 +4,7 @@ import { biliApiLimiter } from './throttle'; import { logger } from '../Logger'; import bfetch from '@utils/BiliFetch'; import { biliShazamOnSonglist } from './bilishazam'; +import { SOURCE } from '@enums/MediaFetch'; import SongTS from '@objects/Song'; const URL_VIDEO_INFO = @@ -31,7 +32,7 @@ const fetchAVIDRaw = async (aid: string): Promise<NoxMedia.Song[]> => { page: index + 1, duration: page.duration, album: data.title, - source: NoxEnum.MediaFetch.Source.Bilivideo, + source: SOURCE.bilivideo, }); }); // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/src/utils/mediafetch/bilichannelAudio.ts b/src/utils/mediafetch/bilichannelAudio.ts index 2cbc72481..40d9b4455 100644 --- a/src/utils/mediafetch/bilichannelAudio.ts +++ b/src/utils/mediafetch/bilichannelAudio.ts @@ -9,16 +9,18 @@ * steps to refactor: * each site needs a fetch to parse regex extracted, a videoinfo fetcher and a song fetcher. */ +import { SOURCE } from '@enums/MediaFetch'; import { logger } from '../Logger'; import { regexFetchProps } from './generic'; import { fetchAwaitBiliPaginatedAPI } from './paginatedbili'; import { awaitLimiter } from './throttle'; import SongTS from '@objects/Song'; +import { info } from 'console'; // https://api.bilibili.com/audio/music-service/web/song/upper?uid=741520&pn=1&ps=70&order=1 const URL_BILICHANNEL_AUDIO_INFO = 'https://api.bilibili.com/audio/music-service/web/song/upper?uid=741520&pn={pn}&ps=30&order=1'; -const CIDPREFIX = `${NoxEnum.MediaFetch.Source.Biliaudio}-`; +const CIDPREFIX = `${SOURCE.biliaudio}-`; export const fetchBiliChannelAudioList = async ( mid: string, @@ -48,7 +50,7 @@ export const fetchBiliChannelAudioList = async ( page: 1, duration: info.duration, album: info.title, - source: NoxEnum.MediaFetch.Source.Biliaudio, + source: SOURCE.biliaudio, }) ), }); diff --git a/src/utils/mediafetch/bililive.ts b/src/utils/mediafetch/bililive.ts index 88366fe79..97bd1a426 100644 --- a/src/utils/mediafetch/bililive.ts +++ b/src/utils/mediafetch/bililive.ts @@ -4,6 +4,7 @@ import SongTS from '@objects/Song'; import { logger } from '../Logger'; import bfetch from '@utils/BiliFetch'; import { biliApiLimiter } from './throttle'; +import { SOURCE } from '@enums/MediaFetch'; interface BiliLiveRoomInfo { room_id: string; @@ -47,14 +48,14 @@ const fetchVideoInfoRaw = async (aid: string) => { const roomInfo = await getRoomInfo(aid); const liverInfo = await getLiver(roomInfo.room_id); return SongTS({ - cid: `${NoxEnum.MediaFetch.Source.BiliLive}-${roomInfo.room_id}`, + cid: `${SOURCE.biliLive}-${roomInfo.room_id}`, bvid: roomInfo.room_id, name: roomInfo.title, singer: liverInfo.uname, cover: roomInfo.user_cover, singerId: aid, album: `b站直播间${aid}`, - source: NoxEnum.MediaFetch.Source.BiliLive, + source: SOURCE.biliLive, isLive: true, liveStatus: roomInfo.live_status === 1, }); diff --git a/src/utils/mediafetch/bilisearch.ts b/src/utils/mediafetch/bilisearch.ts index 88472e1bc..0c2f2b08a 100644 --- a/src/utils/mediafetch/bilisearch.ts +++ b/src/utils/mediafetch/bilisearch.ts @@ -4,6 +4,7 @@ import { timestampToSeconds } from '../Utils'; import bfetch from '../BiliFetch'; import { getBiliCookie } from '@utils/Bilibili/biliCookies'; import SongTS from '@objects/Song'; +import { SOURCE } from '@enums/MediaFetch'; const URL_BILI_SEARCH = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={keyword}&page={pn}&tids=3'; @@ -47,7 +48,7 @@ const fastSearchResolveBVID = async (bvobjs: any[]) => { page: 1, duration: timestampToSeconds(obj.duration), album: name, - source: NoxEnum.MediaFetch.Source.Bilivideo, + source: SOURCE.bilivideo, }); }); }; diff --git a/src/utils/mediafetch/bilisublive.ts b/src/utils/mediafetch/bilisublive.ts index 7cda9de93..ac351c268 100644 --- a/src/utils/mediafetch/bilisublive.ts +++ b/src/utils/mediafetch/bilisublive.ts @@ -4,6 +4,7 @@ import axios from 'axios'; import { regexFetchProps } from './generic'; import SongTS from '@objects/Song'; import { logger } from '../Logger'; +import { SOURCE } from '@enums/MediaFetch'; import { fetchBiliPaginatedAPI } from './paginatedbili'; // https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/live/info.md#%E6%89%B9%E9%87%8F%E6%9F%A5%E8%AF%A2%E7%9B%B4%E6%92%AD%E9%97%B4%E7%8A%B6%E6%80%81 @@ -32,9 +33,9 @@ const getRoomInfos = async (uids: number[]) => { .map( (roomInfo: any) => SongTS({ - cid: `${NoxEnum.MediaFetch.Source.BiliLive}-${roomInfo.room_id}`, + cid: `${SOURCE.biliLive}-${roomInfo.room_id}`, bvid: roomInfo.room_id, - source: NoxEnum.MediaFetch.Source.BiliLive, + source: SOURCE.biliLive, name: roomInfo.title, singer: roomInfo.uname, singerId: roomInfo.uid, diff --git a/src/utils/mediafetch/bilivideo.ts b/src/utils/mediafetch/bilivideo.ts index 26008d9f9..b6aded5a1 100644 --- a/src/utils/mediafetch/bilivideo.ts +++ b/src/utils/mediafetch/bilivideo.ts @@ -7,6 +7,7 @@ import { biliShazamOnSonglist } from './bilishazam'; import SongTS from '@objects/Song'; import { logger } from '../Logger'; import bfetch from '@utils/BiliFetch'; +import { SOURCE } from '@enums/MediaFetch'; export enum FieldEnum { AudioUrl = 'AudioUrl', @@ -44,7 +45,7 @@ const fetchBVIDRaw = async (bvid: string): Promise<NoxMedia.Song[]> => { page: index + 1, duration: page.duration, album: data.title, - source: NoxEnum.MediaFetch.Source.Bilivideo, + source: SOURCE.bilivideo, }); }); } catch (error: any) { @@ -200,9 +201,7 @@ const extractResponseJson = (json: any, field: string) => { case FieldEnum.AudioInfo: return {}; default: - throw new Error( - `invalid field type: ${field} to parse JSON response from ${json}` - ); + throw new Error(`invalid field type: ${field} to parse JSON response from ${json}`); } }; diff --git a/src/utils/mediafetch/local.ts b/src/utils/mediafetch/local.ts index 4de83d186..17b500c23 100644 --- a/src/utils/mediafetch/local.ts +++ b/src/utils/mediafetch/local.ts @@ -13,6 +13,7 @@ import { Platform, NativeModules } from 'react-native'; import RNFetchBlob from 'react-native-blob-util'; import { probeMetadata, cacheAlbumArt } from '@utils/ffmpeg/ffmpeg'; +import { SOURCE } from '@enums/MediaFetch'; import { regexFetchProps } from './generic'; import SongTS from '@objects/Song'; import logger from '../Logger'; @@ -32,7 +33,7 @@ const songFetch = async ( const uniqMediaFiles = mediaFiles.filter(v => !favlist.includes(v.realPath)); return uniqMediaFiles.map(v => SongTS({ - cid: `${NoxEnum.MediaFetch.Source.Local}-${v.realPath}`, + cid: `${SOURCE.local}-${v.realPath}`, bvid: `file://${v.realPath}`, name: v.title, nameRaw: v.title, @@ -43,7 +44,7 @@ const songFetch = async ( page: 0, duration: v.duration / 1000, album: v.album, - source: NoxEnum.MediaFetch.Source.Local, + source: SOURCE.local, }) ); // TODO: no longer needs FFProbe @@ -60,7 +61,7 @@ const songFetch = async ( logger.warn(v); } return SongTS({ - cid: `${NoxEnum.MediaFetch.Source.Local}-${v.realPath}`, + cid: `${SOURCE.local}-${v.realPath}`, bvid: `file://${v.realPath}`, name: probedMetadata.tags?.title || v.fileName, nameRaw: probedMetadata.tags?.title || v.fileName, @@ -71,7 +72,7 @@ const songFetch = async ( page: 0, duration: Number(probedMetadata.duration) || 0, album: probedMetadata.tags?.album || '', - source: NoxEnum.MediaFetch.Source.Local, + source: SOURCE.local, }); }) ); diff --git a/src/utils/mediafetch/steriatk.ts b/src/utils/mediafetch/steriatk.ts index e187ad53c..c396e1c8f 100644 --- a/src/utils/mediafetch/steriatk.ts +++ b/src/utils/mediafetch/steriatk.ts @@ -8,6 +8,7 @@ * steps to refactor: * each site needs a fetch to parse regex extracted, a videoinfo fetcher and a song fetcher. */ +import { SOURCE } from '@enums/MediaFetch'; import { regexFetchProps } from './generic'; import { fetchAwaitPaginatedAPI } from './paginatedfetch'; import SongTS from '@objects/Song'; @@ -42,7 +43,7 @@ const paginatedFetch = ({ page: 0, duration: 0, album: videoinfo.name, - source: NoxEnum.MediaFetch.Source.Steriatk, + source: SOURCE.steriatk, }) ), progressEmitter, diff --git a/src/utils/mediafetch/ytbchannel.ts b/src/utils/mediafetch/ytbchannel.ts index 351c49472..39530b1ab 100644 --- a/src/utils/mediafetch/ytbchannel.ts +++ b/src/utils/mediafetch/ytbchannel.ts @@ -4,6 +4,7 @@ import { get_playlist } from 'libmuse'; import { regexFetchProps } from './generic'; import { CIDPREFIX } from './ytbvideo'; import SongTS from '@objects/Song'; +import { SOURCE } from '@enums/MediaFetch'; const musePlaylistItemToNoxSong = (val: any, data: any) => { try { @@ -20,7 +21,7 @@ const musePlaylistItemToNoxSong = (val: any, data: any) => { page: 1, duration: val.duration_seconds, album: data.title, - source: NoxEnum.MediaFetch.Source.Ytbvideo, + source: SOURCE.ytbvideo, metadataOnLoad: true, }); } catch { diff --git a/src/utils/mediafetch/ytbmixlist.ts b/src/utils/mediafetch/ytbmixlist.ts index 503a1aea7..dc2ebf2b6 100644 --- a/src/utils/mediafetch/ytbmixlist.ts +++ b/src/utils/mediafetch/ytbmixlist.ts @@ -2,6 +2,7 @@ import { regexFetchProps } from './generic'; import { CIDPREFIX } from './ytbvideo'; import SongTS from '@objects/Song'; import { timestampToSeconds } from '../Utils'; +import { SOURCE } from '@enums/MediaFetch'; const fetchYTPlaylist = async ( playlistId: string, @@ -45,7 +46,7 @@ const fetchYTPlaylist = async ( ), album: data.contents.twoColumnWatchNextResults.playlist.playlist.title, - source: NoxEnum.MediaFetch.Source.Ytbvideo, + source: SOURCE.ytbvideo, metadataOnLoad: true, }), ]) diff --git a/src/utils/mediafetch/ytbplaylist.ts b/src/utils/mediafetch/ytbplaylist.ts index 137f7db48..10727d1af 100644 --- a/src/utils/mediafetch/ytbplaylist.ts +++ b/src/utils/mediafetch/ytbplaylist.ts @@ -5,6 +5,7 @@ import { regexFetchProps } from './generic'; import { fetchAudioInfo, CIDPREFIX } from './ytbvideo'; import SongTS from '@objects/Song'; import { logger } from '../Logger'; +import { SOURCE } from '@enums/MediaFetch'; const musePlaylistItemToNoxSong = (val: any, data: any) => { try { @@ -20,7 +21,7 @@ const musePlaylistItemToNoxSong = (val: any, data: any) => { page: 1, duration: val.duration_seconds, album: data.title, - source: NoxEnum.MediaFetch.Source.Ytbvideo, + source: SOURCE.ytbvideo, metadataOnLoad: true, }); } catch { @@ -75,7 +76,7 @@ const fastYTPlaylistSongResolve = (val: any, data: any) => { page: Number(val.playlistVideoRenderer.index.simpleText), duration: Number(val.playlistVideoRenderer.lengthSeconds), album: data.metadata.playlistMetadataRenderer.title, - source: NoxEnum.MediaFetch.Source.Ytbvideo, + source: SOURCE.ytbvideo, metadataOnLoad: true, }); } catch (e) { diff --git a/src/utils/mediafetch/ytbsearch.ts b/src/utils/mediafetch/ytbsearch.ts index f62556e73..fd3b92e1f 100644 --- a/src/utils/mediafetch/ytbsearch.ts +++ b/src/utils/mediafetch/ytbsearch.ts @@ -3,6 +3,7 @@ import { search } from 'libmuse'; import { CIDPREFIX } from './ytbvideo'; import SongTS from '@objects/Song'; +import { SOURCE } from '@enums/MediaFetch'; const musePlaylistItemToNoxSong = (val: any, data: any) => { try { @@ -18,7 +19,7 @@ const musePlaylistItemToNoxSong = (val: any, data: any) => { page: 1, duration: val.duration_seconds, album: data.title, - source: NoxEnum.MediaFetch.Source.Ytbvideo, + source: SOURCE.ytbvideo, metadataOnLoad: true, }); } catch { diff --git a/src/utils/mediafetch/ytbvideo.ts b/src/utils/mediafetch/ytbvideo.ts index 1984ee52a..ce94d762e 100644 --- a/src/utils/mediafetch/ytbvideo.ts +++ b/src/utils/mediafetch/ytbvideo.ts @@ -15,6 +15,7 @@ import { biliApiLimiter } from './throttle'; import SongTS from '@objects/Song'; import { logger } from '../Logger'; +import { SOURCE } from '@enums/MediaFetch'; export const CIDPREFIX = 'youtube-'; @@ -180,7 +181,7 @@ const fetchAudioInfoRaw = async (sid: string) => { ) : 0, album: videoDetails.title, - source: NoxEnum.MediaFetch.Source.Ytbvideo, + source: SOURCE.ytbvideo, metadataOnLoad: true, }), ]; @@ -241,7 +242,7 @@ const suggest = async (song: NoxMedia.Song, filterMW = <T>(v: T[]) => v[0]) => { page: 1, duration: Number(suggestSong.length_seconds), album: suggestSong.title, - source: NoxEnum.MediaFetch.Source.Ytbvideo, + source: SOURCE.ytbvideo, metadataOnLoad: true, }) ); diff --git a/src/utils/playlistOperations.ts b/src/utils/playlistOperations.ts index e87a370e3..44019e759 100644 --- a/src/utils/playlistOperations.ts +++ b/src/utils/playlistOperations.ts @@ -1,3 +1,5 @@ +import { SORT_OPTIONS } from '@enums/Playlist'; + export const updatePlaylistSongs = ( playlist: NoxMedia.Playlist, addSongs: Array<NoxMedia.Song> = [], @@ -15,12 +17,11 @@ export const updatePlaylistSongs = ( export const sortPlaylist = ( playlist: NoxMedia.Playlist, - sort: NoxEnum.Playlist.SortOptions = NoxEnum.Playlist.SortOptions - .PREVIOUS_ORDER, + sort: SORT_OPTIONS = SORT_OPTIONS.PREVIOUS_ORDER, ascend = false ): NoxMedia.Playlist => { playlist.sort = sort; - if (NoxEnum.Playlist.SortOptions.PREVIOUS_ORDER === sort) { + if (SORT_OPTIONS.PREVIOUS_ORDER === sort) { // first get the largest order number in the songlist: let largestOrder = 0; let songsWithoutOrder = 1; @@ -55,7 +56,7 @@ export const sortPlaylist = ( (song, index) => (song.order = songListLength - index) ); switch (sort) { - case NoxEnum.Playlist.SortOptions.TITLE: + case SORT_OPTIONS.TITLE: return { ...playlist, songList: playlist.songList.sort((a, b) => @@ -64,7 +65,7 @@ export const sortPlaylist = ( : b.parsedName.localeCompare(a.parsedName) ), }; - case NoxEnum.Playlist.SortOptions.ARTIST: + case SORT_OPTIONS.ARTIST: return { ...playlist, songList: playlist.songList.sort((a, b) => @@ -73,7 +74,7 @@ export const sortPlaylist = ( : b.singer.localeCompare(a.singer) ), }; - case NoxEnum.Playlist.SortOptions.ALBUM: + case SORT_OPTIONS.ALBUM: return { ...playlist, songList: playlist.songList.sort((a, b) => diff --git a/src/utils/re.ts b/src/utils/re.ts index 47e1b315d..fcd8de20b 100644 --- a/src/utils/re.ts +++ b/src/utils/re.ts @@ -1,9 +1,12 @@ +import { REOPERATIONTYPE } from '@enums/Utils'; +import { SearchRegex } from '@enums/Playlist'; + const operation2RegExtractor = (operation: NoxRegExt.Operation) => { const regExps = operation[1]?.map(val => new RegExp(val)); switch (operation[0]) { - case NoxEnum.Util.RegexType.extractWith: + case REOPERATIONTYPE.extractWith: return (val: string) => extractWith(val, regExps); - case NoxEnum.Util.RegexType.extractParenthesis: + case REOPERATIONTYPE.extractParenthesis: return (val: string) => extractParenthesis(val); default: return (val: string) => val; @@ -94,17 +97,17 @@ interface reExtract { const reExtractionsDefault: reExtract[] = [ { - regex: NoxEnum.Playlist.SearchRegex.absoluteMatch.regex, + regex: SearchRegex.absoluteMatch.regex, process: (val: RegExpExecArray, someRows: Array<NoxMedia.Song>) => someRows.filter(row => row.parsedName === val[1]), }, { - regex: NoxEnum.Playlist.SearchRegex.artistMatch.regex, + regex: SearchRegex.artistMatch.regex, process: (val: RegExpExecArray, someRows: Array<NoxMedia.Song>) => someRows.filter(row => row.singer.includes(val[1])), }, { - regex: NoxEnum.Playlist.SearchRegex.albumMatch.regex, + regex: SearchRegex.albumMatch.regex, process: (val: RegExpExecArray, someRows: Array<NoxMedia.Song>) => someRows.filter(row => row.album?.includes(val[1])), },