|
|
@ -9,14 +9,8 @@ import com.luoo.music.request.cms.SongQueryModel;
|
|
|
|
import com.luoo.music.response.cms.SongVO;
|
|
|
|
import com.luoo.music.response.cms.SongVO;
|
|
|
|
import com.luoo.music.util.CommonUtil;
|
|
|
|
import com.luoo.music.util.CommonUtil;
|
|
|
|
import com.luoo.music.util.Constants;
|
|
|
|
import com.luoo.music.util.Constants;
|
|
|
|
import com.luoo.music.util.UploadUtil;
|
|
|
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.tika.metadata.Metadata;
|
|
|
|
|
|
|
|
import org.apache.tika.parser.AutoDetectParser;
|
|
|
|
|
|
|
|
import org.apache.tika.parser.ParseContext;
|
|
|
|
|
|
|
|
import org.apache.tika.parser.Parser;
|
|
|
|
|
|
|
|
import org.apache.tika.sax.BodyContentHandler;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
@ -31,9 +25,9 @@ import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.*;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
@ -146,7 +140,7 @@ public class CMSSongService {
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, List<String>> buildSongJournalInfo(List<String> ids) {
|
|
|
|
private Map<String, List<String>> buildSongJournalInfo(List<String> ids) {
|
|
|
|
Map<String, List<String>> result = new HashMap<>();
|
|
|
|
Map<String, List<String>> result = new HashMap<>();
|
|
|
|
List<JournalSong> bySongId = journalSongDao.findBySongId(ids);
|
|
|
|
List<JournalSong> bySongId = journalSongDao.findBySongIds(ids);
|
|
|
|
if (!CollectionUtils.isEmpty(bySongId)) {
|
|
|
|
if (!CollectionUtils.isEmpty(bySongId)) {
|
|
|
|
Set<String> idSet = bySongId.stream().map(JournalSong::getJournalNo).collect(Collectors.toSet());
|
|
|
|
Set<String> idSet = bySongId.stream().map(JournalSong::getJournalNo).collect(Collectors.toSet());
|
|
|
|
List<Journal> journalList = journalDao.findByJournalNoIn(idSet);
|
|
|
|
List<Journal> journalList = journalDao.findByJournalNoIn(idSet);
|
|
|
@ -354,6 +348,28 @@ public class CMSSongService {
|
|
|
|
return Result.success("更新成功");
|
|
|
|
return Result.success("更新成功");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取歌曲歌词
|
|
|
|
|
|
|
|
* @param id
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public Result<SongVO> querySongLyric(String id) {
|
|
|
|
|
|
|
|
SongVO result = new SongVO();
|
|
|
|
|
|
|
|
SongInfo song = songDao.findById(id).get();
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(song.getLyric())) {
|
|
|
|
|
|
|
|
result.setLyric(song.getLyric());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(song.getUrl())) {
|
|
|
|
|
|
|
|
String url = song.getUrl();
|
|
|
|
|
|
|
|
String lyricSuffix = url.substring(0, url.lastIndexOf(Constants.DOT)) + ".lyric";
|
|
|
|
|
|
|
|
String lyricUrl = Constants.RESOURCE_PREFIX + Constants.SONG_KEY_PREFIX + lyricSuffix;
|
|
|
|
|
|
|
|
String lyric = readLyric(lyricUrl);
|
|
|
|
|
|
|
|
result.setLyric(lyric);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result.success(result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 更新歌曲歌词
|
|
|
|
* 更新歌曲歌词
|
|
|
|
* @param id
|
|
|
|
* @param id
|
|
|
@ -362,6 +378,17 @@ public class CMSSongService {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Result updateSongLyric(String id, String lyric) {
|
|
|
|
public Result updateSongLyric(String id, String lyric) {
|
|
|
|
songDao.updateSongLyric(id, lyric);
|
|
|
|
songDao.updateSongLyric(id, lyric);
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(lyric)) {
|
|
|
|
|
|
|
|
String key = Constants.SONG_KEY_PREFIX + id + "/00.lyric";
|
|
|
|
|
|
|
|
s3Service.uploadText(Constants.BUCKET, key, lyric);
|
|
|
|
|
|
|
|
List<JournalSong> bySongId = journalSongDao.findBySongId(id);
|
|
|
|
|
|
|
|
for (JournalSong item : bySongId) {
|
|
|
|
|
|
|
|
String format = String.format("%05d/%02d", item.getJournalNo(), item.getSongNo());
|
|
|
|
|
|
|
|
String destLyricSuffix = format + ".lyric";
|
|
|
|
|
|
|
|
String destLyric = Constants.MUSIC_KEY_PREFIX + destLyricSuffix;
|
|
|
|
|
|
|
|
s3Service.copy(Constants.BUCKET, key, destLyric);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return Result.success("更新成功");
|
|
|
|
return Result.success("更新成功");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -407,4 +434,26 @@ public class CMSSongService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result.success("上传成功");
|
|
|
|
return Result.success("上传成功");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String readLyric(String lyricUrl) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 创建 URL 对象
|
|
|
|
|
|
|
|
URL url = new URL(lyricUrl);
|
|
|
|
|
|
|
|
// 打开 HTTP 连接
|
|
|
|
|
|
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
|
|
|
|
|
// 设置请求方法
|
|
|
|
|
|
|
|
connection.setRequestMethod("GET");
|
|
|
|
|
|
|
|
// 获取输入流并读取文件内容到 StringBuilder
|
|
|
|
|
|
|
|
StringBuilder contentBuilder = new StringBuilder();
|
|
|
|
|
|
|
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
|
|
|
|
|
|
|
String line;
|
|
|
|
|
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
|
|
|
|
|
contentBuilder.append(line).append("\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return contentBuilder.toString();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|