This implementation of cmd/msrfetch is only temporary, used to fetch the testdata. At this point we have all metadata present in the repo and all that is left is to fetch the media. Signed-off-by: Yonah <contrib@gensokyo.uk>
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"log"
|
|
|
|
"git.gensokyo.uk/yonah/monstersirenfetch"
|
|
)
|
|
|
|
var (
|
|
flagAlbumsPath string
|
|
flagSongsPath string
|
|
flagOutputPath string
|
|
)
|
|
|
|
func init() {
|
|
flag.StringVar(&flagAlbumsPath, "a", "albums.json",
|
|
"Path to file containing the response body of /api/albums")
|
|
flag.StringVar(&flagSongsPath, "s", "songs.json",
|
|
"Path to file containing the response body of /api/songs")
|
|
flag.StringVar(&flagOutputPath, "o", "composite.json",
|
|
"Path to write composite data")
|
|
}
|
|
|
|
func mustEnrich(ctx context.Context) {
|
|
var (
|
|
albumsResponse monstersirenfetch.AlbumsResponse
|
|
songsResponse monstersirenfetch.SongsResponse
|
|
)
|
|
mustReadJSON(flagAlbumsPath, &albumsResponse)
|
|
mustReadJSON(flagSongsPath, &songsResponse)
|
|
|
|
if c, err := monstersirenfetch.Flatten(albumsResponse.Data, songsResponse.Data); err != nil {
|
|
log.Fatal(err)
|
|
} else {
|
|
n := new(netDirect)
|
|
for _, ca := range c {
|
|
log.Printf("enriching album %s (%s)", ca.Name, ca.CID.String())
|
|
for _, cs := range ca.Songs {
|
|
if !cs.IsFull() {
|
|
if err = cs.Enrich(ctx, n); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
log.Printf("enriched song %s: %s (%s)", cs.CID.String(), cs.SourceURL, cs.Name)
|
|
} else {
|
|
log.Printf("skipped song %s: %s (%s)", cs.CID.String(), cs.SourceURL, cs.Name)
|
|
}
|
|
}
|
|
}
|
|
mustWriteJSON(flagOutputPath, c)
|
|
log.Println("composite data written to", flagOutputPath)
|
|
}
|
|
}
|