diff --git a/apps/website/src/data/showcase.ts b/apps/website/src/data/showcase.ts index f45d51206..9f99d2eb0 100644 --- a/apps/website/src/data/showcase.ts +++ b/apps/website/src/data/showcase.ts @@ -182,7 +182,7 @@ export const ShowcaseResource: IShowcase = { extractors: PromotedList.extractors.concat([ { name: 'discord-player-deezer', - description: 'An unofficial extractor for discord-player to add support for deezer source.', + description: 'An official extractor for discord-player to add support for deezer source.', url: 'https://npm.im/discord-player-deezer' }, { diff --git a/packages/discord-player/package.json b/packages/discord-player/package.json index 9d62935fa..75a335758 100644 --- a/packages/discord-player/package.json +++ b/packages/discord-player/package.json @@ -65,6 +65,7 @@ "@types/ip": "^1.1.0", "@types/node": "^18.6.3", "@types/ws": "^8.5.3", + "@web-scrobbler/metadata-filter": "^3.1.0", "discord-api-types": "^0.37.0", "discord.js": "^14.1.2", "opusscript": "^0.0.8", diff --git a/packages/discord-player/src/fabric/Track.ts b/packages/discord-player/src/fabric/Track.ts index c112f349b..1887b84fd 100644 --- a/packages/discord-player/src/fabric/Track.ts +++ b/packages/discord-player/src/fabric/Track.ts @@ -7,7 +7,8 @@ import { BaseExtractor } from '../extractors/BaseExtractor'; import { Collection } from '@discord-player/utils'; import { TypeUtil } from '../utils/TypeUtil'; import { SerializedType, tryIntoThumbnailString } from '../utils/serde'; -import { Exceptions } from '../errors'; +import { Exceptions } from '../errors'; +import { Util } from '../utils/Util'; export type TrackResolvable = Track | string | number; @@ -36,6 +37,7 @@ export class Track { public readonly id = SnowflakeUtil.generate().toString(); private __metadata: T | null = null; private __reqMetadataFn: () => Promise; + public cleanTitle: string; /** * Track constructor @@ -56,6 +58,7 @@ export class Track { this.raw = Object.assign({}, { source: data.raw?.source ?? data.source }, data.raw ?? data); this.__metadata = data.metadata ?? null; this.__reqMetadataFn = data.requestMetadata || (() => Promise.resolve(null)); + this.cleanTitle = data.cleanTitle ?? Util.cleanTitle(this.title, this.source); } /** diff --git a/packages/discord-player/src/types/types.ts b/packages/discord-player/src/types/types.ts index 2122b6d8d..398d00968 100644 --- a/packages/discord-player/src/types/types.ts +++ b/packages/discord-player/src/types/types.ts @@ -124,6 +124,10 @@ export interface RawTrackData { * The query type */ queryType?: SearchQueryType; + /** + * The seralised title + */ + cleanTitle?: string } export interface TimeData { diff --git a/packages/discord-player/src/utils/Util.ts b/packages/discord-player/src/utils/Util.ts index eedee5afc..0565c80fd 100644 --- a/packages/discord-player/src/utils/Util.ts +++ b/packages/discord-player/src/utils/Util.ts @@ -5,6 +5,8 @@ import { GuildQueue } from '../queue'; import { Playlist, Track } from '../fabric'; import { Exceptions } from '../errors'; import { randomInt } from 'node:crypto'; +import { createFilter, createSpotifyFilter, fixTrackSuffix, removeLive, removeRemastered, youtube } from '@web-scrobbler/metadata-filter'; +import { TrackSource } from '../../dist'; export type RuntimeType = 'node' | 'deno' | 'bun' | 'unknown'; @@ -102,6 +104,28 @@ class Util { return channel && channel.members.filter((member) => !member.user.bot).size === 0; } + static cleanTitle(title: string, source: TrackSource) { + const filterOpts = { + track: [ + removeRemastered, + removeLive, + fixTrackSuffix + ] + }; + const spotifyFilter = createFilter(filterOpts); + spotifyFilter.extend(createSpotifyFilter()); + const defaultFilter = createFilter(filterOpts); + + switch(source) { + case "youtube": + return youtube(title); + case "spotify": + return spotifyFilter.filterField("track", title); + default: + return defaultFilter.filterField("track", title); + } + } + /** * Safer require * @param {string} id Node require id diff --git a/packages/extractor/src/extractors/AppleMusicExtractor.ts b/packages/extractor/src/extractors/AppleMusicExtractor.ts index 87f85c59d..e3732ef9f 100644 --- a/packages/extractor/src/extractors/AppleMusicExtractor.ts +++ b/packages/extractor/src/extractors/AppleMusicExtractor.ts @@ -232,7 +232,7 @@ export class AppleMusicExtractor extends BridgedExtractor metadata: trackInfo, requestMetadata: async () => { return trackInfo; - } + }, + cleanTitle: trackInfo.title }); newTrack.extractor = this; @@ -112,7 +113,8 @@ export class SoundCloudExtractor extends BaseExtractor metadata: trackInfo, requestMetadata: async () => { return trackInfo; - } + }, + cleanTitle: trackInfo.title }); track.extractor = this; @@ -156,7 +158,8 @@ export class SoundCloudExtractor extends BaseExtractor metadata: song, requestMetadata: async () => { return song; - } + }, + cleanTitle: song.title }); track.extractor = this; track.playlist = res; diff --git a/packages/extractor/src/extractors/common/helper.ts b/packages/extractor/src/extractors/common/helper.ts index 25a2eeb46..293023701 100644 --- a/packages/extractor/src/extractors/common/helper.ts +++ b/packages/extractor/src/extractors/common/helper.ts @@ -279,7 +279,7 @@ export async function loadYtdl(options?: any, force = false) { const cookie = options?.requestOptions?.headers?.cookie; - if(cookie && typeof cookie === "string") dl.cookie = cookie + if(cookie && typeof cookie === "string") dl.cookie = cookie; // @ts-ignore Default lib did not provide types for this function // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/yarn.lock b/yarn.lock index f27138303..9ad27f0f4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3651,6 +3651,13 @@ __metadata: languageName: node linkType: hard +"@web-scrobbler/metadata-filter@npm:^3.1.0": + version: 3.1.0 + resolution: "@web-scrobbler/metadata-filter@npm:3.1.0" + checksum: 71e0ff278efc0c6d09bc60cf1cde67e67369d6fb13aee7dcb946a18f02c5387bfb8a391e65fe945f7a4c4cd3fdaad02539a197ff5e14961719eb1349fc42d393 + languageName: node + linkType: hard + "abbrev@npm:1, abbrev@npm:^1.0.0": version: 1.1.1 resolution: "abbrev@npm:1.1.1" @@ -4893,6 +4900,7 @@ __metadata: "@types/ip": "npm:^1.1.0" "@types/node": "npm:^18.6.3" "@types/ws": "npm:^8.5.3" + "@web-scrobbler/metadata-filter": "npm:^3.1.0" discord-api-types: "npm:^0.37.0" discord-voip: "npm:^0.1.3" discord.js: "npm:^14.1.2"