HerzaJ commited on
Commit
96d6e99
·
verified ·
1 Parent(s): 0f55795

Create ncs.js

Browse files
Files changed (1) hide show
  1. plugins/ncs.js +153 -0
plugins/ncs.js ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // SCRAPE BY NEKOLABS
2
+ // CHANNEL WA: https://whatsapp.com/channel/0029VbANq6v0VycMue9vPs3u
3
+
4
+ const axios = require("axios");
5
+ const cheerio = require("cheerio");
6
+
7
+ class NCS {
8
+ constructor() {
9
+ this.baseUrl = "https://ncs.io";
10
+
11
+ this.validGenres = {
12
+ "31": "Alternative Dance", "33": "Alternative Pop", "23": "Ambient", "34": "Anti-Pop",
13
+ "1": "Bass", "18": "Bass House", "26": "Brazilian Phonk", "27": "Breakbeat",
14
+ "2": "Chill", "24": "Chill Bass", "35": "Chill Pop", "85": "Colour Bass",
15
+ "65": "Complextro", "36": "Dance-Pop", "66": "Deep House", "45": "Disco",
16
+ "46": "Disco House", "3": "Drum & Bass", "4": "Drumstep", "5": "Dubstep",
17
+ "6": "EDM", "47": "Electro", "48": "Electro House", "7": "Electronic",
18
+ "39": "Electronic Pop", "83": "Electronic Rock", "17": "Future Bass", "68": "Future Bounce",
19
+ "8": "Future House", "69": "Future Rave", "57": "Future Trap", "40": "Futurepop",
20
+ "51": "Garage", "15": "Glitch Hop", "82": "Hardcore", "9": "Hardstyle",
21
+ "10": "House", "41": "Hyperpop", "11": "Indie Dance", "91": "J-Pop",
22
+ "84": "Jersey Club", "28": "Jump-Up", "29": "Liquid DnB", "60": "Lofi Hip-Hop",
23
+ "12": "Melodic Dubstep", "54": "Melodic House", "22": "Midtempo Bass", "30": "Neurofunk",
24
+ "87": "Nu-Jazz", "16": "Phonk", "86": "Pluggnb", "19": "Pop",
25
+ "55": "Progressive House", "88": "RnB", "89": "Speed Garage", "73": "Tech House",
26
+ "80": "Techno", "81": "Trance", "14": "Trap", "74": "Tribal House",
27
+ "21": "UKG", "90": "Witch House"
28
+ };
29
+
30
+ this.validMoods = {
31
+ "1": "Angry", "33": "angry", "26": "Chasing", "2": "Dark", "35": "dark",
32
+ "36": "dramatic", "3": "Dreamy", "27": "Eccentric", "28": "Elegant", "6": "energetic",
33
+ "4": "Epic", "5": "Euphoric", "37": "exciting", "7": "Fear", "29": "Floating",
34
+ "8": "Funny", "9": "Glamorous", "10": "Gloomy", "11": "Happy", "30": "Heavy",
35
+ "12": "Hopeful", "13": "Laid Back", "38": "majestic", "14": "Mysterious", "34": "negative",
36
+ "39": "neutral", "15": "Peaceful", "40": "positive", "32": "powerful", "16": "Quirky",
37
+ "17": "relaxed", "18": "Restless", "19": "romantic", "20": "sad", "21": "scary",
38
+ "31": "Sentimental", "22": "Sexy", "23": "Suspense", "41": "tense", "24": "Weird"
39
+ };
40
+ }
41
+
42
+ validateParam(type, value) {
43
+ const validList = type === "genre" ? this.validGenres : this.validMoods;
44
+ return value && validList[value] ? String(value) : "";
45
+ }
46
+
47
+ async searchTracks(query, genre = "", mood = "") {
48
+ try {
49
+ const validGenre = this.validateParam("genre", genre);
50
+ const validMood = this.validateParam("mood", mood);
51
+ const url = `${this.baseUrl}/music-search?q=${encodeURIComponent(query)}&genre=${validGenre}&mood=${validMood}`;
52
+
53
+ const { data } = await axios.get(url, {
54
+ headers: {
55
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
56
+ }
57
+ });
58
+
59
+ const $ = cheerio.load(data);
60
+ const tracks = [];
61
+
62
+ $("table.tablesorter tbody tr").each((_, el) => {
63
+ const $row = $(el);
64
+ const $play = $row.find(".player-play");
65
+
66
+ const tid = $play.attr("data-tid") || "";
67
+ const title = $play.attr("data-track") || "";
68
+ const artist = $play.attr("data-artistraw") || "";
69
+ const versions = $play.attr("data-versions") || "";
70
+ const genre = $play.attr("data-genre") || "";
71
+ const previewUrl = $play.attr("data-url") || "";
72
+ const previewStart = $play.attr("data-preview") || "0";
73
+ const image = $row.find("td img[alt]").attr("src") || "";
74
+
75
+ const genres = [];
76
+ const moods = [];
77
+
78
+ $row.find("td:nth-child(5) a.tag").each((i, tag) => {
79
+ const $tag = $(tag);
80
+ const text = $tag.text().trim();
81
+ const href = $tag.attr("href") || "";
82
+ if (href.includes("genre=")) genres.push(text);
83
+ else if (href.includes("mood=")) moods.push(text);
84
+ });
85
+
86
+ const releaseDate = $row.find("td:nth-child(6)").text().trim();
87
+
88
+ if (tid && title) {
89
+ tracks.push({
90
+ tid,
91
+ title,
92
+ artist,
93
+ versions,
94
+ genre,
95
+ image,
96
+ genres,
97
+ moods,
98
+ previewUrl,
99
+ previewStart,
100
+ releaseDate
101
+ });
102
+ }
103
+ });
104
+
105
+ return tracks;
106
+ } catch (err) {
107
+ console.error("Error while searching NCS:", err.message);
108
+ return [];
109
+ }
110
+ }
111
+ }
112
+
113
+ const ncs = new NCS();
114
+
115
+ const handler = async (req, res) => {
116
+ try {
117
+ const { text, genre, mood } = req.query;
118
+
119
+ if (!text) {
120
+ return res.status(400).json({
121
+ success: false,
122
+ error: 'Missing required parameter: text'
123
+ });
124
+ }
125
+
126
+ const results = await ncs.searchTracks(text, genre || "", mood || "");
127
+
128
+ res.json({
129
+ author: 'Herza',
130
+ scraper: 'nekolabs',
131
+ success: true,
132
+ data: results
133
+ });
134
+
135
+ } catch (error) {
136
+ res.status(500).json({
137
+ success: false,
138
+ error: error.message
139
+ });
140
+ }
141
+ };
142
+
143
+ module.exports = {
144
+ name: 'NCS Music Search',
145
+ description: 'Search NoCopyrightSounds tracks by keyword with optional genre and mood filters',
146
+ type: 'GET',
147
+ routes: ['api/search/ncs'],
148
+ tags: ['search', 'music', 'ncs', 'tools'],
149
+ parameters: ['text', 'genre (optional)', 'mood (optional)'],
150
+ enabled: true,
151
+ main: ['Search'],
152
+ handler
153
+ };