Skip to content

Commit

Permalink
Release v0.4.2
Browse files Browse the repository at this point in the history
Release v0.4.2
  • Loading branch information
maotoumao committed Sep 18, 2024
2 parents 8316632 + 2161eee commit 1804561
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "MusicFree",
"version": "0.4.1",
"version": "0.4.2",
"private": true,
"license": "AGPL",
"author": {
Expand Down
6 changes: 6 additions & 0 deletions src/components/musicBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ function CircularPlayBtn() {
accessibilityLabel={'播放或暂停歌曲'}
name={isPaused ? 'play' : 'pause'}
sizeType={'normal'}
hitSlop={{
top: 10,
left: 10,
right: 10,
bottom: 10,
}}
color={colors.musicBarText}
onPress={async () => {
if (isPaused) {
Expand Down
1 change: 1 addition & 0 deletions src/constants/pathConst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default {
imageCachePath: CachesDirectoryPath + '/image_manager_disk_cache',
localLrcPath: `${basePath}/local_lrc/`,
lrcCachePath: `${basePath}/cache/lrc/`,
downloadCachePath: `${basePath}/cache/download/`,
downloadPath: `${basePath}/download/`,
downloadMusicPath: `${basePath}/download/music/`,
mmkvPath: `${basePath}/mmkv`,
Expand Down
22 changes: 19 additions & 3 deletions src/core/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import StateMapper from '@/utils/stateMapper';
import Toast from '@/utils/toast';
import {produce} from 'immer';
import {InteractionManager} from 'react-native';
import {downloadFile, exists} from 'react-native-fs';
import {copyFile, downloadFile, exists, unlink} from 'react-native-fs';

import Config from './config';
import LocalMusicSheet from './localMusicSheet';
Expand All @@ -25,6 +25,7 @@ import {
hideDialog,
showDialog,
} from '@/components/dialogs/useDialog';
import {nanoid} from 'nanoid';

/** 队列中的元素 */
interface IDownloadMusicOptions {
Expand Down Expand Up @@ -68,7 +69,7 @@ const getExtensionName = (url: string) => {
};

/** 生成下载文件 */
const getDownloadPath = (fileName?: string) => {
const getDownloadPath = (fileName: string) => {
const dlPath =
Config.get('setting.basic.downloadPath') ?? pathConst.downloadMusicPath;
if (!dlPath.endsWith('/')) {
Expand All @@ -77,6 +78,14 @@ const getDownloadPath = (fileName?: string) => {
return fileName ? dlPath + fileName : dlPath;
};

const getCacheDownloadPath = (fileName: string) => {
const cachePath = pathConst.downloadCachePath;
if (!cachePath.endsWith('/')) {
return `${cachePath}/${fileName ?? ''}`;
}
return fileName ? cachePath + fileName : cachePath;
};

/** 从待下载中移除 */
function removeFromPendingQueue(item: IDownloadMusicOptions) {
const targetIndex = pendingMusicQueue.findIndex(_ =>
Expand Down Expand Up @@ -222,12 +231,15 @@ async function downloadNext() {
extension = 'mp3';
}
/** 目标下载地址 */
const cacheDownloadPath = addFileScheme(
getCacheDownloadPath(`${nanoid()}.${extension}`),
);
const targetDownloadPath = addFileScheme(
getDownloadPath(`${nextDownloadItem.filename}.${extension}`),
);
const {promise, jobId} = downloadFile({
fromUrl: url ?? '',
toFile: targetDownloadPath,
toFile: cacheDownloadPath,
headers: headers,
background: true,
begin(res) {
Expand Down Expand Up @@ -256,8 +268,10 @@ async function downloadNext() {
if (!folderExists) {
await mkdirR(folder);
}

try {
await promise;
await copyFile(cacheDownloadPath, targetDownloadPath);
/** 下载完成 */
LocalMusicSheet.addMusicDraft({
...musicItem,
Expand Down Expand Up @@ -301,6 +315,8 @@ async function downloadNext() {
targetDownloadPath: targetDownloadPath,
});
hasError = true;
} finally {
await unlink(cacheDownloadPath);
}
removeFromDownloadingQueue(nextDownloadItem);
downloadingProgress = produce(downloadingProgress, draft => {
Expand Down
1 change: 0 additions & 1 deletion src/core/localMusicSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ function localMediaFilter(filename: string) {
let importToken: string | null = null;
// 获取本地的文件列表
async function getMusicStats(folderPaths: string[]) {
console.log('GGGG', folderPaths);
const _importToken = nanoid();
importToken = _importToken;
const musicList: string[] = [];
Expand Down
28 changes: 18 additions & 10 deletions src/core/pluginManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import RNFS, {
exists,
readDir,
readFile,
stat,
unlink,
writeFile,
} from 'react-native-fs';
Expand Down Expand Up @@ -39,7 +40,6 @@ import CookieManager from '@react-native-cookies/cookies';
import he from 'he';
import Network from './network';
import LocalMusicSheet from './localMusicSheet';
import {getInfoAsync} from 'expo-file-system';
import Mp3Util from '@/native/mp3Util';
import {PluginMeta} from './pluginMeta';
import {useEffect, useState} from 'react';
Expand Down Expand Up @@ -253,15 +253,18 @@ export class Plugin {
return true;
}
}

//#endregion

//#region 基于插件类封装的方法,供给APP侧直接调用
/** 有缓存等信息 */
class PluginMethods implements IPlugin.IPluginInstanceMethods {
private plugin;

constructor(plugin: Plugin) {
this.plugin = plugin;
}

/** 搜索 */
async search<T extends ICommon.SupportMediaType>(
query: string,
Expand Down Expand Up @@ -308,7 +311,7 @@ class PluginMethods implements IPlugin.IPluginInstanceMethods {
LocalMusicSheet.isLocalMusic(musicItem),
InternalDataType.LOCALPATH,
);
if (localPath && (await getInfoAsync(localPath)).exists) {
if (localPath && (await exists(localPath))) {
trace('本地播放', localPath);
if (mediaExtra && mediaExtra.localPath !== localPath) {
// 修正一下本地数据
Expand Down Expand Up @@ -801,6 +804,7 @@ class PluginMethods implements IPlugin.IPluginInstanceMethods {
return [];
}
}

/** 导入单曲 */
async importMusicItem(urlLike: string): Promise<IMusic.IMusicItem | null> {
try {
Expand All @@ -818,6 +822,7 @@ class PluginMethods implements IPlugin.IPluginInstanceMethods {
return null;
}
}

/** 获取榜单 */
async getTopLists(): Promise<IMusic.IMusicSheetGroupItem[]> {
try {
Expand All @@ -831,6 +836,7 @@ class PluginMethods implements IPlugin.IPluginInstanceMethods {
return [];
}
}

/** 获取榜单详情 */
async getTopListDetail(
topListItem: IMusic.IMusicSheetItemBase,
Expand Down Expand Up @@ -879,6 +885,7 @@ class PluginMethods implements IPlugin.IPluginInstanceMethods {
};
}
}

/** 获取某个tag的推荐歌单 */
async getRecommendSheetsByTag(
tagItem: ICommon.IUnique,
Expand Down Expand Up @@ -1018,18 +1025,19 @@ const localFilePlugin = new Plugin(function () {
},
async importMusicItem(urlLike) {
let meta: any = {};
let id: string;

try {
meta = await Mp3Util.getBasicMeta(urlLike);
} catch {}
const stat = await getInfoAsync(urlLike, {
md5: true,
});
let id: string;
if (stat.exists) {
id = stat.md5 || nanoid();
} else {
const fileStat = await stat(urlLike);
id =
CryptoJs.MD5(fileStat.originalFilepath).toString(
CryptoJs.enc.Hex,
) || nanoid();
} catch {
id = nanoid();
}

return {
id: id,
platform: '本地',
Expand Down
1 change: 1 addition & 0 deletions src/core/trackPlayer/internal/playList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let playListIndexMap: Record<string, Record<string, number>> = {};
/**
* 设置播放队列
* @param newPlayList 新的播放队列
* @param shouldSave 是否保存到本地
*/
export function setPlayList(
newPlayList: IMusic.IMusicItem[],
Expand Down
1 change: 1 addition & 0 deletions src/entry/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ async function setupFolder() {
checkAndCreateDir(pathConst.cachePath),
checkAndCreateDir(pathConst.pluginPath),
checkAndCreateDir(pathConst.lrcCachePath),
checkAndCreateDir(pathConst.downloadCachePath),
checkAndCreateDir(pathConst.localLrcPath),
checkAndCreateDir(pathConst.downloadPath).then(() => {
checkAndCreateDir(pathConst.downloadMusicPath);
Expand Down

0 comments on commit 1804561

Please sign in to comment.