ソースを参照

解决bug 封面为空 的音乐 都不插入数据库了

onecold 1 年間 前
コミット
ac0f672ad3

+ 18 - 24
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 = {
@@ -68,15 +62,15 @@ 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());
 
     try {
+      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());
       const httpRequest = http.createHttp();
       const options: http.HttpRequestOptions = {
         method: http.RequestMethod.GET,

+ 5 - 7
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';
 
 //
@@ -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) {
@@ -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+'')
+
         }
         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 = ''

+ 14 - 14
entry/src/main/ets/view/LocalMusic.ets

@@ -682,11 +682,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) {
@@ -4327,15 +4327,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