Files
minstrel/internal/library/source_markers.go
T
bvandeusenandClaude Opus 5.5 1aea3e9a1b
release / go (push) Successful in 2m1s
release / web (push) Successful in 1m18s
release / govulncheck (push) Successful in 20s
release / integration (push) Successful in 4m11s
release / android (push) Successful in 4m4s
release / Build signed APK (push) Successful in 4m33s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
chore: take workbench pointers and real library data out of the public tree
A sweep of the export (git archive) against the release leak standard:

- Internal ids in comments: a split "(rule 157)", two "RULE 131" headers
  and a "Preference 172" the id search missed because it was
  case-sensitive.
- Comments that quoted or credited the operator (shuffle caps, mix
  rotation, player bar layout, ID3v1 table).
- Real artists still in the suspect-source fixtures (and the Beck example
  in its comment): replaced with invented ones in the same file shapes.
- "26,171 tracks", a count from a real library, in the plural examples:
  now 12,345.
- Comments pointing at CI files the export leaves out (release.yml, the
  ci-go image, the Gitea keystore secret, an M8 milestone, .dockerignore
  history); client/README describes the release image, not the lanes.
- renovate.json is export-ignore: it targets the workbench's dev branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 06:56:35 -05:00

70 lines
2.4 KiB
Go

package library
import (
"path"
"regexp"
"strings"
)
// sourceMarker is one sign that a file was ripped from a video rather than
// taken from a release: words a video title carries and an album track does
// not.
//
// Each pattern is used twice, so it is written in the subset that Postgres's
// regex flavour and Go's RE2 read the same way: no \b (Postgres spells word
// boundaries \y), no lookaround, and brackets written as (\(|\[) rather than
// as a bracket expression. The SQL side matches it case-insensitively with ~*,
// the Go side with (?i); [^a-zA-Z] is spelled out so neither has to fold case
// inside a negated class.
type sourceMarker struct {
label string
pattern string
}
// suspectSourceMarkers was calibrated against a real library. Two candidates
// were left out on purpose:
// - "live in"/"live at": nearly all from real live albums.
// - a bare "reaction": it caught songs called "Chain Reaction". The marker below
// wants the phrases a reaction video actually uses.
var suspectSourceMarkers = []sourceMarker{
{"music video", `official[^a-zA-Z]*(music[^a-zA-Z]*)?video|music[^a-zA-Z]*video`},
{"official audio", `official[^a-zA-Z]*audio`},
{"lyric video", `lyrics?[^a-zA-Z]*video`},
{"visualiser", `visuali[sz]er`},
{"reaction", `reaction[^a-zA-Z]*(video|mashup)|reacts?[^a-zA-Z]+to[^a-zA-Z]|first[^a-zA-Z]*time[^a-zA-Z]*(hearing|listening)`},
{"MV", `(^|[^a-zA-Z])(mv|m/v)([^a-zA-Z]|$)`},
{"[Audio]", `(\(|\[)audio(\)|\])`},
{"[HD]", `(\(|\[)(hd|hq|4k)(\)|\])`},
}
// SuspectSourcePattern is every marker as one alternation, for the SQL filter
// behind the admin suspect-sources report.
var SuspectSourcePattern = func() string {
parts := make([]string, len(suspectSourceMarkers))
for i, m := range suspectSourceMarkers {
parts[i] = "(" + m.pattern + ")"
}
return strings.Join(parts, "|")
}()
var suspectSourceRegexps = func() []*regexp.Regexp {
out := make([]*regexp.Regexp, len(suspectSourceMarkers))
for i, m := range suspectSourceMarkers {
out[i] = regexp.MustCompile("(?i)" + m.pattern)
}
return out
}()
// SourceMarkersFor returns the labels of every marker the file's basename
// carries, in list order. Empty for a file the SQL filter would not return.
func SourceMarkersFor(filePath string) []string {
base := path.Base(filePath)
labels := make([]string, 0, 2)
for i, re := range suspectSourceRegexps {
if re.MatchString(base) {
labels = append(labels, suspectSourceMarkers[i].label)
}
}
return labels
}