172 lines
4.8 KiB
Go
172 lines
4.8 KiB
Go
package tracker
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
metadataPb "homelab.lan/music-agregator/gen/metadata/v1"
|
|
"homelab.lan/music-agregator/internal/release"
|
|
)
|
|
|
|
func TestGenericParser_Parse(t *testing.T) {
|
|
p := NewGenericParser()
|
|
|
|
tests := []struct {
|
|
name string
|
|
title string
|
|
wantBitrate string
|
|
wantBitDepth int
|
|
wantSampleRate int
|
|
wantSource release.Source
|
|
wantRipType string
|
|
}{
|
|
{
|
|
name: "discography no hires",
|
|
title: "System Of A Down - Discography [FLAC Songs] [PMEDIA]",
|
|
},
|
|
{
|
|
name: "hiphop hires 24-44",
|
|
title: "Snoop Dogg - 10 Til' Midnight (2026 Hip Hop Rap) [Flac 24-44]",
|
|
wantBitDepth: 24,
|
|
wantSampleRate: 44000,
|
|
},
|
|
{
|
|
name: "pop hires 24bit",
|
|
title: "Sabrina Carpenter - Short n' Sweet [Deluxe] [2025] [Hi-Res FLAC 24bit]-Sc4r3cr0w",
|
|
wantBitDepth: 24,
|
|
},
|
|
{
|
|
name: "rock hires 24bit",
|
|
title: "Linkin Park - From Zero [Deluxe Edition] [2025] [Hi-Res] [FLAC-24bit]-Sc4r3cr0w",
|
|
},
|
|
{
|
|
name: "rock hires 24-48",
|
|
title: "Linkin Park - From Zero (2024) [24Bit-48kHz] FLAC [PMEDIA]",
|
|
wantBitDepth: 24,
|
|
wantSampleRate: 48000,
|
|
},
|
|
{
|
|
name: "hiphop hires 24-96",
|
|
title: "J. Cole - The Fall-Off (2026 Hip Hop Rap) [Flac 24-96]",
|
|
wantBitDepth: 24,
|
|
wantSampleRate: 96000,
|
|
},
|
|
{
|
|
name: "minimal format",
|
|
title: "Bjork-Bastards.2012.FLAC-NewAlbumReleases",
|
|
},
|
|
{
|
|
name: "vinyl hires",
|
|
title: "Gorillaz - Demon Days [Live From The Apollo Theater] [2025] [Vinyl Hi-Res] [FLAC-24bit]-Sc4r3cr0w",
|
|
},
|
|
{
|
|
name: "cd with log",
|
|
title: "Linkin Park - Meteora (Tracks, Log, Cue, Scans) (2003) [FLAC] 88",
|
|
},
|
|
{
|
|
name: "rock 16-44",
|
|
title: "Heart - Jupiters Darling (2004 Rock) [Flac 16-44]",
|
|
wantBitDepth: 16,
|
|
wantSampleRate: 44000,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
r := p.Parse(tt.title)
|
|
|
|
if tt.wantBitrate != "" && r.Bitrate != tt.wantBitrate {
|
|
t.Errorf("Bitrate = %q, want %q", r.Bitrate, tt.wantBitrate)
|
|
}
|
|
if tt.wantBitDepth != 0 && r.BitDepth != tt.wantBitDepth {
|
|
t.Errorf("BitDepth = %d, want %d", r.BitDepth, tt.wantBitDepth)
|
|
}
|
|
if tt.wantSampleRate != 0 && r.SampleRate != tt.wantSampleRate {
|
|
t.Errorf("SampleRate = %d, want %d", r.SampleRate, tt.wantSampleRate)
|
|
}
|
|
if tt.wantSource != release.SourceUnknown && r.Source != tt.wantSource {
|
|
t.Errorf("Source = %v, want %v", r.Source, tt.wantSource)
|
|
}
|
|
if tt.wantRipType != "" && r.RipType != tt.wantRipType {
|
|
t.Errorf("RipType = %q, want %q", r.RipType, tt.wantRipType)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGenericParser_ParseTorrent(t *testing.T) {
|
|
torrentData, err := os.ReadFile("/tmp/metallica.torrent")
|
|
if err != nil {
|
|
t.Skip("metallica.torrent not available")
|
|
}
|
|
|
|
album := &metadataPb.Album{
|
|
Title: "72 Seasons",
|
|
AlbumType: "Album",
|
|
ReleaseDate: "2023-04-14",
|
|
TotalTracks: 12,
|
|
TotalDiscs: 1,
|
|
Artists: []*metadataPb.ArtistCredit{
|
|
{Artist: &metadataPb.Artist{Name: "Metallica"}},
|
|
},
|
|
Genres: []*metadataPb.Genre{
|
|
{Name: "Thrash Metal"},
|
|
{Name: "Heavy Metal"},
|
|
},
|
|
Label: &metadataPb.Label{Name: "Blackened Recordings"},
|
|
}
|
|
|
|
p := NewGenericParser()
|
|
r := p.ParseTorrent(torrentData, album)
|
|
|
|
t.Logf("Artist: %s", r.Artist)
|
|
t.Logf("Album: %s", r.Album)
|
|
t.Logf("Year: %d", r.Year)
|
|
t.Logf("Type: %s", r.Type)
|
|
t.Logf("Genres: %v", r.Genres)
|
|
t.Logf("Format: %s", r.Format)
|
|
t.Logf("Source: %s", r.Source)
|
|
t.Logf("Label: %s", r.Label)
|
|
t.Logf("InfoHash: %s", r.InfoHash)
|
|
t.Logf("TrackCount: %d", r.TrackCount)
|
|
t.Logf("AudioFiles: %d", r.AudioFileCount)
|
|
t.Logf("AudioSize: %d bytes", r.TotalAudioSize)
|
|
t.Logf("HasCover: %v", r.HasCoverArt)
|
|
t.Logf("HasCue: %v", r.HasCueSheet)
|
|
t.Logf("HasLog: %v", r.HasRipLog)
|
|
t.Logf("TrackNames: %v", r.TrackNames)
|
|
t.Logf("Parsed OK: %v", r.ParsedSuccessfully)
|
|
t.Logf("Errors: %v", r.ParseErrors)
|
|
|
|
if r.Artist != "Metallica" {
|
|
t.Errorf("Artist = %q, want Metallica", r.Artist)
|
|
}
|
|
if r.Album != "72 Seasons" {
|
|
t.Errorf("Album = %q, want 72 Seasons", r.Album)
|
|
}
|
|
if r.Year != 2023 {
|
|
t.Errorf("Year = %d, want 2023", r.Year)
|
|
}
|
|
if r.Format != release.FormatFLAC {
|
|
t.Errorf("Format = %v, want FLAC", r.Format)
|
|
}
|
|
if r.AudioFileCount != 12 {
|
|
t.Errorf("AudioFileCount = %d, want 12", r.AudioFileCount)
|
|
}
|
|
if !r.HasCoverArt {
|
|
t.Error("expected HasCoverArt")
|
|
}
|
|
if !r.HasCueSheet {
|
|
t.Error("expected HasCueSheet")
|
|
}
|
|
if !r.HasRipLog {
|
|
t.Error("expected HasRipLog")
|
|
}
|
|
if r.Source != release.SourceCD {
|
|
t.Errorf("Source = %v, want CD (inferred from log)", r.Source)
|
|
}
|
|
if !r.ParsedSuccessfully {
|
|
t.Errorf("ParsedSuccessfully = false, errors: %v", r.ParseErrors)
|
|
}
|
|
}
|