odesli.js 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,106 +1,328 @@
1
- # odesli.js
2
- Node.js Client to query odesli.co (song.link/album.link) API
3
-
4
- ## v1.0.0
5
-
6
- Initial release
7
-
8
- ## Installation
9
- ```
10
- npm install odesli.js --save
11
- ```
12
-
13
- ## Initilise
14
- ```js
15
- const Odesli = require('odesli.js');
16
- const odesli = new Odesli();
17
- ```
18
-
19
- ## API Key
20
- An API Key is not needed, however, you will be limited to 10 Requests per minute.
21
- Email `developers@song.link` to get an API Key.
22
-
23
- ```js
24
- const odesli = new Odesli({
25
- apiKey: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
26
- version: 'vX-beta.X'
27
- });
28
- ```
29
-
30
- *If no version is supplied, it'll default to 'v1-alpha.1'*
31
-
32
- ## Fetch
33
- Use `fetch()` to fetch a song by a streaming service url:
34
-
35
- #### async/await
36
-
37
- ```js
38
- // fetch(url: string, country?: 2-character code)
39
- let song = await odesli.fetch('https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR');
40
- console.log(`${song.title} by ${song.artist[0]}`);
41
-
42
- // output: Bad and Boujee by Migos
43
- ```
44
-
45
- #### or you can use promises.
46
-
47
- ```js
48
- // fetch(url: string, country?: 2-character code)
49
- odesli.fetch('https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR').then(song => {
50
- console.log(`${song.title} by ${song.artist[0]}`);
51
-
52
- // output: Bad and Boujee by Migos
53
- });
54
- ```
55
-
56
- ## Get By Parameters
57
- Use `getByParams()` to fetch a song by a streaming service type, song/album type, and it's unique ID:
58
-
59
- #### async/await
60
-
61
- ```js
62
- // getByParams(platform: string, type: enum<song|album>, id: string, country?: 2-character code)
63
- let song = await odesli.getByParams('spotify', 'song', '4Km5HrUvYTaSUfiSGPJeQR');
64
- console.log(song.artist[0]);
65
-
66
- // output: Migos
67
- ```
68
-
69
- #### or you can use promises.
70
-
71
- ```js
72
- // getByParams(platform: string, type: enum<song|album>, id: string, country?: 2-character code)
73
- odesli.getByParams('spotify', 'song', '4Km5HrUvYTaSUfiSGPJeQR').then(song => {
74
- console.log(song.artist[0]);
75
-
76
- // output: Migos
77
- });
78
- ```
79
-
80
- ## Get By ID
81
- Use `getById()` to fetch a song by it's unique ID:
82
-
83
- #### async/await
84
-
85
- ```js
86
- // // getById(id: string, country?: 2-character code)
87
- let song = await odesli.getByParams('SPOTIFY_SONG::4Km5HrUvYTaSUfiSGPJeQR');
88
- console.log(song.title);
89
-
90
- // output: Bad and Boujee
91
- ```
92
-
93
- #### or you can use promises.
94
-
95
- ```js
96
- // getByParams(platform: string, type: enum<song|album>, id: string)
97
- odesli.getByParams('SPOTIFY_SONG::4Km5HrUvYTaSUfiSGPJeQR').then(song => {
98
- console.log(song.title);
99
-
100
- // output: Bad and Boujee
101
- });
102
- ```
103
-
104
- ## Odesli API Docs
105
-
106
- Check the [Odesli's Public API Documentation](https://www.notion.so/Public-API-d8093b1bb8874f8b85527d985c4f9e68) for more info.
1
+ # odesli.js
2
+
3
+ [![npm version](https://badge.fury.io/js/odesli.js.svg)](https://badge.fury.io/js/odesli.js)
4
+ [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
5
+ [![Node.js CI](https://github.com/MattrAus/odesli.js/workflows/CI/badge.svg)](https://github.com/MattrAus/odesli.js/actions/workflows/ci.yml)
6
+ [![Test Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen.svg)](https://github.com/MattrAus/odesli.js)
7
+ [![Bundle Size](https://img.shields.io/bundlephobia/min/odesli.js)](https://bundlephobia.com/result?p=odesli.js)
8
+ [![Downloads](https://img.shields.io/npm/dm/odesli.js.svg)](https://www.npmjs.com/package/odesli.js)
9
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
10
+
11
+ A Node.js client for the [Odesli API](https://odesli.co/) (formerly song.link/album.link) that helps you find links to music across multiple streaming platforms.
12
+
13
+ ## 📋 Table of Contents
14
+
15
+ - [Features](#features)
16
+ - [Installation](#installation)
17
+ - [Quick Start](#quick-start)
18
+ - [API Key](#api-key)
19
+ - [Usage](#usage)
20
+ - [Fetch by URL](#fetch-by-url)
21
+ - [Fetch by Parameters](#fetch-by-parameters)
22
+ - [Fetch by Entity ID](#fetch-by-entity-id)
23
+ - [Country-Specific Results](#country-specific-results)
24
+ - [Error Handling](#error-handling)
25
+ - [Advanced Usage](#advanced-usage)
26
+ - [Response Format](#response-format)
27
+ - [Supported Platforms](#supported-platforms)
28
+ - [TypeScript Support](#typescript-support)
29
+ - [Examples](#examples)
30
+ - [API Documentation](#api-documentation)
31
+ - [Contributing](#contributing)
32
+ - [License](#license)
33
+ - [Support](#support)
34
+
35
+ ## Features
36
+
37
+ - 🔗 **Cross-platform links**: Get links for music across Spotify, Apple Music, YouTube Music, and more
38
+ - 🎵 **Song & Album support**: Works with both individual tracks and full albums
39
+ - 🌍 **Multi-country support**: Specify country codes for region-specific results
40
+ - 🔑 **API Key support**: Optional API key for higher rate limits
41
+ - 📦 **TypeScript support**: Full TypeScript definitions included
42
+ - ⚡ **Lightweight**: Minimal dependencies, fast performance
43
+ - 🛡️ **Robust error handling**: Comprehensive error messages and validation
44
+ - 🧪 **Fully tested**: 100% test coverage with comprehensive test suite
45
+
46
+ ## Installation
47
+
48
+ ```bash
49
+ npm install odesli.js
50
+ ```
51
+
52
+ ## Quick Start
53
+
54
+ ```javascript
55
+ const Odesli = require('odesli.js');
56
+
57
+ // Initialize without API key (10 requests/minute limit)
58
+ const odesli = new Odesli();
59
+
60
+ // Or with API key for higher limits
61
+ const odesli = new Odesli({
62
+ apiKey: 'your-api-key-here',
63
+ version: 'v1-alpha.1', // optional, defaults to v1-alpha.1
64
+ });
65
+ ```
66
+
67
+ ## API Key
68
+
69
+ An API key is **optional** but recommended for production use. Without an API key, you're limited to 10 requests per minute.
70
+
71
+ To get an API key, email `developers@song.link`.
72
+
73
+ ## Usage
74
+
75
+ ### Fetch by URL
76
+
77
+ Get links for a song using any streaming service URL:
78
+
79
+ ```javascript
80
+ // Using async/await
81
+ const song = await odesli.fetch(
82
+ 'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR'
83
+ );
84
+ console.log(`${song.title} by ${song.artist[0]}`);
85
+ // Output: Bad and Boujee by Migos
86
+
87
+ // Using promises
88
+ odesli
89
+ .fetch('https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR')
90
+ .then(song => {
91
+ console.log(`${song.title} by ${song.artist[0]}`);
92
+ });
93
+ ```
94
+
95
+ ### Fetch by Parameters
96
+
97
+ Get links using platform, type, and ID:
98
+
99
+ ```javascript
100
+ // Using async/await
101
+ const song = await odesli.getByParams(
102
+ 'spotify',
103
+ 'song',
104
+ '4Km5HrUvYTaSUfiSGPJeQR'
105
+ );
106
+ console.log(song.artist[0]); // Output: Migos
107
+
108
+ // Using promises
109
+ odesli.getByParams('spotify', 'song', '4Km5HrUvYTaSUfiSGPJeQR').then(song => {
110
+ console.log(song.artist[0]);
111
+ });
112
+ ```
113
+
114
+ ### Fetch by Entity ID
115
+
116
+ Get links using the full entity ID:
117
+
118
+ ```javascript
119
+ // Using async/await
120
+ const song = await odesli.getById('SPOTIFY_SONG::4Km5HrUvYTaSUfiSGPJeQR');
121
+ console.log(song.title); // Output: Bad and Boujee
122
+
123
+ // Using promises
124
+ odesli.getById('SPOTIFY_SONG::4Km5HrUvYTaSUfiSGPJeQR').then(song => {
125
+ console.log(song.title);
126
+ });
127
+ ```
128
+
129
+ ### Country-Specific Results
130
+
131
+ All methods accept an optional country parameter (ISO 3166-1 Alpha-2 code):
132
+
133
+ ```javascript
134
+ // Get results for the United Kingdom
135
+ const song = await odesli.fetch(
136
+ 'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR',
137
+ 'GB'
138
+ );
139
+
140
+ // Get results for Japan
141
+ const song = await odesli.getByParams(
142
+ 'spotify',
143
+ 'song',
144
+ '4Km5HrUvYTaSUfiSGPJeQR',
145
+ 'JP'
146
+ );
147
+ ```
148
+
149
+ ### Error Handling
150
+
151
+ The library throws descriptive errors for various scenarios:
152
+
153
+ ```javascript
154
+ try {
155
+ const song = await odesli.fetch('invalid-url');
156
+ } catch (error) {
157
+ console.error(error.message);
158
+ // Examples:
159
+ // "No URL was provided to odesli.fetch()"
160
+ // "429: RATE_LIMITED, You are being rate limited, No API Key is 10 Requests / Minute."
161
+ // "API returned an unexpected result."
162
+ }
163
+ ```
164
+
165
+ ### Advanced Usage
166
+
167
+ #### Batch Processing
168
+
169
+ ```javascript
170
+ // Process multiple songs efficiently
171
+ const urls = [
172
+ 'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR',
173
+ 'https://open.spotify.com/track/0V3wPSX9ygBnCm8psDIegu',
174
+ 'https://open.spotify.com/track/1z6WtY7X4HQJvzxC4UgkS1',
175
+ ];
176
+
177
+ const songs = await Promise.allSettled(urls.map(url => odesli.fetch(url)));
178
+
179
+ songs.forEach((result, index) => {
180
+ if (result.status === 'fulfilled') {
181
+ console.log(`Song ${index + 1}: ${result.value.title}`);
182
+ } else {
183
+ console.log(`Song ${index + 1}: Error - ${result.reason.message}`);
184
+ }
185
+ });
186
+ ```
187
+
188
+ #### Working with Different Platforms
189
+
190
+ ```javascript
191
+ // Get all available platform links
192
+ const song = await odesli.fetch(
193
+ 'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR'
194
+ );
195
+
196
+ // Extract all platform URLs
197
+ const platformUrls = Object.entries(song.linksByPlatform).map(
198
+ ([platform, data]) => ({
199
+ platform,
200
+ url: data.url,
201
+ mobileUri: data.nativeAppUriMobile,
202
+ desktopUri: data.nativeAppUriDesktop,
203
+ })
204
+ );
205
+
206
+ console.log('Available platforms:', platformUrls);
207
+ ```
208
+
209
+ #### Error Recovery
210
+
211
+ ```javascript
212
+ async function fetchWithRetry(url, maxRetries = 3) {
213
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
214
+ try {
215
+ return await odesli.fetch(url);
216
+ } catch (error) {
217
+ if (attempt === maxRetries) throw error;
218
+
219
+ // Wait before retrying (exponential backoff)
220
+ await new Promise(resolve => setTimeout(resolve, attempt * 1000));
221
+ console.log(`Retry attempt ${attempt} for ${url}`);
222
+ }
223
+ }
224
+ }
225
+
226
+ // Usage
227
+ const song = await fetchWithRetry(
228
+ 'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR'
229
+ );
230
+ ```
231
+
232
+ ## Response Format
233
+
234
+ All methods return a response object with the following structure:
235
+
236
+ ```javascript
237
+ {
238
+ entityUniqueId: "SPOTIFY_SONG::4Km5HrUvYTaSUfiSGPJeQR",
239
+ title: "Bad and Boujee",
240
+ artist: ["Migos"],
241
+ type: "song",
242
+ thumbnail: "https://i.scdn.co/image/...",
243
+ userCountry: "US",
244
+ pageUrl: "https://song.link/i/4Km5HrUvYTaSUfiSGPJeQR",
245
+ linksByPlatform: {
246
+ spotify: {
247
+ entityUniqueId: "SPOTIFY_SONG::4Km5HrUvYTaSUfiSGPJeQR",
248
+ url: "https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR",
249
+ nativeAppUriMobile: "spotify://track/4Km5HrUvYTaSUfiSGPJeQR",
250
+ nativeAppUriDesktop: "spotify://track/4Km5HrUvYTaSUfiSGPJeQR"
251
+ },
252
+ appleMusic: {
253
+ // ... similar structure
254
+ }
255
+ // ... other platforms
256
+ },
257
+ entitiesByUniqueId: {
258
+ "SPOTIFY_SONG::4Km5HrUvYTaSUfiSGPJeQR": {
259
+ id: "4Km5HrUvYTaSUfiSGPJeQR",
260
+ type: "song",
261
+ title: "Bad and Boujee",
262
+ artistName: ["Migos"],
263
+ thumbnailUrl: "https://i.scdn.co/image/...",
264
+ apiProvider: "spotify",
265
+ platforms: ["spotify"]
266
+ }
267
+ // ... other entities
268
+ }
269
+ }
270
+ ```
271
+
272
+ ## Supported Platforms
273
+
274
+ - Spotify
275
+ - Apple Music
276
+ - iTunes
277
+ - YouTube Music
278
+ - YouTube
279
+ - Google Play Music
280
+ - Pandora
281
+ - Deezer
282
+ - Tidal
283
+ - Amazon Music
284
+ - SoundCloud
285
+ - Napster
286
+ - Yandex Music
287
+ - Spinrilla
288
+
289
+ ## TypeScript Support
290
+
291
+ This package includes full TypeScript definitions:
292
+
293
+ ```typescript
294
+ import Odesli from 'odesli.js';
295
+
296
+ const odesli = new Odesli({ apiKey: 'your-key' });
297
+ const song = await odesli.fetch('https://open.spotify.com/track/...');
298
+ // song is fully typed with all properties
299
+ ```
300
+
301
+ ## Examples
302
+
303
+ Check out the [examples directory](./examples) for more detailed usage examples:
304
+
305
+ - [Basic Usage](./examples/basic-usage.js) - Simple song fetching
306
+ - [Advanced Usage](./examples/advanced-usage.js) - Complex scenarios and error handling
307
+
308
+ ## API Documentation
309
+
310
+ For more detailed information about the Odesli API, check the [official documentation](https://www.notion.so/d8093b1bb8874f8b85527d985c4f9e68).
311
+
312
+ ## Contributing
313
+
314
+ 1. Fork the repository
315
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
316
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
317
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
318
+ 5. Open a Pull Request
319
+
320
+ ## License
321
+
322
+ This project is licensed under the ISC License - see the [LICENSE](LICENSE) file for details.
323
+
324
+ ## Support
325
+
326
+ - 📧 Email: `developers@song.link` (for API key requests)
327
+ - 🐛 Issues: [GitHub Issues](https://github.com/MattrAus/odesli.js/issues)
328
+ - 📖 Documentation: [Odesli API Docs](https://www.notion.so/d8093b1bb8874f8b85527d985c4f9e68)
package/SECURITY.md ADDED
@@ -0,0 +1,112 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ | ------- | ------------------ |
7
+ | 1.0.x | :white_check_mark: |
8
+
9
+ ## Reporting a Vulnerability
10
+
11
+ We take security vulnerabilities seriously. If you discover a security vulnerability in odesli.js, please follow these steps:
12
+
13
+ ### 1. **DO NOT** create a public GitHub issue
14
+
15
+ Security vulnerabilities should be reported privately to avoid potential exploitation.
16
+
17
+ ### 2. Email the maintainer
18
+
19
+ Send a detailed report to: `me@mtr.gg`
20
+
21
+ ### 3. Include the following information:
22
+
23
+ - **Description**: A clear description of the vulnerability
24
+ - **Steps to reproduce**: Detailed steps to reproduce the issue
25
+ - **Impact**: Potential impact of the vulnerability
26
+ - **Suggested fix**: If you have suggestions for fixing the issue
27
+ - **Affected versions**: Which versions are affected
28
+ - **Proof of concept**: If applicable, include a proof of concept
29
+
30
+ ### 4. Response timeline
31
+
32
+ - **Initial response**: Within 48 hours
33
+ - **Status update**: Within 1 week
34
+ - **Fix timeline**: Depends on severity and complexity
35
+
36
+ ## Security Best Practices
37
+
38
+ ### For Users
39
+
40
+ 1. **Keep dependencies updated**: Regularly update to the latest version
41
+ 2. **Use HTTPS**: Always use HTTPS when making API calls
42
+ 3. **Validate inputs**: Validate all user inputs before passing to the library
43
+ 4. **Rate limiting**: Respect API rate limits to avoid being blocked
44
+ 5. **API key security**: Store API keys securely and never commit them to version control
45
+
46
+ ### For Contributors
47
+
48
+ 1. **Code review**: All code changes require security review
49
+ 2. **Dependency scanning**: Run `npm audit` before submitting PRs
50
+ 3. **Input validation**: Always validate and sanitize inputs
51
+ 4. **Error handling**: Don't expose sensitive information in error messages
52
+ 5. **Testing**: Include security-focused tests
53
+
54
+ ## Security Features
55
+
56
+ ### Input Validation
57
+
58
+ - URL validation and sanitization
59
+ - Parameter type checking
60
+ - Malformed response handling
61
+
62
+ ### Error Handling
63
+
64
+ - Safe error messages that don't expose internal details
65
+ - Graceful handling of malformed API responses
66
+ - Rate limiting error handling
67
+
68
+ ### API Security
69
+
70
+ - HTTPS-only communication
71
+ - API key validation
72
+ - Request parameter sanitization
73
+
74
+ ## Dependency Security
75
+
76
+ We regularly audit our dependencies for security vulnerabilities:
77
+
78
+ ```bash
79
+ # Check for vulnerabilities
80
+ npm audit
81
+
82
+ # Fix automatically fixable issues
83
+ npm audit fix
84
+
85
+ # Run security scan with Snyk
86
+ npm run security
87
+ ```
88
+
89
+ ## Disclosure Policy
90
+
91
+ When a security vulnerability is discovered:
92
+
93
+ 1. **Private disclosure**: Issue is reported privately
94
+ 2. **Investigation**: We investigate and validate the issue
95
+ 3. **Fix development**: We develop and test a fix
96
+ 4. **Release**: We release a patched version
97
+ 5. **Public disclosure**: We publicly disclose the vulnerability with details
98
+
99
+ ## Security Updates
100
+
101
+ Security updates are released as patch versions (e.g., 1.0.1, 1.0.2) and should be applied immediately.
102
+
103
+ ## Contact
104
+
105
+ For security-related questions or concerns:
106
+
107
+ - Email: `me@mtr.gg`
108
+ - GitHub: [@MattrAus](https://github.com/MattrAus)
109
+
110
+ ## Acknowledgments
111
+
112
+ We appreciate security researchers and users who responsibly disclose vulnerabilities. Contributors to security improvements will be acknowledged in our release notes.
@@ -0,0 +1,50 @@
1
+ # Examples
2
+
3
+ This directory contains example code showing how to use the `odesli.js` package.
4
+
5
+ ## Basic Usage
6
+
7
+ Run the basic example to see how to fetch song information:
8
+
9
+ ```bash
10
+ node examples/basic-usage.js
11
+ ```
12
+
13
+ This example shows:
14
+
15
+ - Initializing the Odesli client
16
+ - Fetching a song by URL
17
+ - Displaying song information
18
+ - Showing available streaming platforms
19
+
20
+ ## Advanced Usage
21
+
22
+ Run the advanced example to see more complex scenarios:
23
+
24
+ ```bash
25
+ node examples/advanced-usage.js
26
+ ```
27
+
28
+ - By default, this will run without an API key and is limited to 10 requests per minute.
29
+ - If you need to make more than 10 requests per minute, set your API key as an environment variable:
30
+
31
+ ```bash
32
+ export ODESLI_API_KEY=your-api-key-here
33
+ node examples/advanced-usage.js
34
+ ```
35
+
36
+ This example shows:
37
+
38
+ - Using an API key for higher rate limits (optional)
39
+ - Fetching songs for different countries
40
+ - Using different methods (fetch, getByParams, getById)
41
+ - Processing multiple songs in parallel
42
+ - Error handling
43
+
44
+ ## Getting an API Key
45
+
46
+ An API key is **not required** for most users or for running these examples. You only need an API key if you want to make more than 10 requests per minute (for production or high-volume use). To get an API key for higher rate limits, email `developers@song.link`.
47
+
48
+ ## Note
49
+
50
+ The examples use real API calls, so you may be rate-limited if you make more than 10 requests per minute without an API key. The basic example should work with the free tier (10 requests/minute).
@@ -0,0 +1,66 @@
1
+ const Odesli = require('../lib/index.js');
2
+
3
+ async function advancedExample() {
4
+ // API key is optional. Only needed for more than 10 requests/minute.
5
+ const apiKey = process.env.ODESLI_API_KEY;
6
+ const odesli = apiKey
7
+ ? new Odesli({ apiKey, version: 'v1-alpha.1' })
8
+ : new Odesli();
9
+
10
+ if (!apiKey) {
11
+ console.log(
12
+ 'ℹ️ No API key set. You are limited to 10 requests per minute. Set ODESLI_API_KEY for higher limits.'
13
+ );
14
+ }
15
+
16
+ try {
17
+ // Example 1: Fetch by URL with custom country
18
+ console.log('🌍 Fetching song for UK market...');
19
+ const ukSong = await odesli.fetch(
20
+ 'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR',
21
+ 'GB'
22
+ );
23
+ console.log(`UK Title: ${ukSong.title}`);
24
+
25
+ // Example 2: Fetch by parameters
26
+ console.log('\n🎯 Fetching by parameters...');
27
+ const paramSong = await odesli.getByParams(
28
+ 'spotify',
29
+ 'song',
30
+ '4Km5HrUvYTaSUfiSGPJeQR'
31
+ );
32
+ console.log(`Param Title: ${paramSong.title}`);
33
+
34
+ // Example 3: Fetch by entity ID
35
+ console.log('\n🆔 Fetching by entity ID...');
36
+ const idSong = await odesli.getById('SPOTIFY_SONG::4Km5HrUvYTaSUfiSGPJeQR');
37
+ console.log(`ID Title: ${idSong.title}`);
38
+
39
+ // Example 4: Process multiple songs
40
+ console.log('\n📊 Processing multiple songs...');
41
+ const urls = [
42
+ 'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR',
43
+ 'https://open.spotify.com/track/0V3wPSX9ygBnCm8psDIegu',
44
+ ];
45
+
46
+ const songs = await Promise.all(
47
+ urls.map(url =>
48
+ odesli.fetch(url).catch(err => ({ error: err.message, url }))
49
+ )
50
+ );
51
+
52
+ songs.forEach((song, index) => {
53
+ if (song.error) {
54
+ console.log(`Song ${index + 1}: Error - ${song.error}`);
55
+ } else {
56
+ console.log(
57
+ `Song ${index + 1}: ${song.title} by ${song.artist.join(', ')}`
58
+ );
59
+ }
60
+ });
61
+ } catch (error) {
62
+ console.error('❌ Error:', error.message);
63
+ }
64
+ }
65
+
66
+ advancedExample();
@@ -0,0 +1,30 @@
1
+ const Odesli = require('../lib/index.js');
2
+
3
+ async function basicExample() {
4
+ // Initialize without API key (10 requests/minute limit)
5
+ const odesli = new Odesli();
6
+
7
+ try {
8
+ // Fetch a song by Spotify URL
9
+ console.log('🎵 Fetching song by URL...');
10
+ const song = await odesli.fetch(
11
+ 'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR'
12
+ );
13
+
14
+ console.log(`Title: ${song.title}`);
15
+ console.log(`Artist: ${song.artist.join(', ')}`);
16
+ console.log(`Type: ${song.type}`);
17
+ console.log(`Thumbnail: ${song.thumbnail}`);
18
+
19
+ // Show available platforms
20
+ console.log('\n📱 Available platforms:');
21
+ Object.keys(song.linksByPlatform).forEach(platform => {
22
+ const link = song.linksByPlatform[platform];
23
+ console.log(` ${platform}: ${link.url}`);
24
+ });
25
+ } catch (error) {
26
+ console.error('❌ Error:', error.message);
27
+ }
28
+ }
29
+
30
+ basicExample();