add kugou search
This commit is contained in:
parent
853064813f
commit
914313944b
@ -3,6 +3,7 @@ package top.baogutang.music.client;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import top.baogutang.music.annos.ChannelInfo;
|
||||
import top.baogutang.music.dao.entity.MusicDownloadRecordEntity;
|
||||
import top.baogutang.music.dao.entity.MusicRecordEntity;
|
||||
@ -19,6 +20,7 @@ import top.baogutang.music.utils.OkHttpUtil;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
@ -178,7 +180,39 @@ public class KuGouMusicClient implements ChannelClient<MusicSearchReq, MusicSear
|
||||
|
||||
@Override
|
||||
public MusicPlaylistRes playlist(String id) {
|
||||
return null;
|
||||
String playlistUrl = String.format(kuGouMusicProperties.getPlaylistBaseUrl(), id);
|
||||
KuGouMusicSearchCommonRes<KuGouMusicSearchCommonRes.InfoData<KuGouMusicSearchCommonRes.PlayListSong>> kuGouMusicSearchCommonRes = OkHttpUtil.get(playlistUrl, null, null, new TypeReference<>() {
|
||||
});
|
||||
if (Objects.isNull(kuGouMusicSearchCommonRes) || Objects.isNull(kuGouMusicSearchCommonRes.getData())) {
|
||||
return null;
|
||||
}
|
||||
List<MusicPlaylistRes.Song> songs = kuGouMusicSearchCommonRes.getData().getLists().stream()
|
||||
.map(s -> {
|
||||
MusicPlaylistRes.Song song = new MusicPlaylistRes.Song();
|
||||
song.setId(s.getHash());
|
||||
song.setName(s.getName());
|
||||
List<MusicPlaylistRes.Artist> artists = s.getSingerList().stream()
|
||||
.map(si -> {
|
||||
MusicPlaylistRes.Artist artist = new MusicPlaylistRes.Artist();
|
||||
artist.setId(si.getId());
|
||||
artist.setName(si.getName());
|
||||
return artist;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
song.setAr(artists);
|
||||
MusicPlaylistRes.Album album = new MusicPlaylistRes.Album();
|
||||
if (Objects.nonNull(s.getAlbum())) {
|
||||
album.setId(s.getAlbum().getId());
|
||||
album.setName(s.getAlbum().getName());
|
||||
}
|
||||
song.setAl(album);
|
||||
return song;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
MusicPlaylistRes musicPlaylistRes = new MusicPlaylistRes();
|
||||
musicPlaylistRes.setCode(200);
|
||||
musicPlaylistRes.setSongs(songs);
|
||||
return musicPlaylistRes;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -188,12 +222,71 @@ public class KuGouMusicClient implements ChannelClient<MusicSearchReq, MusicSear
|
||||
|
||||
@Override
|
||||
public MusicAlbumRes album(String id) {
|
||||
return null;
|
||||
String albumUrl = String.format(kuGouMusicProperties.getAlbumBaseUrl(), id);
|
||||
KuGouMusicSearchCommonRes<KuGouMusicSearchCommonRes.AlbumData<KuGouMusicSearchCommonRes.AlbumSong>> kuGouMusicSearchCommonRes = OkHttpUtil.get(albumUrl, null, null, new TypeReference<>() {
|
||||
});
|
||||
if (Objects.isNull(kuGouMusicSearchCommonRes) || Objects.isNull(kuGouMusicSearchCommonRes.getData())) {
|
||||
return null;
|
||||
}
|
||||
List<MusicAlbumRes.Song> songs = kuGouMusicSearchCommonRes.getData().getSongs().stream()
|
||||
.map(albumSong -> {
|
||||
MusicAlbumRes.Song song = new MusicAlbumRes.Song();
|
||||
song.setId(albumSong.getAudioInfo().getHash());
|
||||
song.setName(albumSong.getBase().getAudioName());
|
||||
List<MusicAlbumRes.Artist> artists = albumSong.getAuthors().stream()
|
||||
.map(songSinger -> {
|
||||
MusicAlbumRes.Artist artist = new MusicAlbumRes.Artist();
|
||||
artist.setId(songSinger.getAuthorId());
|
||||
artist.setName(songSinger.getAuthorName());
|
||||
return artist;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
song.setAr(artists);
|
||||
MusicAlbumRes.Album album = new MusicAlbumRes.Album();
|
||||
album.setName(albumSong.getAlbumInfo().getAlbumName());
|
||||
song.setAl(album);
|
||||
return song;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
MusicAlbumRes musicAlbumRes = new MusicAlbumRes();
|
||||
musicAlbumRes.setCode(200);
|
||||
musicAlbumRes.setSongs(songs);
|
||||
return musicAlbumRes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MusicArtistRes artist(String id) {
|
||||
return null;
|
||||
String artistUrl = String.format(kuGouMusicProperties.getArtistBaseUrl(), id, 1);
|
||||
KuGouMusicSearchCommonRes commonRes = OkHttpUtil.get(artistUrl, null, null, new TypeReference<>() {
|
||||
});
|
||||
if (Objects.isNull(commonRes) || Objects.isNull(commonRes.getTotal()) || commonRes.getTotal() < 1) {
|
||||
return null;
|
||||
}
|
||||
artistUrl = String.format(kuGouMusicProperties.getArtistBaseUrl(), id, commonRes.getTotal());
|
||||
KuGouMusicSearchCommonRes<List<KuGouMusicSearchCommonRes.ArtistSong>> kuGouMusicSearchCommonRes = OkHttpUtil.get(artistUrl, null, null, new TypeReference<>() {
|
||||
});
|
||||
|
||||
if (Objects.isNull(kuGouMusicSearchCommonRes) || CollectionUtils.isEmpty(kuGouMusicSearchCommonRes.getData())) {
|
||||
return null;
|
||||
}
|
||||
List<MusicArtistRes.Song> songs = kuGouMusicSearchCommonRes.getData().stream()
|
||||
.map(s -> {
|
||||
MusicArtistRes.Song song = new MusicArtistRes.Song();
|
||||
song.setId(s.getHash());
|
||||
song.setName(s.getAudioName());
|
||||
MusicArtistRes.Artist artist = new MusicArtistRes.Artist();
|
||||
artist.setName(s.getAuthorName());
|
||||
song.setAr(Collections.singletonList(artist));
|
||||
MusicArtistRes.Album album = new MusicArtistRes.Album();
|
||||
album.setName(s.getAlbumName());
|
||||
song.setAl(album);
|
||||
return song;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
MusicArtistRes musicArtistRes = new MusicArtistRes();
|
||||
musicArtistRes.setSongs(songs);
|
||||
|
||||
return musicArtistRes;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -203,7 +296,7 @@ public class KuGouMusicClient implements ChannelClient<MusicSearchReq, MusicSear
|
||||
|
||||
@Override
|
||||
public void saveMusic(MusicDownloadRes res) {
|
||||
|
||||
musicRecordService.save(res, ChannelEnum.KU_GOU_MUSIC);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -2,6 +2,7 @@ package top.baogutang.music.client;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import top.baogutang.music.annos.ChannelInfo;
|
||||
import top.baogutang.music.dao.entity.MusicDownloadRecordEntity;
|
||||
@ -110,7 +111,12 @@ public class NetEaseMusicClient implements ChannelClient<MusicSearchReq, MusicSe
|
||||
if (Objects.isNull(res) || Objects.isNull(res.getName()) || Objects.isNull(res.getUrl())) {
|
||||
return;
|
||||
}
|
||||
Path baseDir = Paths.get(netEaseMusicProperties.getDownloadPath(), res.getArtistName(), res.getAlbumName());
|
||||
Path baseDir;
|
||||
if (StringUtils.isNotBlank(res.getAlbumName())) {
|
||||
baseDir = Paths.get(netEaseMusicProperties.getDownloadPath(), res.getArtistName(), res.getAlbumName());
|
||||
} else {
|
||||
baseDir = Paths.get(netEaseMusicProperties.getDownloadPath(), res.getArtistName());
|
||||
}
|
||||
if (!Files.exists(baseDir)) {
|
||||
Files.createDirectories(baseDir);
|
||||
}
|
||||
|
||||
@ -326,7 +326,12 @@ public class QQMusicClient implements ChannelClient<MusicSearchReq, MusicSearchR
|
||||
if (Objects.isNull(res) || Objects.isNull(res.getName()) || Objects.isNull(res.getUrl())) {
|
||||
return;
|
||||
}
|
||||
Path baseDir = Paths.get(qqMusicProperties.getDownloadPath(), res.getArtistName(), res.getAlbumName());
|
||||
Path baseDir;
|
||||
if (StringUtils.isNotBlank(res.getAlbumName())) {
|
||||
baseDir = Paths.get(qqMusicProperties.getDownloadPath(), res.getArtistName(), res.getAlbumName());
|
||||
} else {
|
||||
baseDir = Paths.get(qqMusicProperties.getDownloadPath(), res.getArtistName());
|
||||
}
|
||||
if (!Files.exists(baseDir)) {
|
||||
Files.createDirectories(baseDir);
|
||||
}
|
||||
|
||||
@ -14,10 +14,12 @@ import java.util.List;
|
||||
* @date: 2024/12/16 : 18:33
|
||||
*/
|
||||
@Data
|
||||
public class KuGouMusicSearchCommonRes<T extends Serializable> implements Serializable {
|
||||
public class KuGouMusicSearchCommonRes<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3851575429347578104L;
|
||||
|
||||
private Integer total;
|
||||
|
||||
private Integer status;
|
||||
|
||||
@JsonProperty("error_code")
|
||||
@ -28,6 +30,157 @@ public class KuGouMusicSearchCommonRes<T extends Serializable> implements Serial
|
||||
|
||||
private T data;
|
||||
|
||||
@Data
|
||||
public static class ArtistSong implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 3165381746779447503L;
|
||||
|
||||
@JsonProperty("hash")
|
||||
private String hash;
|
||||
|
||||
@JsonProperty("audio_name")
|
||||
private String audioName;
|
||||
|
||||
@JsonProperty("author_name")
|
||||
private String authorName;
|
||||
|
||||
@JsonProperty("album_name")
|
||||
private String albumName;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class AlbumData<T extends Serializable> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 425274258965725976L;
|
||||
|
||||
@JsonProperty("total")
|
||||
private Integer total;
|
||||
|
||||
@JsonProperty("songs")
|
||||
private List<T> songs;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class AlbumSong implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 6916254734866228577L;
|
||||
|
||||
@JsonProperty("audio_info")
|
||||
private AudioInfo audioInfo;
|
||||
|
||||
@JsonProperty("base")
|
||||
private SongBase base;
|
||||
|
||||
@JsonProperty("authors")
|
||||
private List<AlbumSongAuthor> authors;
|
||||
|
||||
@JsonProperty("album_info")
|
||||
private AlbumInfo albumInfo;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class AlbumInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 9053952278346646036L;
|
||||
|
||||
@JsonProperty("album_name")
|
||||
private String albumName;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class AlbumSongAuthor implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4273434798080895649L;
|
||||
|
||||
@JsonProperty("author_id")
|
||||
private String authorId;
|
||||
|
||||
@JsonProperty("author_name")
|
||||
private String authorName;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class SongBase implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5422843795950363408L;
|
||||
|
||||
@JsonProperty("audio_name")
|
||||
private String audioName;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class AudioInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4706023836553750567L;
|
||||
|
||||
@JsonProperty("hash")
|
||||
private String hash;
|
||||
|
||||
@JsonProperty("hash_flac")
|
||||
private String hashFlac;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class InfoData<T extends Serializable> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3855070385611292886L;
|
||||
|
||||
private Integer page;
|
||||
|
||||
@JsonProperty("pagesize")
|
||||
private Integer pageSize;
|
||||
|
||||
private Integer count;
|
||||
|
||||
@JsonProperty("info")
|
||||
private List<T> lists;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class PlayListSong implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -765848606882852042L;
|
||||
|
||||
@JsonProperty("hash")
|
||||
private String hash;
|
||||
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
|
||||
@JsonProperty("albuminfo")
|
||||
private PlayListSongAlbum album;
|
||||
|
||||
@JsonProperty("singerinfo")
|
||||
private List<PlayListSongSinger> singerList;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class PlayListSongSinger implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -8169846601636903186L;
|
||||
|
||||
@JsonProperty("id")
|
||||
private String id;
|
||||
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class PlayListSongAlbum implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 2581046968055806575L;
|
||||
|
||||
@JsonProperty("id")
|
||||
private String id;
|
||||
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
}
|
||||
|
||||
|
||||
@Data
|
||||
public static class PageData<T extends Serializable> implements Serializable {
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ public class MusicArtistRes extends AbstractMusicRes implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -636513450925661161L;
|
||||
|
||||
private long id;
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
|
||||
@ -61,9 +61,10 @@ baogutang:
|
||||
|
||||
kugou-music:
|
||||
query-base-url: http://117.72.78.133:5177/search?keywords=%s&page=%d&pagesize=%d&type=%s
|
||||
playlist-base-url: http://117.72.78.133:5175/songlist?id=%s
|
||||
album-base-url: http://117.72.78.133:5175/album/songs?albummid=%s
|
||||
download-base-url: http://117.72.78.133:5176/song?url=https://y.qq.com/n/ryqq/songDetail/%s
|
||||
playlist-base-url: http://117.72.78.133:5177/playlist/track/all?id=%s&pagesize=200
|
||||
album-base-url: http://117.72.78.133:5177/album/songs?id=%s&pagesize=50
|
||||
artist-base-url: http://117.72.78.133:5177/artist/audios?id=%s&sort=hot&pagesize=%d
|
||||
download-base-url: http://117.72.78.133:5177/song/url?hash=%s&quality=viper_clear
|
||||
download-path: /downloads/music
|
||||
# download-path: /Users/nikooh/Desktop/downloads/music
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user