discord-player-deezer 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,25 +1,26 @@
1
- /// <reference types="node" />
2
- import { BaseExtractor, ExtractorInfo, ExtractorSearchContext, SearchQueryType, Track } from "discord-player";
3
- import { Readable } from "stream";
4
- import { default as SoundCloud } from "soundcloud.ts";
5
- interface DeezerOptions {
6
- bridgeFrom?: "YouTube" | "SoundCloud";
7
- soundcloud?: {
8
- clientId?: string;
9
- oauthToken?: string;
10
- proxy?: string;
11
- };
12
- onBeforeCreateStream?: (track: Track) => Promise<string | Readable>;
13
- }
14
- export default class DeezerExtractor extends BaseExtractor<DeezerOptions> {
15
- static identifier: string;
16
- private _stream;
17
- client: SoundCloud;
18
- private deezerRegex;
19
- activate(): Promise<void>;
20
- validate(query: string, _type?: SearchQueryType | null | undefined): Promise<boolean>;
21
- handle(query: string, context: ExtractorSearchContext): Promise<ExtractorInfo>;
22
- brdgeProvider(track: Track): Promise<string>;
23
- stream(info: Track): Promise<string | Readable>;
24
- }
25
- export {};
1
+ /// <reference types="node" />
2
+ import { BaseExtractor, ExtractorInfo, ExtractorSearchContext, SearchQueryType, Track } from "discord-player";
3
+ import { Readable } from "stream";
4
+ import { default as SoundCloud } from "soundcloud.ts";
5
+ interface DeezerOptions {
6
+ bridgeFrom?: "YouTube" | "SoundCloud";
7
+ soundcloud?: {
8
+ clientId?: string;
9
+ oauthToken?: string;
10
+ proxy?: string;
11
+ };
12
+ onBeforeCreateStream?: (track: Track) => Promise<string | Readable>;
13
+ }
14
+ export default class DeezerExtractor extends BaseExtractor<DeezerOptions> {
15
+ static identifier: string;
16
+ private _stream;
17
+ protocols: string[];
18
+ client: SoundCloud;
19
+ private deezerRegex;
20
+ activate(): Promise<void>;
21
+ validate(query: string, _type?: SearchQueryType | null | undefined): Promise<boolean>;
22
+ handle(query: string, context: ExtractorSearchContext): Promise<ExtractorInfo>;
23
+ brdgeProvider(track: Track): Promise<string>;
24
+ stream(info: Track): Promise<string | Readable>;
25
+ }
26
+ export {};
@@ -1,139 +1,138 @@
1
- 'use strict';
2
- var __importDefault =
3
- (this && this.__importDefault) ||
4
- function (mod) {
5
- return mod && mod.__esModule ? mod : { default: mod };
6
- };
7
- Object.defineProperty(exports, '__esModule', { value: true });
8
- const discord_player_1 = require('discord-player');
9
- const deezer_music_metadata_1 = require('@mithron/deezer-music-metadata');
10
- const youtube_sr_1 = require('youtube-sr');
11
- const yt_stream_1 = require('yt-stream');
12
- const soundcloud_ts_1 = __importDefault(require('soundcloud.ts'));
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const discord_player_1 = require("discord-player");
7
+ const deezer_music_metadata_1 = require("@mithron/deezer-music-metadata");
8
+ const youtube_sr_1 = require("youtube-sr");
9
+ const yt_stream_1 = require("yt-stream");
10
+ const soundcloud_ts_1 = __importDefault(require("soundcloud.ts"));
13
11
  class DeezerExtractor extends discord_player_1.BaseExtractor {
14
- constructor() {
15
- super(...arguments);
16
- this._stream = yt_stream_1.stream;
17
- this.client = new soundcloud_ts_1.default({
18
- clientId: this.options.soundcloud?.clientId,
19
- oauthToken: this.options.soundcloud?.oauthToken,
20
- proxy: this.options.soundcloud?.proxy,
21
- });
22
- this.deezerRegex = {
23
- track: /(^https:)\/\/(www\.)?deezer.com\/([a-zA-Z]+\/)?track\/[0-9]+/,
24
- playlistNalbums: /(^https:)\/\/(www\.)?deezer.com\/[a-zA-Z]+\/(playlist|album)\/[0-9]+(\?)?(.*)/,
25
- share: /(^https:)\/\/deezer\.page\.link\/[A-Za-z0-9]+/,
26
- };
27
- }
28
- async activate() {
29
- /* tslint:disable-next-line */
30
- if (!this.options.bridgeFrom) this.options.bridgeFrom === 'YouTube';
31
- }
32
- async validate(query, _type) {
33
- if (typeof query !== 'string') return false;
34
- return (
35
- this.deezerRegex.track.test(query) ||
36
- this.deezerRegex.playlistNalbums.test(query) ||
37
- this.deezerRegex.share.test(query)
38
- );
39
- }
40
- async handle(query, context) {
41
- if (this.deezerRegex.share.test(query)) {
42
- const fetchRes = await fetch(query);
43
- query = fetchRes.url.split('?')[0];
12
+ constructor() {
13
+ super(...arguments);
14
+ this._stream = yt_stream_1.stream;
15
+ this.protocols = ["deezer", "dzsearch"];
16
+ this.client = new soundcloud_ts_1.default({
17
+ clientId: this.options.soundcloud?.clientId,
18
+ oauthToken: this.options.soundcloud?.oauthToken,
19
+ proxy: this.options.soundcloud?.proxy
20
+ });
21
+ this.deezerRegex = {
22
+ track: /(^https:)\/\/(www\.)?deezer.com\/([a-zA-Z]+\/)?track\/[0-9]+/,
23
+ playlistNalbums: /(^https:)\/\/(www\.)?deezer.com\/[a-zA-Z]+\/(playlist|album)\/[0-9]+(\?)?(.*)/,
24
+ share: /(^https:)\/\/deezer\.page\.link\/[A-Za-z0-9]+/
25
+ };
44
26
  }
45
- const data = await (0, deezer_music_metadata_1.getData)(query);
46
- if (data?.type === 'song') {
47
- const returnData = {
48
- playlist: null,
49
- tracks: [
50
- new discord_player_1.Track(this.context.player, {
51
- title: data?.name,
52
- raw: data,
53
- description: '',
54
- author: data.author.map((artist) => artist.name).join(' '),
55
- url: data.url,
56
- source: 'arbitrary',
57
- thumbnail: data.thumbnail[0].url,
58
- duration: discord_player_1.Util.buildTimeCode(discord_player_1.Util.parseMS(data.duration * 1000)),
59
- views: 0,
60
- requestedBy: context.requestedBy,
61
- }),
62
- ],
63
- };
64
- return returnData;
27
+ async activate() {
28
+ /* tslint:disable-next-line */
29
+ if (!this.options.bridgeFrom)
30
+ this.options.bridgeFrom === "YouTube";
65
31
  }
66
- if (data?.type === 'playlist' || data?.type === 'album') {
67
- const raw = data.url.split('/');
68
- const identifier = raw[raw.length - 1];
69
- const playlist = new discord_player_1.Playlist(this.context.player, {
70
- title: data.name,
71
- thumbnail: data.thumbnail[0].url,
72
- author: {
73
- name: data.artist.name,
74
- url: data.artist.url,
75
- },
76
- type: data.type,
77
- rawPlaylist: data,
78
- tracks: [],
79
- description: '',
80
- source: 'arbitrary',
81
- id: identifier,
82
- url: data.url,
83
- });
84
- const tracks = data.tracks.map((track) => {
85
- return new discord_player_1.Track(this.context.player, {
86
- title: track.name,
87
- raw: track,
88
- description: '',
89
- author: track.author.map((artist) => artist.name).join(' '),
90
- url: track.url,
91
- source: 'arbitrary',
92
- thumbnail: track.thumbnail[0].url,
93
- duration: discord_player_1.Util.buildTimeCode(discord_player_1.Util.parseMS(track.duration * 1000)),
94
- views: 0,
95
- requestedBy: context.requestedBy,
96
- });
97
- });
98
- playlist.tracks = tracks;
99
- return {
100
- playlist,
101
- tracks,
102
- };
32
+ async validate(query, _type) {
33
+ if (typeof query !== "string")
34
+ return false;
35
+ return this.deezerRegex.track.test(query) || this.deezerRegex.playlistNalbums.test(query) || this.deezerRegex.share.test(query);
103
36
  }
104
- return { playlist: null, tracks: [] };
105
- }
106
- async brdgeProvider(track) {
107
- const query = this.createBridgeQuery(track);
108
- if (this.options.bridgeFrom === 'YouTube') {
109
- try {
110
- const serachResults = await youtube_sr_1.YouTube.search(query, {
111
- limit: 1,
112
- type: 'video',
113
- });
114
- const ytStream = await this._stream(serachResults[0].url, {
115
- quality: 'high',
116
- type: 'audio',
117
- highWaterMark: 1048576 * 32,
37
+ async handle(query, context) {
38
+ if (this.deezerRegex.share.test(query)) {
39
+ const fetchRes = await fetch(query);
40
+ query = fetchRes.url.split("?")[0];
41
+ }
42
+ const data = await (0, deezer_music_metadata_1.getData)(query);
43
+ if (data?.type === "song") {
44
+ const returnData = {
45
+ playlist: null,
46
+ tracks: [
47
+ new discord_player_1.Track(this.context.player, {
48
+ title: data?.name,
49
+ raw: data,
50
+ description: "",
51
+ author: data.author.map((artist) => artist.name).join(" "),
52
+ url: data.url,
53
+ source: "arbitrary",
54
+ thumbnail: data.thumbnail[0].url,
55
+ duration: discord_player_1.Util.buildTimeCode(discord_player_1.Util.parseMS(data.duration * 1000)),
56
+ views: 0,
57
+ requestedBy: context.requestedBy
58
+ })
59
+ ]
60
+ };
61
+ return returnData;
62
+ }
63
+ if (data?.type === "playlist" || data?.type === "album") {
64
+ const raw = data.url.split("/");
65
+ const identifier = raw[raw.length - 1];
66
+ const playlist = new discord_player_1.Playlist(this.context.player, {
67
+ title: data.name,
68
+ thumbnail: data.thumbnail[0].url,
69
+ author: {
70
+ name: data.artist.name,
71
+ url: data.artist.url
72
+ },
73
+ type: data.type,
74
+ rawPlaylist: data,
75
+ tracks: [],
76
+ description: "",
77
+ source: "arbitrary",
78
+ id: identifier,
79
+ url: data.url
80
+ });
81
+ const tracks = data.tracks.map(track => {
82
+ return new discord_player_1.Track(this.context.player, {
83
+ title: track.name,
84
+ raw: track,
85
+ description: "",
86
+ author: track.author.map((artist) => artist.name).join(" "),
87
+ url: track.url,
88
+ source: "arbitrary",
89
+ thumbnail: track.thumbnail[0].url,
90
+ duration: discord_player_1.Util.buildTimeCode(discord_player_1.Util.parseMS(track.duration * 1000)),
91
+ views: 0,
92
+ requestedBy: context.requestedBy
93
+ });
94
+ });
95
+ playlist.tracks = tracks;
96
+ return {
97
+ playlist,
98
+ tracks
99
+ };
100
+ }
101
+ return { playlist: null, tracks: [] };
102
+ }
103
+ async brdgeProvider(track) {
104
+ const query = this.createBridgeQuery(track);
105
+ if (this.options.bridgeFrom === "YouTube") {
106
+ try {
107
+ const serachResults = await youtube_sr_1.YouTube.search(query, {
108
+ limit: 1,
109
+ type: "video"
110
+ });
111
+ const ytStream = await this._stream(serachResults[0].url, {
112
+ quality: 'high',
113
+ type: 'audio',
114
+ highWaterMark: 1048576 * 32
115
+ });
116
+ return ytStream.url;
117
+ }
118
+ catch (error) {
119
+ throw new Error(`Could not find a source to bridge from. The error is as follows.\n\n${error}`);
120
+ }
121
+ }
122
+ const res = await this.client.tracks.searchV2({
123
+ q: query
118
124
  });
119
- return ytStream.url;
120
- } catch (error) {
121
- throw new Error(`Could not find a source to bridge from. The error is as follows.\n\n${error}`);
122
- }
125
+ if (res.collection.length === 0)
126
+ throw new Error("Could not find a suitable source to stream from.");
127
+ const str = this.client.util.streamLink(res.collection[0].permalink_url);
128
+ return str;
123
129
  }
124
- const res = await this.client.tracks.searchV2({
125
- q: query,
126
- });
127
- if (res.collection.length === 0) throw new Error('Could not find a suitable source to stream from.');
128
- const str = this.client.util.streamLink(res.collection[0].permalink_url);
129
- return str;
130
- }
131
- async stream(info) {
132
- if (this.options.onBeforeCreateStream && typeof this.options.onBeforeCreateStream === 'function') {
133
- return await this.options.onBeforeCreateStream(info);
130
+ async stream(info) {
131
+ if (this.options.onBeforeCreateStream && typeof this.options.onBeforeCreateStream === "function") {
132
+ return await this.options.onBeforeCreateStream(info);
133
+ }
134
+ return this.brdgeProvider(info);
134
135
  }
135
- return this.brdgeProvider(info);
136
- }
137
136
  }
137
+ DeezerExtractor.identifier = "com.discord-player.deezerextractor";
138
138
  exports.default = DeezerExtractor;
139
- DeezerExtractor.identifier = 'com.discord-player.deezerextractor';
package/package.json CHANGED
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "name": "discord-player-deezer",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A custom extractor made for discord-player that enables you to extract from Deezer.",
5
5
  "main": "dist/DeezerExtractor.js",
6
6
  "author": "retro_ig",
7
7
  "license": "MIT",
8
8
  "private": false,
9
9
  "dependencies": {
10
- "@discord-player/extractor": "^4.4.4",
11
10
  "@mithron/deezer-music-metadata": "^1.0.3",
12
- "discord-player": "*",
13
11
  "soundcloud.ts": "^0.5.2",
14
12
  "tslint-config-prettier": "^1.18.0",
15
13
  "youtube-sr": "^4.3.4",
16
14
  "yt-stream": "^1.4.4"
17
15
  },
18
16
  "devDependencies": {
17
+ "@discord-player/extractor": "^4.4.4",
19
18
  "prettier": "^2.8.4",
20
19
  "tslint": "^6.1.3",
20
+ "discord-player": "*",
21
21
  "typescript": "^4.9.5"
22
22
  },
23
23
  "scripts": {
package/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Discord Player Deezer Extractor
2
2
 
3
- Discord Player Deezer Extractor. An unofficial extractor made for discord-player for **Deezer** support. Deezer extractor works by either making a request to the Deezer API or extracting metadata from the Deezer site. Because we cannot get streams from deezer itself, the extractor uses the extracted data to stream from youtube!
3
+ Discord Player Deezer Extractor. An extractor made for discord-player for **Deezer** support. Deezer extractor works by either making a request to the Deezer API or extracting metadata from the Deezer site. Because we cannot get streams from deezer itself, the extractor uses the extracted data to stream from youtube!
4
4
 
5
5
  ## Installing the extractor
6
6
 
@@ -40,4 +40,4 @@ player.extractors.register(DeezerExtractor)
40
40
 
41
41
  *note: be sure to register it before loading the default extractors to make sure any conflicts with discord-player's default attachment extractor is resolved!*
42
42
 
43
- That's it! See the magic happen as you bot is now able to play from Deezer URLs
43
+ That's it! See the magic happen as you bot is now able to play from Deezer URLs
@@ -24,6 +24,8 @@ interface DeezerRegex {
24
24
  export default class DeezerExtractor extends BaseExtractor<DeezerOptions> {
25
25
  public static identifier: string = "com.discord-player.deezerextractor" as const
26
26
  private _stream = stream
27
+ protocols = ["deezer", "dzsearch"]
28
+
27
29
  client = new SoundCloud({
28
30
  clientId: this.options.soundcloud?.clientId,
29
31
  oauthToken: this.options.soundcloud?.oauthToken,