mirror of
https://git.luna-app.eu/50n50/sources
synced 2025-12-21 21:26:19 +01:00
Update soundcloud/soundcloud.js
This commit is contained in:
parent
27d7cd02ef
commit
068051cbda
1 changed files with 70 additions and 73 deletions
|
|
@ -1,92 +1,89 @@
|
||||||
const PLACEHOLDER_IMAGE = "https://media.istockphoto.com/id/1147544807/vector/thumbnail-image-vector-graphic.jpg?s=612x612&w=0&k=20&c=rnCKVbdxqkjlcs3xH87-9gocETqpspHFXu5dIGB4wuM=";
|
|
||||||
|
|
||||||
async function searchResults(keyword) {
|
async function searchResults(keyword) {
|
||||||
const searchUrl = `https://api-v2.soundcloud.com/search?q=${encodeURIComponent(keyword)}&facet=model&user_id=200971-112325-516393-99787&client_id=UjhhbCuNo1OQfTwkzajxQNLlJcSlUlVz&limit=30`;
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(searchUrl);
|
const response = await fetchv2(`https://api-v2.soundcloud.com/search/tracks?q=${encodeURIComponent(keyword)}&facet=genre&user_id=618848-625616-52355-612546&client_id=xwYTVSni6n4FghaI0c4uJ8T9c4pyJ3rh&limit=20&offset=0&linked_partitioning=1&app_version=1761897122&app_locale=en`);
|
||||||
const json = await JSON.parse(response);
|
const data = await response.json();
|
||||||
|
|
||||||
|
const results = data.collection
|
||||||
|
.map(track => {
|
||||||
|
const hlsLink = track.media.transcodings.find(t => t.format.protocol === "hls" && t.format.mime_type.includes("mp4"))?.url || "";
|
||||||
|
const imageUrl = track.artwork_url ? track.artwork_url.replace(/-large\.jpg$/, '-t500x500.jpg') : "";
|
||||||
|
return {
|
||||||
|
title: track.title,
|
||||||
|
image: imageUrl,
|
||||||
|
href: `${hlsLink}?title=${encodeURIComponent(track.title)}&artist=${encodeURIComponent(track.user.username)}`,
|
||||||
|
hasHls: hlsLink !== ""
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.filter(track => track.hasHls)
|
||||||
|
.map(track => ({
|
||||||
|
title: track.title,
|
||||||
|
image: track.image,
|
||||||
|
href: track.href
|
||||||
|
}));
|
||||||
|
|
||||||
const results = json.collection.map(item => ({
|
|
||||||
title: item.title,
|
|
||||||
image: item.artwork_url || PLACEHOLDER_IMAGE,
|
|
||||||
href: item.permalink_url
|
|
||||||
}));
|
|
||||||
//console.log(results);
|
|
||||||
console.log(JSON.stringify(results));
|
|
||||||
return JSON.stringify(results);
|
return JSON.stringify(results);
|
||||||
} catch (error) {
|
} catch (err) {
|
||||||
console.error("Error fetching search results:", error);
|
return JSON.stringify([{
|
||||||
return JSON.stringify([]);
|
title: "Error",
|
||||||
|
image: "Error",
|
||||||
|
href: "Error"
|
||||||
|
}]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function extractDetails(url) {
|
async function extractDetails(url) {
|
||||||
const details = [];
|
console.log(url);
|
||||||
details.push({
|
try {
|
||||||
description: 'N/A',
|
const params = url.split('?')[1] || '';
|
||||||
alias: 'N/A',
|
const pairs = params.split('&');
|
||||||
airdate: 'N/A'
|
let title = '';
|
||||||
});
|
let artist = '';
|
||||||
|
|
||||||
//#IAMLAZY
|
for (const pair of pairs) {
|
||||||
|
const [key, value] = pair.split('=');
|
||||||
|
if (key === 'title') title = decodeURIComponent(value);
|
||||||
|
if (key === 'artist') artist = decodeURIComponent(value);
|
||||||
|
}
|
||||||
|
|
||||||
console.log(JSON.stringify(details));
|
const description = `${title} by ${artist}`;
|
||||||
return JSON.stringify(details);
|
return JSON.stringify([{
|
||||||
|
description: description,
|
||||||
|
aliases: "",
|
||||||
|
airdate: ""
|
||||||
|
}]);
|
||||||
|
} catch (err) {
|
||||||
|
return JSON.stringify([{
|
||||||
|
description: "Error",
|
||||||
|
aliases: "Error",
|
||||||
|
airdate: "Error"
|
||||||
|
}]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function extractEpisodes(url) {
|
async function extractEpisodes(url) {
|
||||||
const response = await fetch(url);
|
const results = [];
|
||||||
const html = await response;
|
try {
|
||||||
const tracks = [];
|
const cleanUrl = url.split('?')[0];
|
||||||
|
results.push({
|
||||||
const trackRegex = /<article itemprop="track"[^>]*>[\s\S]*?<h2 itemprop="name"><a itemprop="url" href="([^"]+)">/g;
|
href: cleanUrl,
|
||||||
|
number: 1
|
||||||
let match;
|
|
||||||
let number = 1;
|
|
||||||
|
|
||||||
while ((match = trackRegex.exec(html)) !== null) {
|
|
||||||
tracks.push({
|
|
||||||
number: number++,
|
|
||||||
href: 'https://soundcloud.com' + match[1].trim()
|
|
||||||
});
|
});
|
||||||
|
return JSON.stringify(results);
|
||||||
|
} catch (err) {
|
||||||
|
return JSON.stringify([{
|
||||||
|
href: "Error",
|
||||||
|
number: "Error"
|
||||||
|
}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tracks.length > 0) {
|
|
||||||
return JSON.stringify(tracks);
|
|
||||||
} else {
|
|
||||||
const canonicalMatch = html.match(/\["link",\{"rel":"canonical","href":"([^"]+)"\}\]/);
|
|
||||||
if (canonicalMatch) {
|
|
||||||
return JSON.stringify([{ number: 1, href: canonicalMatch[1].trim() }]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return JSON.stringify([]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function extractStreamUrl(url) {
|
async function extractStreamUrl(url) {
|
||||||
const clientId = "UjhhbCuNo1OQfTwkzajxQNLlJcSlUlVz";
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url);
|
const response = await fetchv2(url+"?client_id=xwYTVSni6n4FghaI0c4uJ8T9c4pyJ3rh&track_authorization=");
|
||||||
const html = await response;
|
const data = await response.json();
|
||||||
|
|
||||||
const urlMatch = html.match(/"url":"(https:\/\/api[^\.]*\.soundcloud\.com\/media\/soundcloud:tracks:[^"]+)"/);
|
return data.url || "https://error.org/";
|
||||||
const authMatch = html.match(/"track_authorization":"([^"]+)"/);
|
} catch (err) {
|
||||||
|
return "https://error.org/";
|
||||||
if (urlMatch && authMatch) {
|
|
||||||
const streamUrl = `${urlMatch[1]}?client_id=${clientId}&track_authorization=${authMatch[1]}`;
|
|
||||||
|
|
||||||
const responseTwo = await fetch(streamUrl);
|
|
||||||
const json = await JSON.parse(responseTwo);
|
|
||||||
|
|
||||||
return json.url;
|
|
||||||
} else {
|
|
||||||
console.log("No stream URL found");
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error:", error);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue