music
This commit is contained in:
parent
7f4be753b2
commit
ba272e4b1b
@ -1,6 +1,7 @@
|
||||
package top.baogutang.music.processor;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jaudiotagger.audio.AudioFile;
|
||||
import org.jaudiotagger.audio.exceptions.CannotReadException;
|
||||
import org.jaudiotagger.audio.exceptions.CannotWriteException;
|
||||
@ -18,9 +19,7 @@ import top.baogutang.music.domain.res.download.MusicDownloadRes;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @description:
|
||||
*
|
||||
* @author: N1KO
|
||||
* @date: 2024/12/12 : 10:40
|
||||
*/
|
||||
@ -33,13 +32,23 @@ public class FlacAudioProcessor extends AbstractAudioProcessor {
|
||||
FlacFileReader flacFileReader = new FlacFileReader();
|
||||
AudioFile audioFile = flacFileReader.read(file);
|
||||
Tag tag = audioFile.getTag();
|
||||
tag.setField(FieldKey.TITLE, res.getName());
|
||||
tag.setField(FieldKey.ALBUM, res.getAlbumName());
|
||||
tag.setField(FieldKey.ARTIST, res.getArtistName());
|
||||
tag.setField(FieldKey.LYRICS, res.getLyric());
|
||||
if (StringUtils.isNotBlank(res.getName())) {
|
||||
tag.setField(FieldKey.TITLE, res.getName());
|
||||
}
|
||||
if (StringUtils.isNotBlank(res.getAlbumName())) {
|
||||
tag.setField(FieldKey.ALBUM, res.getAlbumName());
|
||||
}
|
||||
if (StringUtils.isNotBlank(res.getArtistName())) {
|
||||
tag.setField(FieldKey.ARTIST, res.getArtistName());
|
||||
}
|
||||
if (StringUtils.isNotBlank(res.getLyric())) {
|
||||
tag.setField(FieldKey.LYRICS, res.getLyric());
|
||||
}
|
||||
StandardArtwork artwork = new StandardArtwork();
|
||||
artwork.setImageUrl(res.getPic());
|
||||
artwork.setBinaryData(fetchImageData(res.getPic()));
|
||||
if (StringUtils.isNotBlank(res.getPic())) {
|
||||
artwork.setImageUrl(res.getPic());
|
||||
artwork.setBinaryData(fetchImageData(res.getPic()));
|
||||
}
|
||||
tag.setField(artwork);
|
||||
FlacFileWriter flacFileWriter = new FlacFileWriter();
|
||||
flacFileWriter.write(audioFile);
|
||||
|
||||
@ -5,6 +5,8 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@ -37,12 +39,12 @@ import static top.baogutang.music.constants.CacheKey.KEY_MUSIC_TAG_TOKEN_PREFIX;
|
||||
/**
|
||||
*
|
||||
* @description:
|
||||
*
|
||||
* @author: N1KO
|
||||
* @date: 2025/01/23 : 14:53
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RefreshScope
|
||||
public class MusicInfoServiceImpl implements IMusicInfoService {
|
||||
|
||||
@Resource
|
||||
@ -57,6 +59,24 @@ public class MusicInfoServiceImpl implements IMusicInfoService {
|
||||
@Resource(name = "commonExecutor")
|
||||
private Executor commonExecutor;
|
||||
|
||||
@Value("${baogutang.music-tag.token}")
|
||||
private String tokenUrl;
|
||||
|
||||
@Value("${baogutang.music-tag.token.param1:username}")
|
||||
private String tokenParam1;
|
||||
|
||||
@Value("${baogutang.music-tag.token.value1:admin}")
|
||||
private String tokenValue1;
|
||||
|
||||
@Value("${baogutang.music-tag.token.param2:password}")
|
||||
private String tokenParam2;
|
||||
|
||||
@Value("${baogutang.music-tag.token.value2:admin}")
|
||||
private String tokenValue2;
|
||||
|
||||
@Value(("${baogutang.music-tag.cover}"))
|
||||
private String coverUrl;
|
||||
|
||||
@Override
|
||||
public void getCover(String title, String artist, String album, HttpServletResponse response) {
|
||||
MusicRecordEntity musicRecord = musicRecordService.queryByNameOrAlbumOrArtist(title, album, artist);
|
||||
@ -99,11 +119,11 @@ public class MusicInfoServiceImpl implements IMusicInfoService {
|
||||
InfoRes<List<MusicInfoRes>> res = null;
|
||||
try {
|
||||
params.put("resource", "qmusic");
|
||||
res = OkHttpUtil.post("http://114.96.87.132:8002/apimt/fetch_id3_by_title/", headers, params, new TypeReference<>() {
|
||||
res = OkHttpUtil.post(coverUrl, headers, params, new TypeReference<>() {
|
||||
});
|
||||
if (Objects.isNull(res) || !Boolean.TRUE.equals(res.getResult()) || CollectionUtils.isEmpty(res.getData())) {
|
||||
params.put("resource", "netease");
|
||||
res = OkHttpUtil.post("http://114.96.87.132:8002/apimt/fetch_id3_by_title/", headers, params, new TypeReference<>() {
|
||||
res = OkHttpUtil.post(coverUrl, headers, params, new TypeReference<>() {
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -115,11 +135,11 @@ public class MusicInfoServiceImpl implements IMusicInfoService {
|
||||
|
||||
private String geneToken() {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("username", "admin");
|
||||
params.put("password", "admin");
|
||||
params.put(tokenParam1, tokenValue1);
|
||||
params.put(tokenParam2, tokenValue2);
|
||||
TokenRes tokenRes = null;
|
||||
try {
|
||||
tokenRes = OkHttpUtil.post("http://114.96.87.132:8002/apimt/token/", params, new TypeReference<>() {
|
||||
tokenRes = OkHttpUtil.post(tokenUrl, params, new TypeReference<>() {
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error("<<<<<<<<<<获取token异常:{}>>>>>>>>>>", e.getMessage(), e);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user