Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
achiragaming committed Nov 21, 2024
1 parent 8eddedf commit 86423a0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "damonjs",
"version": "2.1.1",
"version": "2.1.2",
"preview": false,
"description": "A modified Shoukaku wrapper with enhanced queue support.",
"main": "dist/Index.js",
Expand Down
63 changes: 35 additions & 28 deletions src/Managers/Supports/DamonJsTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,55 +180,62 @@ export class DamonJsTrack {
}
return this;
}
private getTrackScore(track: any): number {
private getTrackScore(track: Track): number {
let score = 0;
const title = track.info.title.toLowerCase();
const author = track.info.author.toLowerCase();

// Prefer "Topic" channels
if (author.includes('- topic')) score += 3;

// Lower score for music videos
if (title.includes('official video') ||
title.includes('music video') ||
if (track.info.sourceName === 'youtube') {
// Prefer "Topic" channels
if (author.includes('- topic')) score += 3;

// Lower score for music videos
if (
title.includes('official video') ||
title.includes('music video') ||
title.includes('official mv') ||
title.includes('(video)') ||
title.includes('[video]')) {
title.includes('[video]')
) {
score -= 2;
}
}

// Prefer "audio" tracks
if (title.includes('audio') || title.includes('lyric')) score += 1;
// Prefer "audio" tracks
if (title.includes('audio') || title.includes('lyric')) score += 1;
} else if (track.info.sourceName === 'soundcloud') {
// Prefer "audio" tracks
if (author.includes('official')) score += 2;
if (title.includes('original mix')) score += 3;
if (title.includes('remix')) score -= 1;
if (title.includes('repost')) score -= 2;
if (title.includes('cover')) score -= 1;
}

return score;
}
}
private filterPlayableTrack(track: Track): boolean {
if (track.info.sourceName === 'soundcloud' && track.info.identifier.includes('/preview/')) {
return false;
}
return true;
}
private async getTrack(player: DamonJsPlayer, source: any): Promise<Track> {
if (!this.damonjs) throw new DamonJsError(1, 'DamonJs is not set');
const query = [this.author, this.title].filter((x) => !!x).join(' - ');
const result = await player.search(`${query}`, { requester: this.requester, engine: source });
if (!result || !result.tracks.length) throw new DamonJsError(2, 'No results found');
const rawTracks = result.tracks.map((x) => x.getRaw()._raw);
// Filter out preview tracks
const filteredTracks = rawTracks.filter((track) => {
// Filter out SoundCloud previews
if (track.info.sourceName === 'soundcloud' && track.info.identifier.includes('/preview/')) {
return false;
}
// Add more platform-specific preview checks here as needed
return true;
});
const filteredTracks = rawTracks.filter((track) => this.filterPlayableTrack(track));

if (!filteredTracks.length) throw new DamonJsError(2, 'No non-preview tracks found');

const sortedTracks = filteredTracks.sort((a, b) => {
if (a.info.sourceName === 'youtube') {
// Prioritize "Topic" channels and tracks without "Official Video" in title
const aScore = this.getTrackScore(a);
const bScore = this.getTrackScore(b);
return bScore - aScore;
}
return 0;
});
// Prioritize "Topic" channels and tracks without "Official Video" in title
const aScore = this.getTrackScore(a);
const bScore = this.getTrackScore(b);
return bScore - aScore;
});
return sortedTracks[0];
}
}

0 comments on commit 86423a0

Please sign in to comment.