Deduplicate GetAlbum response: merge release info into AlbumDetail, track release into TrackDetail
This commit is contained in:
+61
-70
@@ -289,6 +289,44 @@ func (service *MusicAgregatorService) buildAlbumInfo(ctx context.Context, dbAlbu
|
||||
dbTracksByExternalID[t.ExternalID] = t
|
||||
}
|
||||
|
||||
var trackReleasesByTrackID map[string]*database.TrackRelease
|
||||
albumReleases, err := service.albumReleases.GetByAlbumID(ctx, dbAlbum.ID)
|
||||
if err == nil && len(albumReleases) > 0 {
|
||||
ar := albumReleases[0]
|
||||
album.Release = &pb.AlbumReleaseDetail{
|
||||
Id: ar.ID,
|
||||
Format: ar.Format,
|
||||
Channels: int32(ar.Channels),
|
||||
IsLossless: ar.IsLossless,
|
||||
TotalSize: ar.TotalSize,
|
||||
TotalDurationMs: int32(ar.TotalDurationMs),
|
||||
TrackCount: int32(ar.TrackCount),
|
||||
HasCoverArt: ar.HasCoverArt,
|
||||
HasCueSheet: ar.HasCueSheet,
|
||||
HasRipLog: ar.HasRipLog,
|
||||
Path: ar.Path,
|
||||
}
|
||||
if ar.BitDepth != nil {
|
||||
album.Release.BitDepth = int32(*ar.BitDepth)
|
||||
}
|
||||
if ar.SampleRate != nil {
|
||||
album.Release.SampleRate = int32(*ar.SampleRate)
|
||||
}
|
||||
if ar.Source != nil {
|
||||
album.Release.Source = *ar.Source
|
||||
}
|
||||
|
||||
trs, err := service.trackReleases.GetByAlbumReleaseID(ctx, ar.ID)
|
||||
if err == nil {
|
||||
trackReleasesByTrackID = make(map[string]*database.TrackRelease, len(trs))
|
||||
for _, tr := range trs {
|
||||
if tr.TrackID != nil {
|
||||
trackReleasesByTrackID[*tr.TrackID] = tr
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tracks := make([]*pb.TrackDetail, 0, len(metadataTracks))
|
||||
for _, mt := range metadataTracks {
|
||||
td := &pb.TrackDetail{
|
||||
@@ -310,85 +348,38 @@ func (service *MusicAgregatorService) buildAlbumInfo(ctx context.Context, dbAlbu
|
||||
|
||||
if dbTrack, ok := dbTracksByExternalID[mt.GetId()]; ok {
|
||||
td.Id = dbTrack.ID
|
||||
if df, ok := downloadFilesByTrackID[dbTrack.ID]; ok {
|
||||
td.File = &pb.TrackFile{
|
||||
Path: df.FilePath,
|
||||
Format: df.FileType,
|
||||
Size: df.FileSize,
|
||||
|
||||
if tr, ok := trackReleasesByTrackID[dbTrack.ID]; ok {
|
||||
td.FilePath = tr.FilePath
|
||||
td.FileSize = tr.FileSize
|
||||
td.Format = tr.Format
|
||||
td.Channels = int32(tr.Channels)
|
||||
if tr.DurationMs != nil {
|
||||
td.DurationMs = int32(*tr.DurationMs)
|
||||
}
|
||||
if tr.BitDepth != nil {
|
||||
td.BitDepth = int32(*tr.BitDepth)
|
||||
}
|
||||
if tr.SampleRate != nil {
|
||||
td.SampleRate = int32(*tr.SampleRate)
|
||||
}
|
||||
if tr.BitrateKbps != nil {
|
||||
td.BitrateKbps = int32(*tr.BitrateKbps)
|
||||
}
|
||||
} else if df, ok := downloadFilesByTrackID[dbTrack.ID]; ok {
|
||||
td.FilePath = df.FilePath
|
||||
td.FileSize = df.FileSize
|
||||
td.Format = df.FileType
|
||||
}
|
||||
}
|
||||
|
||||
tracks = append(tracks, td)
|
||||
}
|
||||
|
||||
info := &pb.AlbumInfo{
|
||||
return &pb.AlbumInfo{
|
||||
Album: album,
|
||||
Tracks: tracks,
|
||||
}
|
||||
|
||||
albumReleases, err := service.albumReleases.GetByAlbumID(ctx, dbAlbum.ID)
|
||||
if err == nil && len(albumReleases) > 0 {
|
||||
ar := albumReleases[0]
|
||||
releaseDetail := &pb.AlbumReleaseDetail{
|
||||
Id: ar.ID,
|
||||
Format: ar.Format,
|
||||
Channels: int32(ar.Channels),
|
||||
IsLossless: ar.IsLossless,
|
||||
TotalSize: ar.TotalSize,
|
||||
TotalDurationMs: int32(ar.TotalDurationMs),
|
||||
TrackCount: int32(ar.TrackCount),
|
||||
HasCoverArt: ar.HasCoverArt,
|
||||
HasCueSheet: ar.HasCueSheet,
|
||||
HasRipLog: ar.HasRipLog,
|
||||
Path: ar.Path,
|
||||
}
|
||||
if ar.BitDepth != nil {
|
||||
releaseDetail.BitDepth = int32(*ar.BitDepth)
|
||||
}
|
||||
if ar.SampleRate != nil {
|
||||
releaseDetail.SampleRate = int32(*ar.SampleRate)
|
||||
}
|
||||
if ar.Source != nil {
|
||||
releaseDetail.Source = *ar.Source
|
||||
}
|
||||
|
||||
trackReleases, err := service.trackReleases.GetByAlbumReleaseID(ctx, ar.ID)
|
||||
if err == nil {
|
||||
for _, tr := range trackReleases {
|
||||
trd := &pb.TrackReleaseDetail{
|
||||
Id: tr.ID,
|
||||
Title: tr.Title,
|
||||
TrackNumber: int32(tr.TrackNumber),
|
||||
DiscNumber: int32(tr.DiscNumber),
|
||||
Format: tr.Format,
|
||||
Channels: int32(tr.Channels),
|
||||
FileSize: tr.FileSize,
|
||||
FilePath: tr.FilePath,
|
||||
}
|
||||
if tr.TrackID != nil {
|
||||
trd.TrackId = *tr.TrackID
|
||||
}
|
||||
if tr.DurationMs != nil {
|
||||
trd.DurationMs = int32(*tr.DurationMs)
|
||||
}
|
||||
if tr.BitDepth != nil {
|
||||
trd.BitDepth = int32(*tr.BitDepth)
|
||||
}
|
||||
if tr.SampleRate != nil {
|
||||
trd.SampleRate = int32(*tr.SampleRate)
|
||||
}
|
||||
if tr.BitrateKbps != nil {
|
||||
trd.BitrateKbps = int32(*tr.BitrateKbps)
|
||||
}
|
||||
releaseDetail.Tracks = append(releaseDetail.Tracks, trd)
|
||||
}
|
||||
}
|
||||
|
||||
info.Release = releaseDetail
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (service *MusicAgregatorService) AnalyzeAlbumRelease(ctx context.Context, req *pb.AnalyzeAlbumReleaseRequest) (*pb.AnalyzeAlbumReleaseResponse, error) {
|
||||
|
||||
@@ -69,6 +69,7 @@ message AlbumDetail {
|
||||
string label = 10;
|
||||
MonitorState monitor_state = 11;
|
||||
DownloadInfo download = 12;
|
||||
AlbumReleaseDetail release = 13;
|
||||
}
|
||||
|
||||
message DownloadInfo {
|
||||
@@ -85,7 +86,6 @@ message GetAlbumRequest {
|
||||
message AlbumInfo {
|
||||
AlbumDetail album = 1;
|
||||
repeated TrackDetail tracks = 2;
|
||||
AlbumReleaseDetail release = 3;
|
||||
}
|
||||
|
||||
message GetAlbumResponse {
|
||||
@@ -110,7 +110,13 @@ message TrackDetail {
|
||||
string isrc = 7;
|
||||
bool explicit = 8;
|
||||
repeated ArtistCredit artists = 9;
|
||||
TrackFile file = 10;
|
||||
string file_path = 10;
|
||||
int64 file_size = 11;
|
||||
string format = 12;
|
||||
int32 bit_depth = 13;
|
||||
int32 sample_rate = 14;
|
||||
int32 channels = 15;
|
||||
int32 bitrate_kbps = 16;
|
||||
}
|
||||
|
||||
message ArtistCredit {
|
||||
@@ -118,12 +124,6 @@ message ArtistCredit {
|
||||
string name = 2;
|
||||
}
|
||||
|
||||
message TrackFile {
|
||||
string path = 1;
|
||||
string format = 2;
|
||||
int64 size = 3;
|
||||
}
|
||||
|
||||
message AlbumReleaseDetail {
|
||||
string id = 1;
|
||||
string format = 2;
|
||||
@@ -139,23 +139,6 @@ message AlbumReleaseDetail {
|
||||
bool has_cue_sheet = 12;
|
||||
bool has_rip_log = 13;
|
||||
string path = 14;
|
||||
repeated TrackReleaseDetail tracks = 15;
|
||||
}
|
||||
|
||||
message TrackReleaseDetail {
|
||||
string id = 1;
|
||||
string track_id = 2;
|
||||
string title = 3;
|
||||
int32 track_number = 4;
|
||||
int32 disc_number = 5;
|
||||
int32 duration_ms = 6;
|
||||
string format = 7;
|
||||
int32 bit_depth = 8;
|
||||
int32 sample_rate = 9;
|
||||
int32 channels = 10;
|
||||
int32 bitrate_kbps = 11;
|
||||
int64 file_size = 12;
|
||||
string file_path = 13;
|
||||
}
|
||||
|
||||
message MonitoredRelease {
|
||||
|
||||
Reference in New Issue
Block a user