Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- src/soundgasmApi.js +42 -0
src/soundgasmApi.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const fetch = require('node-fetch');
|
| 2 |
+
const cheerio = require('cheerio');
|
| 3 |
+
|
| 4 |
+
async function searchSoundgasm(query) {
|
| 5 |
+
try {
|
| 6 |
+
const response = await fetch(`https://soundgasm.net/search?q=${encodeURIComponent(query)}`);
|
| 7 |
+
const html = await response.text();
|
| 8 |
+
const $ = cheerio.load(html);
|
| 9 |
+
|
| 10 |
+
const results = [];
|
| 11 |
+
$('.sound-details').each((i, elem) => {
|
| 12 |
+
const title = $(elem).find('a').text().trim();
|
| 13 |
+
const url = $(elem).find('a').attr('href');
|
| 14 |
+
const id = url.split('/').pop();
|
| 15 |
+
results.push({ id, title, url });
|
| 16 |
+
});
|
| 17 |
+
|
| 18 |
+
return results;
|
| 19 |
+
} catch (error) {
|
| 20 |
+
throw new Error('Failed to search soundgasm');
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
async function getAudioDetails(id) {
|
| 25 |
+
try {
|
| 26 |
+
const response = await fetch(`https://soundgasm.net/u/temp/${id}`);
|
| 27 |
+
const html = await response.text();
|
| 28 |
+
const $ = cheerio.load(html);
|
| 29 |
+
|
| 30 |
+
const audioUrl = $('audio source').attr('src');
|
| 31 |
+
const title = $('.jp-title').text().trim();
|
| 32 |
+
|
| 33 |
+
return { title, audioUrl };
|
| 34 |
+
} catch (error) {
|
| 35 |
+
throw new Error('Failed to get audio details');
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
module.exports = {
|
| 40 |
+
searchSoundgasm,
|
| 41 |
+
getAudioDetails
|
| 42 |
+
};
|