Add SearchArtists and GetArtistAlbums proxy RPCs to music-agregator service
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/claude-agent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -54,6 +54,30 @@ func (s *MetadataService) GetArtistAlbums(ctx context.Context, artistExternalID
|
||||
return resp.GetAlbums(), nil
|
||||
}
|
||||
|
||||
func (s *MetadataService) SearchArtists(ctx context.Context, query string, limit, offset int32) (*metadataPb.SearchArtistsResponse, error) {
|
||||
resp, err := s.client.SearchArtists(ctx, &metadataPb.SearchArtistsRequest{
|
||||
Query: query,
|
||||
Limit: limit,
|
||||
Offset: offset,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("searching artists: %w", err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *MetadataService) GetArtistAlbumsWithPagination(ctx context.Context, artistID string, limit, offset int32) (*metadataPb.GetArtistAlbumsResponse, error) {
|
||||
resp, err := s.client.GetArtistAlbums(ctx, &metadataPb.GetArtistAlbumsRequest{
|
||||
ArtistId: artistID,
|
||||
Limit: limit,
|
||||
Offset: offset,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("fetching artist albums: %w", err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *MetadataService) GetAlbumTracks(ctx context.Context, albumExternalID string) ([]*metadataPb.Track, error) {
|
||||
resp, err := s.client.GetAlbumTracks(ctx, &metadataPb.GetAlbumTracksRequest{
|
||||
AlbumId: albumExternalID,
|
||||
|
||||
@@ -75,6 +75,14 @@ func (s *MusicAgregatorServer) AnalyzeAlbumRelease(ctx context.Context, req *pb.
|
||||
return s.service.AnalyzeAlbumRelease(ctx, req)
|
||||
}
|
||||
|
||||
func (s *MusicAgregatorServer) SearchArtists(ctx context.Context, req *pb.SearchArtistsRequest) (*pb.SearchArtistsResponse, error) {
|
||||
return s.service.SearchArtists(ctx, req)
|
||||
}
|
||||
|
||||
func (s *MusicAgregatorServer) GetArtistAlbums(ctx context.Context, req *pb.GetArtistAlbumsRequest) (*pb.GetArtistAlbumsResponse, error) {
|
||||
return s.service.GetArtistAlbums(ctx, req)
|
||||
}
|
||||
|
||||
func (s *MusicAgregatorServer) Register(server *grpc.Server) {
|
||||
pb.RegisterMusicAgregatorServiceServer(server, s)
|
||||
}
|
||||
|
||||
@@ -869,3 +869,106 @@ func downloadTorrentData(url string) ([]byte, error) {
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (service *MusicAgregatorService) SearchArtists(ctx context.Context, req *pb.SearchArtistsRequest) (*pb.SearchArtistsResponse, error) {
|
||||
resp, err := service.metadata.SearchArtists(ctx, req.GetQuery(), req.GetLimit(), req.GetOffset())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
artists := make([]*pb.SearchArtistResult, len(resp.GetArtists()))
|
||||
for i, a := range resp.GetArtists() {
|
||||
genres := make([]string, len(a.GetGenres()))
|
||||
for j, g := range a.GetGenres() {
|
||||
genres[j] = g.GetName()
|
||||
}
|
||||
|
||||
extIDs := make([]*pb.ExternalId, len(a.GetExternalIds()))
|
||||
for j, e := range a.GetExternalIds() {
|
||||
extIDs[j] = &pb.ExternalId{
|
||||
Provider: e.GetSource(),
|
||||
Id: e.GetSourceId(),
|
||||
}
|
||||
}
|
||||
|
||||
artists[i] = &pb.SearchArtistResult{
|
||||
Id: a.GetId(),
|
||||
Name: a.GetName(),
|
||||
SortName: a.GetSortName(),
|
||||
ArtistType: a.GetArtistType(),
|
||||
Country: a.GetCountry(),
|
||||
FormedDate: a.GetFormedDate(),
|
||||
DisbandedDate: a.GetDisbandedDate(),
|
||||
Description: a.GetDescription(),
|
||||
ImageUrl: a.GetImageUrl(),
|
||||
Genres: genres,
|
||||
ExternalIds: extIDs,
|
||||
}
|
||||
}
|
||||
|
||||
return &pb.SearchArtistsResponse{
|
||||
Artists: artists,
|
||||
Total: resp.GetTotal(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (service *MusicAgregatorService) GetArtistAlbums(ctx context.Context, req *pb.GetArtistAlbumsRequest) (*pb.GetArtistAlbumsResponse, error) {
|
||||
resp, err := service.metadata.GetArtistAlbumsWithPagination(ctx, req.GetArtistId(), req.GetLimit(), req.GetOffset())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
albums := make([]*pb.AlbumResult, len(resp.GetAlbums()))
|
||||
for i, a := range resp.GetAlbums() {
|
||||
genres := make([]string, len(a.GetGenres()))
|
||||
for j, g := range a.GetGenres() {
|
||||
genres[j] = g.GetName()
|
||||
}
|
||||
|
||||
extIDs := make([]*pb.ExternalId, len(a.GetExternalIds()))
|
||||
for j, e := range a.GetExternalIds() {
|
||||
extIDs[j] = &pb.ExternalId{
|
||||
Provider: e.GetSource(),
|
||||
Id: e.GetSourceId(),
|
||||
}
|
||||
}
|
||||
|
||||
artists := make([]*pb.AlbumArtistCredit, len(a.GetArtists()))
|
||||
for j, ac := range a.GetArtists() {
|
||||
artists[j] = &pb.AlbumArtistCredit{
|
||||
Id: ac.GetArtist().GetId(),
|
||||
Name: ac.GetArtist().GetName(),
|
||||
Role: ac.GetRole(),
|
||||
}
|
||||
}
|
||||
|
||||
var label *pb.AlbumLabel
|
||||
if a.GetLabel() != nil {
|
||||
label = &pb.AlbumLabel{
|
||||
Id: a.GetLabel().GetId(),
|
||||
Name: a.GetLabel().GetName(),
|
||||
Country: a.GetLabel().GetCountry(),
|
||||
}
|
||||
}
|
||||
|
||||
albums[i] = &pb.AlbumResult{
|
||||
Id: a.GetId(),
|
||||
Title: a.GetTitle(),
|
||||
AlbumType: a.GetAlbumType(),
|
||||
ReleaseDate: a.GetReleaseDate(),
|
||||
Upc: a.GetUpc(),
|
||||
TotalTracks: a.GetTotalTracks(),
|
||||
TotalDiscs: a.GetTotalDiscs(),
|
||||
CoverUrl: a.GetCoverUrl(),
|
||||
Artists: artists,
|
||||
Label: label,
|
||||
Genres: genres,
|
||||
ExternalIds: extIDs,
|
||||
}
|
||||
}
|
||||
|
||||
return &pb.GetArtistAlbumsResponse{
|
||||
Albums: albums,
|
||||
Total: resp.GetTotal(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user