浏览代码

Merge remote-tracking branch 'origin/master'

chendeben 1 年之前
父节点
当前提交
d5c81cf36f

+ 3 - 2
entry/src/main/ets/common/util/MediaTable.ets

@@ -20,9 +20,10 @@ export default class MediaTable {
     this.accountTable.getRdbStore(context,callback);
   }
 
-  insert(item: VideoItem, callback: Function) {
+
+  insert(item: VideoItem, callback: Function,cover_api?:string) {
     const valueBucket: relationalStore.ValuesBucket = generateBucket(item);
-    this.accountTable.insertData(valueBucket, callback);
+    this.accountTable.insertData(valueBucket, callback,cover_api);
   }
 
   deleteData(item: VideoItem, callback: Function) {

+ 23 - 25
entry/src/main/ets/common/util/NetAxiosUtil.ets

@@ -12,26 +12,20 @@ class NetAxiosUtil{
 
 
   async getLyric(title:string,artist:string,isApi2:boolean): Promise<string>{
-    if(StrUtil.isNotEmpty(title)&&title==='全世界最好的你'){
-      artist = ''
-    }
-    let baseUrl = PreferencesUtil.getStringSync('LRC_API')
-    if (baseUrl=='') {
-      LogUtil.debug("Heanup 未设置API");
-      return ''
-    }
-    let requestUrl = baseUrl
-      + '?title=' + encodeURIComponent(title.trim()) + '&artist=' + encodeURIComponent(artist.trim());
-
-    LogUtil.debug("Heanup requestUrl =" + requestUrl + '; title = '+title+'; artist = '+artist)
-    // if(isApi2){
-    //    requestUrl = CommonConstants.LRC_API_2
-    //      + '?title=' + encodeURIComponent(title.trim()) + '&artist=' + encodeURIComponent(artist.trim());
-    // }
-    // LogUtil.debug("onecold requestUrl =" + requestUrl + ' title = '+title+' artist = '+artist)
 
     try {
+      if(StrUtil.isNotEmpty(title)&&title==='全世界最好的你'){
+        artist = ''
+      }
+      let baseUrl = PreferencesUtil.getStringSync('LRC_API','')
+      if (baseUrl=='') {
+        LogUtil.debug("Heanup 未设置API");
+        return ''
+      }
+      let requestUrl = baseUrl
+        + '?title=' + encodeURIComponent(title.trim()) + '&artist=' + encodeURIComponent(artist.trim());
 
+      LogUtil.debug("Heanup requestUrl =" + requestUrl + '; title = '+title+'; artist = '+artist)
 
       const httpRequest = http.createHttp();
       const options: http.HttpRequestOptions = {
@@ -67,16 +61,20 @@ class NetAxiosUtil{
 
 
 
-  async getLyricCover(title: string, artist: string): Promise<string> {
-    let baseUrl = PreferencesUtil.getStringSync('COVER_API')
-    if (baseUrl=='') {
-      LogUtil.debug("Heanup 未设置API");
-      return ''
-    }
-    const cover_url = baseUrl
-      + '?title=' + encodeURIComponent(title.trim()) + '&artist=' + encodeURIComponent(artist.trim());
+  async getLyricCover(title: string, artist: string,cover_api?:string): Promise<string> {
 
     try {
+      let baseUrl = cover_api
+      if(cover_api===undefined&&StrUtil.isEmpty(cover_api)){
+        baseUrl =  PreferencesUtil.getStringSync('COVER_API','')
+        if ( baseUrl=='') {
+          LogUtil.debug("Heanup 未设置API");
+          return ''
+        }
+      }
+
+      const cover_url = baseUrl
+        + '?title=' + encodeURIComponent(title.trim()) + '&artist=' + encodeURIComponent(artist.trim());
       const httpRequest = http.createHttp();
       const options: http.HttpRequestOptions = {
         method: http.RequestMethod.GET,

+ 8 - 10
entry/src/main/ets/common/util/RdbUtils.ets

@@ -2,7 +2,6 @@
 import relationalStore from '@ohos.data.relationalStore';
 import { StrUtil } from '@pura/harmony-utils';
 import Logger from './Logger';
-import MediaTable from './MediaTable';
 import NetAxiosUtil from './NetAxiosUtil';
 
 //
@@ -93,7 +92,7 @@ export default class RdbUtils {
 
 
   //检查是否存在相同id的记录,存在则不插入,进一步判断pixelMapPath字段,如果旧值为空而新值不为空,则更新该字段。
-  async insertData(data: relationalStore.ValuesBucket, callback: Function = () => {}) {
+  async insertData(data: relationalStore.ValuesBucket, callback: Function = () => {},cover_api?:string) {
     if (!callback || typeof callback !== 'function') {
       Logger.info(RdbUtils.RDB_TAG, 'insertData() has no valid callback!');
       return;
@@ -103,7 +102,7 @@ export default class RdbUtils {
     const valueBucket: relationalStore.ValuesBucket = data;
     const id = valueBucket.id;
     let titleNameV = valueBucket.name;
-    let artistV = valueBucket.artist;
+    let artistV = valueBucket.artist ;
     let pixelMapPathV = valueBucket.pixelMapPath
 
     if (this.rdbStore) {
@@ -126,8 +125,8 @@ export default class RdbUtils {
             const existingPixelMapPath = resultSet.getString(resultSet.getColumnIndex('pixelMapPath'));
             const name = resultSet.getString(resultSet.getColumnIndex('name'));
             const artist = resultSet.getString(resultSet.getColumnIndex('artist'));
-            if ((!existingPixelMapPath || existingPixelMapPath.trim() === '') ) {
-              let newPixelMapPath =  await NetAxiosUtil.getLyricCover(name,artist)
+            if ((!existingPixelMapPath || existingPixelMapPath.trim() === '')&& cover_api!==undefined) {
+              let newPixelMapPath =  await NetAxiosUtil.getLyricCover(name,artist,cover_api)
               console.info('onecold getLyricCover success. name= '+name);
               console.info('onecold getLyricCover success. newPixelMapPath= '+newPixelMapPath);
               if(StrUtil.isNotEmpty(newPixelMapPath)){
@@ -158,12 +157,11 @@ export default class RdbUtils {
           callback(false);
           return;
         }
+
         //不存在相同记录 ,判断要不要去请求getLyricCover
-        if(pixelMapPathV ===undefined){
-          // if(titleNameV){
-            valueBucket.pixelMapPath =  await NetAxiosUtil.getLyricCover(titleNameV+'',artistV+'')
-            console.info('onecold getLyricCover success. valueBucket.pixelMapPath= '+valueBucket.pixelMapPath);
-          // }
+        if(pixelMapPathV==undefined||pixelMapPathV.toString()==='' ){
+          valueBucket.pixelMapPath = await NetAxiosUtil.getLyricCover(titleNameV+'',artistV+'',cover_api)
+
         }
         console.info('onecold getLyricCover pixelMapPathV1= '+pixelMapPathV);
         // Proceed with insert if record does not exist

+ 3 - 3
entry/src/main/ets/common/util/Utility.ets

@@ -615,11 +615,11 @@ export class Utility {
 
         let fileSize = Utility.formatFSize(videoSize)
         //按照添加时间
-        let addTime = Utility.getFormatDateStr(new Date().getTime(),'yyyy-MM-dd HH:mm');
-        console.info('onecold asset addTime: ', addTime);
+        let addTime = Utility.getFormatDateStr(new Date(),'yyyy-MM-dd HH:mm');
+        // console.info('onecold asset addTime: ', addTime);
         // let cTime = Utility.getFormatDateStr(stat.mtime,'yyyy-MM-dd HH:mm')
 
-        console.info('asset stat.ctime: ', stat.ctime);
+        // console.info('asset stat.ctime: ', stat.ctime);
 
         let musicName:string | undefined = file.name
         let artist:string | undefined = ''

+ 4 - 5
entry/src/main/ets/pages/ScanFilePage.ets

@@ -62,7 +62,6 @@ export struct ScanFilePage{
     this.lockPath =  this.rootPath +'/'+ LocalMusic.STR_LOCK_VIDEO
     LogUtil.info('onecold 文件扫描 aboutToAppear')
 
-
   }
 
   endScan(){
@@ -112,7 +111,8 @@ export struct ScanFilePage{
   doOptimize(){
 
     this.initState()
-    const task = new taskpool.Task(scanDirectoryTask, getContext(this), this.rootPath,  this.lockPath);
+    const task = new taskpool.Task(scanDirectoryTask, getContext(this), this.rootPath,
+      this.lockPath,PreferencesUtil.getStringSync('COVER_API',''));
     taskpool.execute(task, taskpool.Priority.HIGH).then(()=>{
       this.endScan()
     }).catch((e:object)=>{
@@ -289,13 +289,12 @@ export struct ScanFilePage{
 // }
 
 @Concurrent
-async function  scanDirectoryTask(context: Context, dirPath: string, lockPath: string) {
+async function  scanDirectoryTask(context: Context, dirPath: string, lockPath: string,cover_api:string) {
   const stack: string[] = [dirPath];
   const table: MediaTable = new MediaTable(context);
   while (stack.length  > 0) {
     const currentPath = stack.pop()!;
     const files = FileUtil.listFileSync(currentPath);
-
     await Promise.all(files.map(async  (file) => {
       const fPath = `${currentPath}/${file}`;
       if (fPath === lockPath) return;
@@ -311,7 +310,7 @@ async function  scanDirectoryTask(context: Context, dirPath: string, lockPath: s
           );
           table.insert(mediaItem,  (id: number) => {
 
-          });
+          },cover_api);
         }
       }
     }));

+ 19 - 17
entry/src/main/ets/view/LocalMusic.ets

@@ -450,7 +450,8 @@ export struct LocalMusic {
           code: 1,
           data1: this.context,
           data2: this.rootPath,
-          data3: this.lockPath
+          data3: this.lockPath,
+          data4: PreferencesUtil.getStringSync('COVER_API',''),
         });
         PreferencesUtil.putSync('isFirstApp', false)
       } else {
@@ -683,11 +684,11 @@ export struct LocalMusic {
       }
 
       console.info(`onecold gengxin 1: ${this.videoLocalList.length}`);
-      for (let i = 0; i < this.videoLocalList.length; i++) {
-
-        console.info(`onecold gengxin 1: ${this.videoLocalList[i].name}`);
-
-      }
+      // for (let i = 0; i < this.videoLocalList.length; i++) {
+      //
+      //   console.info(`onecold gengxin 1: ${this.videoLocalList[i].name}`);
+      //
+      // }
 
       // this.setButtonStatus()
       if (isOpen) {
@@ -967,7 +968,8 @@ export struct LocalMusic {
             code: 1,
             data1: this.context,
             data2: this.rootPath,
-            data3: this.lockPath
+            data3: this.lockPath,
+            data4: PreferencesUtil.getStringSync('COVER_API',''),
           });
           break
       }
@@ -1520,7 +1522,7 @@ export struct LocalMusic {
         if (!newPath.includes(this.lockPath)) { //如果移动到私密,就不插入数据库
           this.table.insert(newItem, (id: number) => {
             //加入数据库
-            // workerInstance.postMessage({ code: 1, data1: this.context,data2: newPath,data3: this.lockPath });
+
           });
         }
 
@@ -4328,15 +4330,15 @@ export struct LocalMusic {
         // ToastUtil.showShort('正在为你搜索在线歌词!')
         //判断是不是赞助会员,是会员的话才开启歌词功能
         // if (!this.isDebug) {
-          if (!Utility.isNoble()) {
-            LogUtil.debug("onecold 不是赞助会员")
-            return
-          }
-        if(!Utility.isPassInstallTime(33)){
-            LogUtil.debug("onecold not pass time")
-            // LogUtil.debug("onecold 用户安装app没超过12天" )
-            return
-          }
+        // if (!Utility.isNoble()) {
+        //     LogUtil.debug("onecold 不是赞助会员")
+        //     return
+        //   }
+        // if(!Utility.isPassInstallTime(33)){
+        //     LogUtil.debug("onecold not pass time")
+        //     // LogUtil.debug("onecold 用户安装app没超过12天" )
+        //     return
+        // }
         // }
 
         let artist = this.currentSong?.artist

+ 4 - 4
entry/src/main/ets/workers/Worker.ets

@@ -19,7 +19,7 @@ workerPort.onmessage = async (e: MessageEvents) => {
 
   switch (e.data.code){
     case 1://第一次扫描文件夹入库
-      await scanDirectory(e.data.data1,e.data.data2,e.data.data3).then(()=>{
+      await scanDirectory(e.data.data1,e.data.data2,e.data.data3,e.data.data4).then(()=>{
         Logger.info('onecold scanDirectory 22 全部扫描完成后执行  ')
         // 全部扫描完成后执行
         workerPort.postMessage({  code: 101, data: {} });
@@ -47,7 +47,7 @@ workerPort.onmessage = async (e: MessageEvents) => {
 
 
 
-async function scanDirectory(context: Context, curPath: string, lockPath: string): Promise<VideoItem[]> {
+async function scanDirectory(context: Context, curPath: string, lockPath: string,cover_api:string): Promise<VideoItem[]> {
   const table: MediaTable = new MediaTable(context);
   let mediaItems: VideoItem[] = [];
 
@@ -70,7 +70,7 @@ async function scanDirectory(context: Context, curPath: string, lockPath: string
           if (FileUtil.isDirectory(fPath))  {
             // 用立即执行函数处理异步递归
             pendingTasks.push((async  () => {
-              const subItems = await scanDirectory(context, fPath, lockPath);
+              const subItems = await scanDirectory(context, fPath, lockPath,cover_api);
               mediaItems = mediaItems.concat(subItems);
             })());
           } else {
@@ -84,7 +84,7 @@ async function scanDirectory(context: Context, curPath: string, lockPath: string
                 await new Promise<void>((resolve: (value: void) => void) => {
                   table.insert(mediaItem,  (id: number) => {
                     resolve(); // 明确调用 resolve 且无返回值
-                  });
+                  },cover_api);
                 });
               })());
             }