soundcloud.ts
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -23,2 +23,6 @@ import api from "../API"; | ||
scrape: (query: string) => Promise<SoundCloudPlaylist[]>; | ||
/** | ||
* Gets a playlist by URL (web scraping) | ||
*/ | ||
getURL: (url: string) => Promise<SoundCloudPlaylist>; | ||
} |
@@ -131,2 +131,23 @@ "use strict"; | ||
}); }; | ||
/** | ||
* Gets a playlist by URL (web scraping) | ||
*/ | ||
this.getURL = function (url) { return __awaiter(_this, void 0, void 0, function () { | ||
var headers, songHTML, data, playlist; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!url.startsWith("https://soundcloud.com/")) | ||
url = "https://soundcloud.com/" + url; | ||
headers = { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36" }; | ||
return [4 /*yield*/, axios_1["default"].get(url, { headers: headers }).then(function (r) { return r.data; })]; | ||
case 1: | ||
songHTML = _b.sent(); | ||
data = JSON.parse((_a = songHTML.match(/(\[{"id")(.*?)(?=\);)/)) === null || _a === void 0 ? void 0 : _a[0]); | ||
playlist = data[5].data[0]; | ||
return [2 /*return*/, playlist]; | ||
} | ||
}); | ||
}); }; | ||
} | ||
@@ -133,0 +154,0 @@ return Playlists; |
@@ -39,2 +39,6 @@ import api from "../API"; | ||
scrape: (query: string) => Promise<SoundCloudTrack[]>; | ||
/** | ||
* Gets a track by URL (web scraping) | ||
*/ | ||
getURL: (url: string) => Promise<SoundCloudTrack>; | ||
} |
@@ -202,2 +202,23 @@ "use strict"; | ||
}); }; | ||
/** | ||
* Gets a track by URL (web scraping) | ||
*/ | ||
this.getURL = function (url) { return __awaiter(_this, void 0, void 0, function () { | ||
var headers, songHTML, data, track; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!url.startsWith("https://soundcloud.com/")) | ||
url = "https://soundcloud.com/" + url; | ||
headers = { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36" }; | ||
return [4 /*yield*/, axios_1["default"].get(url, { headers: headers }).then(function (r) { return r.data; })]; | ||
case 1: | ||
songHTML = _b.sent(); | ||
data = JSON.parse((_a = songHTML.match(/(\[{"id")(.*?)(?=\);)/)) === null || _a === void 0 ? void 0 : _a[0]); | ||
track = data[5].data[0]; | ||
return [2 /*return*/, track]; | ||
} | ||
}); | ||
}); }; | ||
} | ||
@@ -204,0 +225,0 @@ return Tracks; |
@@ -59,2 +59,6 @@ import api from "../API"; | ||
scrape: (query: string) => Promise<SoundCloudUser[]>; | ||
/** | ||
* Gets a user by URL (web scraping) | ||
*/ | ||
getURL: (url: string) => Promise<SoundCloudUser>; | ||
} |
@@ -293,2 +293,23 @@ "use strict"; | ||
}); }; | ||
/** | ||
* Gets a user by URL (web scraping) | ||
*/ | ||
this.getURL = function (url) { return __awaiter(_this, void 0, void 0, function () { | ||
var headers, songHTML, data, user; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!url.startsWith("https://soundcloud.com/")) | ||
url = "https://soundcloud.com/" + url; | ||
headers = { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36" }; | ||
return [4 /*yield*/, axios_1["default"].get(url, { headers: headers }).then(function (r) { return r.data; })]; | ||
case 1: | ||
songHTML = _b.sent(); | ||
data = JSON.parse((_a = songHTML.match(/(\[{"id")(.*?)(?=\);)/)) === null || _a === void 0 ? void 0 : _a[0]); | ||
user = data[4].data[0]; | ||
return [2 /*return*/, user]; | ||
} | ||
}); | ||
}); }; | ||
} | ||
@@ -295,0 +316,0 @@ return Users; |
@@ -55,2 +55,14 @@ import axios from "axios" | ||
} | ||
/** | ||
* Gets a playlist by URL (web scraping) | ||
*/ | ||
public getURL = async (url: string) => { | ||
if (!url.startsWith("https://soundcloud.com/")) url = `https://soundcloud.com/${url}` | ||
const headers = {"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36"} | ||
const songHTML = await axios.get(url, {headers}).then((r: any) => r.data) | ||
const data = JSON.parse(songHTML.match(/(\[{"id")(.*?)(?=\);)/)?.[0]) | ||
const playlist = data[5].data[0] | ||
return playlist as Promise<SoundCloudPlaylist> | ||
} | ||
} |
@@ -92,2 +92,14 @@ import axios from "axios" | ||
/** | ||
* Gets a track by URL (web scraping) | ||
*/ | ||
public getURL = async (url: string) => { | ||
if (!url.startsWith("https://soundcloud.com/")) url = `https://soundcloud.com/${url}` | ||
const headers = {"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36"} | ||
const songHTML = await axios.get(url, {headers}).then((r: any) => r.data) | ||
const data = JSON.parse(songHTML.match(/(\[{"id")(.*?)(?=\);)/)?.[0]) | ||
const track = data[5].data[0] | ||
return track as Promise<SoundCloudTrack> | ||
} | ||
} |
@@ -140,2 +140,14 @@ import axios from "axios" | ||
/** | ||
* Gets a user by URL (web scraping) | ||
*/ | ||
public getURL = async (url: string) => { | ||
if (!url.startsWith("https://soundcloud.com/")) url = `https://soundcloud.com/${url}` | ||
const headers = {"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36"} | ||
const songHTML = await axios.get(url, {headers}).then((r: any) => r.data) | ||
const data = JSON.parse(songHTML.match(/(\[{"id")(.*?)(?=\);)/)?.[0]) | ||
const user = data[4].data[0] | ||
return user as Promise<SoundCloudUser> | ||
} | ||
} |
{ | ||
"name": "soundcloud.ts", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Wrapper for the Soundcloud API with typings", | ||
@@ -5,0 +5,0 @@ "main": "dist/soundcloud.js", |
@@ -34,10 +34,16 @@ <div align="left"> | ||
Most of the api endpoints are subject to breaking (or already broke), possibly because Soundcloud is migrating to a new v2 api. For the time being | ||
you can use the `scrape` methods which get data from the html source instead. | ||
you can use the `scrape` and `getURL` methods which get data from the html source instead. | ||
```ts | ||
/*Alt get tracks*/ | ||
/*Alt search tracks*/ | ||
const tracks = await soundcloud.tracks.scrape("cool track name") | ||
/*Alt get playlists*/ | ||
/*Alt get track*/ | ||
const track = await soundcloud.tracks.getURL("succducc/azure") | ||
/*Alt search playlists*/ | ||
const playlists = await soundcloud.playlists.scrape("cool playlist name") | ||
/*Alt get users*/ | ||
/*Alt get playlist*/ | ||
const playlist = await soundcloud.playlists.getURL("virtual-riot/sets/throwback-ep") | ||
/*Alt search users*/ | ||
const users = await soundcloud.users.scrape("cool username") | ||
/*Alt get user*/ | ||
const user = await soundcloud.playlists.getURL("someone") | ||
``` | ||
@@ -44,0 +50,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
211153
4338
308