Skip to content

Commit

Permalink
removed the string similarity because it does not work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
achiragaming committed Jan 2, 2024
1 parent 4b72f7b commit ab92fe6
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 58 deletions.
13 changes: 3 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "damonjs",
"version": "1.5.4",
"version": "1.5.5",
"preview": false,
"description": "A modified Shoukaku wrapper with enhanced queue support.",
"main": "dist/Index.js",
Expand Down Expand Up @@ -49,8 +49,7 @@
},
"dependencies": {
"events": "^3.3.0",
"shoukaku": "^4.0.1",
"string-similarity": "^4.0.4"
"shoukaku": "^4.0.1"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export * from './DamonJs';
export { DamonJsTrack, DamonJsQueue, DamonJsPlayer, Plugins };
export * from './Modules/Interfaces';

export const version = '1.5.4';
export const version = '1.5.5';
41 changes: 1 addition & 40 deletions src/Managers/Supports/DamonJsTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Track } from 'shoukaku';
import { DamonJsPlayer } from '../DamonJsPlayer';
import { DamonJsUtils } from '../../Modules/Utils';
import { Utils } from 'discord.js';
import stringSimilarity from 'string-similarity';
export class DamonJsTrack {
/**
* DamonJs Instance
Expand Down Expand Up @@ -176,52 +175,14 @@ export class DamonJsTrack {
}
return this;
}
private fixTitle(title: string) {
const target = title
.replace(/\[.*?\]/g, '') // Remove content within square brackets
.replace(/\(.*?\)/g, '') // Remove content within parentheses
.replace(/- .*? -/g, '') // Remove content within hyphens
.replace(/:.*/, '') // Remove content after colon
.replace(/\|.*$/, '') // Remove content after the first occurrence of |
.replace(/\s+/g, ' ') // Replace multiple spaces with single space
.trim();

// Trim excess spaces
return target.trim();
}
private async getTrack(player: DamonJsPlayer): Promise<Track> {
if (!this.damonjs) throw new DamonJsError(1, 'DamonJs is not set');
const defaultSearchEngine = this.damonjs.DamonJsOptions.defaultSearchEngine;
const source = (SourceIDs as any)[defaultSearchEngine || 'youtube'] || 'yt';
const query = [this.author, this.title].filter((x) => !!x).join(' - ');
const result = await player.search(`${query}`, { requester: this.requester, engine: source });
const threshold = this.damonjs.DamonJsOptions.trackResolveThreshold || 0.4;
if (!result || !result.tracks.length) throw new DamonJsError(2, 'No results found');
const shoukakUTracks = result.tracks.map((track) => DamonJsUtils.convertDamonJsTrackToTrack(track));
const matchedSongs: { threshold: number; track: Track }[] = [];
for (const track of shoukakUTracks) {
const titleScore = stringSimilarity.compareTwoStrings(
this.title,
[track.info.author, this.fixTitle(track.info.title)].filter((x) => !!x).join(' - '),
);
const authorScore = stringSimilarity.compareTwoStrings(this.author, track.info.author);
const duration = this.length ? this.length : 0;
const durationScore = track.info.length >= duration - 2000 && track.info.length <= duration + 2000 ? 1 : 0;

const totalScore = (titleScore + durationScore + authorScore) / 3;
matchedSongs.push({
threshold: totalScore || 0,
track,
});
}
const matchedSong = matchedSongs
.filter((val) => val.threshold >= threshold)
.map((val) => {
return val.track;
})
.at(0);
if (!matchedSong) throw new DamonJsError(2, 'No results found');

return matchedSong;
return shoukakUTracks[0];
}
}
4 changes: 0 additions & 4 deletions src/Modules/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ export interface DamonJsOptions {
sourceForceResolve?: string[];
/** The track resolver. Make sure you set <DamonJsTrack>.track for it to work. (I'm not responsible for any error during playback if you don't set it right) */
trackResolver?: (this: DamonJsTrack, options?: ResolveOptions) => Promise<boolean>;
/**
* The track resolve threshold.
*/
trackResolveThreshold?: number;
/** The default youtube thumbnail's size */
defaultYoutubeThumbnail?: YoutubeThumbnail;
/** Extend some of the Structures */
Expand Down

0 comments on commit ab92fe6

Please sign in to comment.