WIP
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/fujin/music-agregator/internal/database"
|
||||
"github.com/fujin/music-agregator/internal/indexer"
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type RankedSearchResult struct {
|
||||
@@ -30,11 +31,16 @@ func SearchAlbum(
|
||||
db *database.DB,
|
||||
indexerService *IndexerService,
|
||||
) (*AlbumSearchResult, error) {
|
||||
log.Info().Str("album_id", albumID.String()).Msg("[ALBUM_SEARCH] starting search")
|
||||
|
||||
album, err := db.GetAlbumDetailByID(ctx, albumID)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("album_id", albumID.String()).Msg("[ALBUM_SEARCH] album not found")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Info().Str("artist", album.ArtistName).Str("album", album.Title).Msg("[ALBUM_SEARCH] searching for album")
|
||||
|
||||
var year *uint32
|
||||
if album.ReleaseDate != nil {
|
||||
y := uint32(album.ReleaseDate.Year())
|
||||
@@ -51,13 +57,18 @@ func SearchAlbum(
|
||||
|
||||
results, err := indexerService.Search(ctx, criteria, nil)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("[ALBUM_SEARCH] indexer search failed")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Info().Int("raw_results", len(results)).Msg("[ALBUM_SEARCH] got raw results from indexers")
|
||||
|
||||
var rankedResults []RankedSearchResult
|
||||
var blockedCount int
|
||||
for _, r := range results {
|
||||
blocked, _ := db.IsBlocklisted(ctx, r.Title, r.Infohash)
|
||||
if blocked {
|
||||
blockedCount++
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -71,10 +82,30 @@ func SearchAlbum(
|
||||
})
|
||||
}
|
||||
|
||||
if blockedCount > 0 {
|
||||
log.Info().Int("blocked", blockedCount).Msg("[ALBUM_SEARCH] filtered blocklisted results")
|
||||
}
|
||||
|
||||
sort.Slice(rankedResults, func(i, j int) bool {
|
||||
return rankedResults[i].Score > rankedResults[j].Score
|
||||
})
|
||||
|
||||
if len(rankedResults) > 0 {
|
||||
best := rankedResults[0]
|
||||
seeders := 0
|
||||
if best.Seeders != nil {
|
||||
seeders = *best.Seeders
|
||||
}
|
||||
log.Info().
|
||||
Str("title", best.Title).
|
||||
Str("quality", best.Quality).
|
||||
Float64("score", best.Score).
|
||||
Int("seeders", seeders).
|
||||
Msg("[ALBUM_SEARCH] best result")
|
||||
}
|
||||
|
||||
log.Info().Int("total_results", len(rankedResults)).Msg("[ALBUM_SEARCH] search completed")
|
||||
|
||||
return &AlbumSearchResult{
|
||||
AlbumID: albumID.String(),
|
||||
AlbumTitle: album.Title,
|
||||
|
||||
Reference in New Issue
Block a user