58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
// Package report writes an optional JSON run report.
|
|
package report
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"applesync/internal/state"
|
|
)
|
|
|
|
type Report struct {
|
|
GeneratedAt time.Time `json:"generated_at"`
|
|
RipError string `json:"rip_error,omitempty"`
|
|
AlbumsToDownload int `json:"albums_to_download"`
|
|
AlbumsPresent int `json:"albums_present"`
|
|
Playlists []PlaylistReport `json:"playlists"`
|
|
}
|
|
|
|
type PlaylistReport struct {
|
|
Name string `json:"name"`
|
|
URL string `json:"url"`
|
|
Mode string `json:"mode"`
|
|
M3UPath string `json:"m3u_path,omitempty"`
|
|
TracksTotal int `json:"tracks_total"`
|
|
AlbumsTotal int `json:"albums_total"`
|
|
AlbumsMatched int `json:"albums_matched"`
|
|
AlbumsUnmatched int `json:"albums_unmatched"`
|
|
TracksWritten int `json:"tracks_written"`
|
|
TracksMissing int `json:"tracks_missing"`
|
|
UnmatchedAlbums []AlbumIssue `json:"unmatched_albums,omitempty"`
|
|
MissingTracks []TrackIssue `json:"missing_tracks,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
type AlbumIssue struct {
|
|
Artist string `json:"artist"`
|
|
Title string `json:"title"`
|
|
UPC string `json:"upc,omitempty"`
|
|
Reason string `json:"reason,omitempty"`
|
|
}
|
|
|
|
type TrackIssue struct {
|
|
Artist string `json:"artist"`
|
|
Title string `json:"title"`
|
|
Album string `json:"album,omitempty"`
|
|
ISRC string `json:"isrc,omitempty"`
|
|
Reason string `json:"reason,omitempty"`
|
|
}
|
|
|
|
func Write(path string, r *Report) error {
|
|
data, err := json.MarshalIndent(r, "", " ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
data = append(data, '\n')
|
|
return state.WriteFileAtomic(path, data)
|
|
}
|