R-Kentaren commited on
Commit
028f29e
·
verified ·
1 Parent(s): e8d8fbb

Create spotifydl.js

Browse files
Files changed (1) hide show
  1. spotifydl.js +81 -0
spotifydl.js ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const axios = require('axios');
2
+
3
+ const cheerio = require('cheerio');
4
+
5
+
6
+
7
+ async function spotifydl(url) {
8
+
9
+ try {
10
+
11
+ if (!url.includes('open.spotify.com')) throw new Error('Invalid url.');
12
+
13
+
14
+
15
+ const rynn = await axios.get('https://spotdl.io/', {
16
+
17
+ headers: {
18
+
19
+ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
20
+
21
+ }
22
+
23
+ });
24
+
25
+ const $ = cheerio.load(uzip.data);
26
+
27
+
28
+
29
+ const api = axios.create({
30
+
31
+ baseURL: 'https://spotdl.io',
32
+
33
+ headers: {
34
+
35
+ cookie: uzip.headers['set-cookie'].join('; '),
36
+
37
+ 'content-type': 'application/json',
38
+
39
+ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
40
+
41
+ 'x-csrf-token': $('meta[name="csrf-token"]').attr('content')
42
+
43
+ }
44
+
45
+ });
46
+
47
+
48
+
49
+ const [{ data: meta }, { data: dl }] = await Promise.all([
50
+
51
+ api.post('/getTrackData', { spotify_url: url }),
52
+
53
+ api.post('/convert', { urls: url })
54
+
55
+ ]);
56
+
57
+
58
+
59
+ return {
60
+
61
+ ...meta,
62
+
63
+ download_url: dl.url
64
+
65
+ };
66
+
67
+ } catch (error) {
68
+
69
+ throw new Error(error.message);
70
+
71
+ }
72
+
73
+ }
74
+
75
+
76
+
77
+ // Usage:
78
+
79
+ const resp = await spotifydl('https://open.spotify.com/track/6yID3RbYKiwn2p2LPz0OkK');
80
+
81
+ console.log(resp);