Skip to content

Commit

Permalink
[Matching] Improve accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
Schaka committed Nov 6, 2024
1 parent d3f42f5 commit 51f2a1e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class MatchService {

private fun matchTracks(result: SearchResult, trackResults: List<TrackMatchResult>): SearchMatchResult {
var score = 10.0

if (!result.hasFreeUploadSlot) {
// small punishment for not *currently* having an upload slot
score -= 1
Expand All @@ -92,7 +93,6 @@ class MatchService {
val relevantFiles = result.files.filter(this::musicFilter)
score -= abs(relevantFiles.size - trackResults.size)

// TODO: boost FLAC *properly*
val isFlac = relevantFiles.filter { it.extension == "flac" || cleanupFilename(it.filename).fileName.endsWith(".flac") }.size >= (relevantFiles.size / 2.0)
|| trackResults.filter { it.file?.filename?.endsWith("flac") == true }.size >= (trackResults.size / 2.0)
if (isFlac) {
Expand All @@ -104,14 +104,24 @@ class MatchService {
score += trackResult.score
}

// boosting bitDepth
relevantFiles.filter { it.bitDepth == 24 }.forEach { score+= 1.0 / relevantFiles.size }

// TODO: boost bitdepth
trackResults.forEach {
val expectedRunTime = it.lidarrTrack.duration
val runTime = it.file?.length ?: 0

//TODO: match runtime
if (it.file != null && musicFilter(it.file) && expectedRunTime > 0 && runTime > 0
&& abs(expectedRunTime - runTime) <= expectedRunTime * 0.1) {
// within 10% of each other's runtime
score+= 1.0 / relevantFiles.size
}
}


// Better matching via Artist + Album + Track, maybe?
// https://github.com/guessit-io/guessit type for audio (part extraction)
// beets match? https://github.com/beetbox/beets

return SearchMatchResult(result, score, trackResults)

}
Expand All @@ -134,7 +144,7 @@ class MatchService {
}
writer.close()

// FIXME: Turn query into 2 steps - first an exact match on "TrackName" or "Artist - TrackName", then more error prone, but tolerant Lucene search
// TODO: Turn query into 2 steps - first an exact match on "TrackName" or "Artist - TrackName", then more error prone, but tolerant Lucene search
val reader = DirectoryReader.open(memoryIndex)
val searcher = IndexSearcher(reader)
val storedFields = searcher.storedFields()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class LidarrRestService(
val albums = lidarrClient.getAlbums(artist.id).map { album ->
val tracks = lidarrClient.getTrackFiles(album.id)
//FIXME: if empty, get filenaming structure from Lidarr and build folder name from it
// this isn't very easy, we don't have access to a lot of the necessary variables
val trackPath = tracks.firstOrNull() ?: TrackFile(-1, Path.of(artist.path).resolve("dummy-album/dummy-track.flac").toString())
val path = Path.of(trackPath.path)
album.path = path.parent.toString()
Expand Down

0 comments on commit 51f2a1e

Please sign in to comment.