Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
fix: update to [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
skick1234 committed Jul 4, 2023
1 parent 8c45dad commit 9b95fbe
Show file tree
Hide file tree
Showing 4 changed files with 843 additions and 655 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ scPlugin.search("A SoundCloud Playlist", "playlist", 3); // class method

- `SoundCloudPluginOptions.clientId` [string] _(optional)_: Your account's client id.
- `SoundCloudPluginOptions.oauthToken` [string] _(optional)_: Your account's oauth token. Used to fetch more data with SoundCloud Go+ account.
- How to get `clientId` and `oauthToken`? [See here](https://github.com/Tenpi/soundcloud.ts#getting-started)

#### Example

Expand Down
24 changes: 21 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export class SoundCloudPlugin extends ExtractorPlugin {
if (options.oauthToken && typeof options.oauthToken !== "string") {
throw new DisTubeError("INVALID_TYPE", "string", options.oauthToken, "oauthToken");
}
this.#sc = new SoundCloud(options?.clientId, options?.oauthToken);
this.#sc = new SoundCloud({
clientId: options.clientId,
oauthToken: options.oauthToken,
});
}
static search(query: string, type?: SearchType.Track, limit?: number): Promise<Song<undefined>[]>;
static search(query: string, type: SearchType.Playlist, limit?: number): Promise<Playlist<undefined>[]>;
Expand All @@ -47,6 +50,13 @@ export class SoundCloudPlugin extends ExtractorPlugin {
throw new DisTubeError("INVALID_TYPE", "natural number", limit, "limit");
}

await SC.api.getClientId().catch(() => {
throw new DisTubeError(
"SOUNDCLOUD_PLUGIN_NO_CLIENT_ID",
"Cannot find SoundCloud client id automatically. Please provide a client id in the constructor.\nGuide: https://github.com/distubejs/soundcloud#documentation",
);
});

switch (type) {
case SearchType.Track: {
const data = await SC.tracks.searchV2({ q: query, limit });
Expand Down Expand Up @@ -80,11 +90,19 @@ export class SoundCloudPlugin extends ExtractorPlugin {
}

async resolve(url: string, options: { member?: GuildMember; metadata?: any }) {
await SC.api.getClientId().catch(() => {
throw new DisTubeError(
"SOUNDCLOUD_PLUGIN_NO_CLIENT_ID",
"Cannot find SoundCloud client id automatically. Please provide a client id in the constructor.\nGuide: https://github.com/distubejs/soundcloud#documentation",
);
});
const opt = { ...options, source: "soundcloud" };
url = url.replace(/:\/\/(m|www)\./g, "://");
const data = await this.#sc.resolve.getV2(url, true).catch(() => undefined);
const data = await this.#sc.resolve.getV2(url, true).catch(e => {
throw new DisTubeError("SOUNDCLOUD_PLUGIN_RESOLVE_ERROR", e.message);
});
if (!data || !["track", "playlist"].includes(data.kind)) {
throw new DisTubeError("SOUNDCLOUD_PLUGIN_NOT_SUPPORTED", "Only public links are supported.");
throw new DisTubeError("SOUNDCLOUD_PLUGIN_NOT_SUPPORTED", "Only public tracks and playlists are supported.");
}

return data.kind === "playlist"
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,29 @@
},
"homepage": "https://github.com/distubejs/soundcloud#readme",
"devDependencies": {
"@commitlint/cli": "^17.6.1",
"@commitlint/config-conventional": "^17.6.1",
"@commitlint/cli": "^17.6.6",
"@commitlint/config-conventional": "^17.6.6",
"@discordjs/opus": "^0.9.0",
"@discordjs/voice": "^0.16.0",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"commitlint": "^17.6.1",
"discord.js": "^14.9.0",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"commitlint": "^17.6.6",
"discord.js": "^14.11.0",
"distube": "^4.0.4",
"eslint": "^8.38.0",
"eslint": "^8.44.0",
"eslint-config-distube": "^1.6.4",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-deprecation": "^1.4.1",
"eslint-plugin-jsdoc": "^41.1.1",
"eslint-plugin-jsdoc": "^46.4.3",
"husky": "^8.0.3",
"nano-staged": "^0.8.0",
"pinst": "^3.0.0",
"prettier": "^2.8.7",
"tsup": "^6.7.0",
"typescript": "^5.0.4"
"prettier": "^2.8.8",
"tsup": "^7.1.0",
"typescript": "^5.1.6"
},
"dependencies": {
"soundcloud.ts": "^0.5.0"
"soundcloud.ts": "^0.5.2"
},
"peerDependencies": {
"distube": "3||4"
Expand Down
Loading

0 comments on commit 9b95fbe

Please sign in to comment.