Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/bot/src/utils/music/queueManipulation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,6 @@ describe('queueManipulation.replenishQueue', () => {
url: 'https://example.com/karma',
metadata: expect.objectContaining({
isAutoplay: true,
recommendationReason: expect.stringContaining('last.fm'),
}),
}),
)
Expand Down
34 changes: 33 additions & 1 deletion packages/bot/src/utils/music/queueManipulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
const MAX_TRACKS_PER_ARTIST = 2
const MAX_TRACKS_PER_SOURCE = 3
const LASTFM_SEED_COUNT = 3
const LASTFM_SCORE_BOOST = 0.1
const LASTFM_SCORE_BOOST = 0.0

Check warning on line 44 in packages/bot/src/utils/music/queueManipulation.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Don't use a zero fraction in the number.

See more on https://sonarcloud.io/project/issues?id=LucasSantana-Dev_Lucky&issues=AZ2ILRmO9gu5vfpUkL_L&open=AZ2ILRmO9gu5vfpUkL_L&pullRequest=591
const MAX_SIMILAR_LOOKUPS = 5
const QUEUE_RESCUE_PROBE_TIMEOUT_MS = Number.parseInt(
process.env.QUEUE_RESCUE_PROBE_TIMEOUT_MS ?? '5000',
Expand Down Expand Up @@ -291,6 +291,8 @@
const currentTrack = queue.currentTrack ?? finishedTrack ?? null
if (!currentTrack) return

purgeDuplicatesOfCurrentTrack(queue, currentTrack)

const missingTracks = AUTOPLAY_BUFFER_SIZE - queue.tracks.size
if (missingTracks <= 0) return

Expand Down Expand Up @@ -654,6 +656,36 @@
return result
}

function purgeDuplicatesOfCurrentTrack(
queue: GuildQueue,
currentTrack: Track,
): void {
const urls = new Set<string>()
if (currentTrack.url) {
urls.add(currentTrack.url)
const vid = extractYouTubeVideoId(currentTrack.url)
if (vid) urls.add(vid)
}
const keys = new Set<string>()
keys.add(normalizeTrackKey(currentTrack.title, currentTrack.author))
keys.add(normalizeTitleOnly(currentTrack.title))
const core = extractSongCore(currentTrack.title ?? '', currentTrack.author)
if (core) keys.add(normalizeText(core))

for (const track of queue.tracks.toArray()) {
if (isDuplicateCandidate(track, urls, keys)) {
queue.node.remove(track)
debugLog({
message: 'Autoplay: purged stale duplicate of now-playing',
data: {
removed: track.title,
nowPlaying: currentTrack.title,
},
})
}
}
}

function buildExcludedKeys(
queue: GuildQueue,
currentTrack: Track,
Expand Down
2 changes: 2 additions & 0 deletions packages/bot/src/utils/music/searchQueryCleaner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ const NOISE_PATTERNS: readonly RegExp[] = [
/#\S+/g,
/\(tradu[çc][aã]o[^)]*\)/gi,
/\[tradu[çc][aã]o[^\]]*\]/gi,
/\btradu[çc][aã]o\b/gi,
/\btraduzido\b/gi,
/\blegendado\b/gi,
/\(clipe\s+oficial[^)]*\)/gi,
/\[clipe\s+oficial[^\]]*\]/gi,
Expand Down
Loading