### Install spotify-preview-finder and dotenv Source: https://www.npmjs.com/package/spotify-preview-finder/v/2.1.0?activeTab=versions Installs the spotify-preview-finder package along with dotenv for managing environment variables. This is a prerequisite for using the package's authentication features. ```bash npm install spotify-preview-finder dotenv ``` -------------------------------- ### Perform Spotify song searches Source: https://www.npmjs.com/package/spotify-preview-finder/v/2.1.0?activeTab=readme Demonstrates how to perform basic searches by song name, enhanced searches with artist names, and batch processing of multiple tracks. These examples require a configured .env file with Spotify credentials. ```javascript require('dotenv').config(); const spotifyPreviewFinder = require('spotify-preview-finder'); async function example() { try { const result = await spotifyPreviewFinder('Shape of You', 3); if (result.success) { result.results.forEach(song => { console.log(`Song: ${song.name}`); console.log(`Preview URLs: ${song.previewUrls.join(', ')}`); }); } } catch (error) { console.error('Error:', error.message); } } example(); ``` ```javascript require('dotenv').config(); const spotifyPreviewFinder = require('spotify-preview-finder'); async function enhancedSearch() { try { const result = await spotifyPreviewFinder('Shape of You', 'Ed Sheeran', 2); if (result.success) { result.results.forEach(song => { console.log(`Found: ${song.name} by ${song.albumName}`); }); } } catch (error) { console.error('Error:', error.message); } } enhancedSearch(); ``` ```javascript require('dotenv').config(); const spotifyPreviewFinder = require('spotify-preview-finder'); async function batchSearch() { const searches = [ { song: 'Bohemian Rhapsody', artist: 'Queen' }, { song: 'Imagine' } ]; for (const search of searches) { const result = search.artist ? await spotifyPreviewFinder(search.song, search.artist, 1) : await spotifyPreviewFinder(search.song, 1); console.log(result); } } batchSearch(); ``` -------------------------------- ### Perform Spotify song searches Source: https://www.npmjs.com/package/spotify-preview-finder/v/2.1.0?activeTab=code Examples demonstrating basic search by song name, enhanced search by song and artist, and batch processing. These functions return song metadata including album, release date, popularity, and preview URLs. ```javascript require('dotenv').config(); const spotifyPreviewFinder = require('spotify-preview-finder'); async function example() { try { const result = await spotifyPreviewFinder('Shape of You', 3); if (result.success) { result.results.forEach(song => { console.log(`Song: ${song.name}`); console.log(`Preview URLs: ${song.previewUrls.join(', ')}`); }); } } catch (error) { console.error('Error:', error.message); } } async function enhancedSearch() { const result = await spotifyPreviewFinder('Shape of You', 'Ed Sheeran', 2); // ... handle result } async function batchSearch() { const searches = [{ song: 'Bohemian Rhapsody', artist: 'Queen' }, { song: 'Yesterday' }]; for (const search of searches) { const result = await spotifyPreviewFinder(search.song, search.artist, 1); // ... handle result } } ``` -------------------------------- ### Environment Variables Setup for Spotify Credentials Source: https://www.npmjs.com/package/spotify-preview-finder/v/2.1.0?activeTab=versions Configures the necessary Spotify API credentials (Client ID and Client Secret) by creating a `.env` file in the project's root directory. These credentials are used by the package for authentication. ```dotenv SPOTIFY_CLIENT_ID=your_client_id SPOTIFY_CLIENT_SECRET=your_client_secret ``` -------------------------------- ### Perform Spotify song searches Source: https://www.npmjs.com/package/spotify-preview-finder/v/2.1.0?activeTab=dependencies Examples demonstrating how to perform basic searches by song name, enhanced searches by song name and artist, and batch processing of multiple search queries. These functions return a result object containing track metadata and preview URLs. ```javascript require('dotenv').config(); const spotifyPreviewFinder = require('spotify-preview-finder'); async function example() { try { const result = await spotifyPreviewFinder('Shape of You', 3); if (result.success) { result.results.forEach(song => { console.log(`Song: ${song.name}`); console.log(`Preview URLs: ${song.previewUrls.join(', ')}`); }); } } catch (error) { console.error('Error:', error.message); } } async function enhancedSearch() { const result = await spotifyPreviewFinder('Shape of You', 'Ed Sheeran', 2); // Process result... } async function batchSearch() { const searches = [{ song: 'Bohemian Rhapsody', artist: 'Queen' }]; for (const search of searches) { const result = await spotifyPreviewFinder(search.song, search.artist, 1); // Process result... } } ``` -------------------------------- ### GET /spotify-preview-finder Source: https://www.npmjs.com/package/spotify-preview-finder/v/2.1.0?activeTab=dependents Searches for Spotify tracks based on song name, optional artist, and result limits. ```APIDOC ## GET spotifyPreviewFinder ### Description Searches for song previews and metadata on Spotify. Supports basic song searches or enhanced searches by specifying an artist. ### Method Function Call (Async) ### Parameters #### Query Parameters - **songName** (string) - Required - The name of the song to search for - **artistOrLimit** (string|number) - Optional - Either the artist name (string) or the maximum number of results (number) - **limit** (number) - Optional - Maximum number of results to return (default: 5) ### Request Example ```javascript await spotifyPreviewFinder('Shape of You', 'Ed Sheeran', 2); ``` ### Response #### Success Response (200) - **success** (boolean) - Whether the request was successful - **searchQuery** (string) - The actual search query used - **results** (array) - Array of song objects containing name, spotifyUrl, previewUrls, trackId, albumName, releaseDate, popularity, and durationMs #### Response Example { "success": true, "searchQuery": "track:\"Shape of You\" artist:\"Ed Sheeran\"", "results": [ { "name": "Shape of You - Ed Sheeran", "spotifyUrl": "https://open.spotify.com/track/7qiZfU4dY1lWllzX7mPBI3", "previewUrls": ["https://p.scdn.co/mp3-preview/7339548839a263fd721d01eb3364a848cad16fa7"], "trackId": "7qiZfU4dY1lWllzX7mPBI3", "albumName": "÷ (Deluxe)", "releaseDate": "2017-03-03", "popularity": 87, "durationMs": 233713 } ] } ``` -------------------------------- ### Basic Search Response Structure Source: https://www.npmjs.com/package/spotify-preview-finder?activeTab=versions An example of the JSON response structure returned by a basic search query using the spotify-preview-finder package. It includes success status, the search query used, and an array of song result objects. ```json { "success": true, "searchQuery": "Shape of You", "results": [ { "name": "Shape of You - Ed Sheeran", "spotifyUrl": "https://open.spotify.com/track/7qiZfU4dY1lWllzX7mPBI3", "previewUrls": [ "https://p.scdn.co/mp3-preview/7339548839a263fd721d01eb3364a848cad16fa7" ], "trackId": "7qiZfU4dY1lWllzX7mPBI3", "albumName": "÷ (Deluxe)", "releaseDate": "2017-03-03", "popularity": 87, "durationMs": 233713 } // ... more results ] } ``` -------------------------------- ### GET /spotify-preview-finder Source: https://www.npmjs.com/package/spotify-preview-finder/v/2.1.0?activeTab=readme Searches for Spotify tracks based on a song name and optional artist or result limit. ```APIDOC ## GET spotifyPreviewFinder ### Description Searches for a song on Spotify and returns track metadata including preview URLs. ### Method Function Call (Node.js) ### Parameters #### Query Parameters - **songName** (string) - Required - The name of the song to search for. - **artistOrLimit** (string|number) - Optional - Either the artist name for accuracy or the maximum number of results. - **limit** (number) - Optional - Maximum number of results to return (default: 5, used when artistOrLimit is an artist name). ### Request Example ```javascript await spotifyPreviewFinder('Shape of You', 'Ed Sheeran', 2); ``` ### Response #### Success Response (200) - **success** (boolean) - Whether the request was successful - **searchQuery** (string) - The actual search query used - **results** (array) - Array of song objects containing name, spotifyUrl, previewUrls, trackId, albumName, releaseDate, popularity, and durationMs #### Response Example { "success": true, "searchQuery": "track:\"Shape of You\" artist:\"Ed Sheeran\"", "results": [ { "name": "Shape of You - Ed Sheeran", "spotifyUrl": "https://open.spotify.com/track/7qiZfU4dY1lWllzX7mPBI3", "previewUrls": ["https://p.scdn.co/mp3-preview/7339548839a263fd721d01eb3364a848cad16fa7"], "trackId": "7qiZfU4dY1lWllzX7mPBI3", "albumName": "÷ (Deluxe)", "releaseDate": "2017-03-03", "popularity": 87, "durationMs": 233713 } ] } ``` -------------------------------- ### GET /spotify-preview-finder Source: https://www.npmjs.com/package/spotify-preview-finder/v/2.1.0 Searches for Spotify tracks based on a song name, with optional artist filtering and result limiting. ```APIDOC ## GET /spotify-preview-finder ### Description Searches for song previews and track information. Supports basic search by song name or enhanced search by providing an artist name. ### Method GET (via function call) ### Parameters #### Query Parameters - **songName** (string) - Required - The name of the song to search for. - **artistOrLimit** (string|number) - Optional - Either the artist name (string) for accuracy or the maximum number of results (number). - **limit** (number) - Optional - Maximum number of results to return (default: 5, only used when artistOrLimit is an artist name). ### Request Example ```javascript await spotifyPreviewFinder('Shape of You', 'Ed Sheeran', 2); ``` ### Response #### Success Response (200) - **success** (boolean) - Whether the request was successful. - **searchQuery** (string) - The actual search query used. - **results** (array) - List of objects containing track details (name, spotifyUrl, previewUrls, trackId, albumName, releaseDate, popularity, durationMs). #### Response Example ```json { "success": true, "searchQuery": "track:\"Shape of You\" artist:\"Ed Sheeran\"", "results": [ { "name": "Shape of You - Ed Sheeran", "spotifyUrl": "https://open.spotify.com/track/7qiZfU4dY1lWllzX7mPBI3", "previewUrls": ["https://p.scdn.co/mp3-preview/7339548839a263fd721d01eb3364a848cad16fa7"], "trackId": "7qiZfU4dY1lWllzX7mPBI3", "albumName": "÷ (Deluxe)", "releaseDate": "2017-03-03", "popularity": 87, "durationMs": 233713 } ] } ``` ``` -------------------------------- ### GET /spotifyPreviewFinder Source: https://www.npmjs.com/package/spotify-preview-finder/v/2.1.0?activeTab=dependencies Searches for song previews and metadata on Spotify. Supports basic song name searches or enhanced searches with artist filtering. ```APIDOC ## GET /spotifyPreviewFinder ### Description Searches for tracks on Spotify based on a song name, with optional support for artist filtering and result limiting. ### Method GET ### Endpoint spotifyPreviewFinder(songName, artistOrLimit, limit) ### Parameters #### Query Parameters - **songName** (string) - Required - The name of the song to search for. - **artistOrLimit** (string|number) - Optional - Either the artist name (string) for accuracy or the maximum number of results (number). - **limit** (number) - Optional - Maximum number of results to return (default: 5, only used when artistOrLimit is an artist name). ### Request Example ```javascript await spotifyPreviewFinder('Shape of You', 'Ed Sheeran', 2); ``` ### Response #### Success Response (200) - **success** (boolean) - Whether the request was successful. - **searchQuery** (string) - The actual search query used. - **results** (array) - Array of song objects containing name, spotifyUrl, previewUrls, trackId, albumName, releaseDate, popularity, and durationMs. #### Response Example ```json { "success": true, "searchQuery": "track:\"Shape of You\" artist:\"Ed Sheeran\"", "results": [ { "name": "Shape of You - Ed Sheeran", "spotifyUrl": "https://open.spotify.com/track/7qiZfU4dY1lWllzX7mPBI3", "previewUrls": ["https://p.scdn.co/mp3-preview/7339548839a263fd721d01eb3364a848cad16fa7"], "trackId": "7qiZfU4dY1lWllzX7mPBI3", "albumName": "÷ (Deluxe)", "releaseDate": "2017-03-03", "popularity": 87, "durationMs": 233713 } ] } ``` ``` -------------------------------- ### Enhanced Search Response Structure (with Artist) Source: https://www.npmjs.com/package/spotify-preview-finder?activeTab=versions An example of the JSON response structure for an enhanced search that includes an artist parameter. The `searchQuery` field reflects the more specific query used, and the results are similarly detailed song objects. ```json { "success": true, "searchQuery": 'track:"Shape of You" artist:"Ed Sheeran"', "results": [ { "name": "Shape of You - Ed Sheeran", "spotifyUrl": "https://open.spotify.com/track/7qiZfU4dY1lWllzX7mPBI3", "previewUrls": [ "https://p.scdn.co/mp3-preview/7339548839a263fd721d01eb3364a848cad16fa7" ], "trackId": "7qiZfU4dY1lWllzX7mPBI3", "albumName": "÷ (Deluxe)", "releaseDate": "2017-03-03", "popularity": 87, "durationMs": 233713 } ] } ``` -------------------------------- ### Basic Spotify Song Search with spotify-preview-finder Source: https://www.npmjs.com/package/spotify-preview-finder?activeTab=dependents Demonstrates how to perform a basic search for a song using the spotify-preview-finder package. It shows how to specify the song name and optionally set a limit for the number of results. This function is backward compatible and defaults to 5 results if no limit is provided. ```javascript await spotifyPreviewFinder('Shape of You'); // Default limit of 5 await spotifyPreviewFinder('Shape of You', 3); // Limit to 3 results ``` -------------------------------- ### Configure Spotify environment variables Source: https://www.npmjs.com/package/spotify-preview-finder/v/2.1.0?activeTab=versions Shows the required format for storing Spotify API credentials in a .env file to enable package authentication. ```text SPOTIFY_CLIENT_ID=your_client_id_here SPOTIFY_CLIENT_SECRET=your_client_secret_here ``` -------------------------------- ### Search for Spotify tracks Source: https://www.npmjs.com/package/spotify-preview-finder?activeTab=versions Demonstrates various ways to search for songs using the spotify-preview-finder package, including basic name-only searches, enhanced artist-specific searches, and batch processing. ```javascript require('dotenv').config(); const spotifyPreviewFinder = require('spotify-preview-finder'); async function example() { try { const result = await spotifyPreviewFinder('Shape of You', 3); if (result.success) { result.results.forEach(song => { console.log(`Song: ${song.name}`); console.log(`Preview URLs: ${song.previewUrls.join(', ')}`); }); } } catch (error) { console.error('Error:', error.message); } } // Enhanced Search async function enhancedSearch() { const result = await spotifyPreviewFinder('Shape of You', 'Ed Sheeran', 2); console.log(result); } // Batch Search async function batchSearch() { const searches = [{ song: 'Bohemian Rhapsody', artist: 'Queen' }]; for (const search of searches) { const result = await spotifyPreviewFinder(search.song, search.artist, 1); console.log(result); } } ``` -------------------------------- ### Basic Song Search with spotify-preview-finder Source: https://www.npmjs.com/package/spotify-preview-finder/v/2.1.0?activeTab=versions Demonstrates how to search for a song using only its name. It retrieves song details like album, release date, popularity, duration, Spotify URL, and available preview URLs. Error handling is included. ```javascript require('dotenv').config(); const spotifyPreviewFinder = require('spotify-preview-finder'); async function example() { try { // Search by song name only (limit is optional, default is 5) const result = await spotifyPreviewFinder('Shape of You', 3); if (result.success) { console.log(`Search Query Used: ${result.searchQuery}`); result.results.forEach(song => { console.log(`\nSong: ${song.name}`); console.log(`Album: ${song.albumName}`); console.log(`Release Date: ${song.releaseDate}`); console.log(`Popularity: ${song.popularity}`); console.log(`Duration: ${Math.round(song.durationMs / 1000)}s`); console.log(`Spotify URL: ${song.spotifyUrl}`); console.log('Preview URLs:'); song.previewUrls.forEach(url => console.log(`- ${url}`)); }); } else { console.error('Error:', result.error); } } catch (error) { console.error('Error:', error.message); } } example(); ``` -------------------------------- ### Search for Spotify song previews Source: https://www.npmjs.com/package/spotify-preview-finder?activeTab=dependencies Demonstrates how to search for songs using either just the song name or a combination of song name and artist. The functions return an object containing track metadata and an array of preview URLs. ```javascript require('dotenv').config(); const spotifyPreviewFinder = require('spotify-preview-finder'); async function example() { try { const result = await spotifyPreviewFinder('Shape of You', 3); if (result.success) { result.results.forEach(song => { console.log(`Song: ${song.name}`); console.log(`Preview URLs: ${song.previewUrls.join(', ')}`); }); } } catch (error) { console.error('Error:', error.message); } } async function enhancedSearch() { try { const result = await spotifyPreviewFinder('Shape of You', 'Ed Sheeran', 2); if (result.success) { console.log(`Found: ${result.results[0].name}`); } } catch (error) { console.error('Error:', error.message); } } example(); enhancedSearch(); ``` -------------------------------- ### Perform batch searches Source: https://www.npmjs.com/package/spotify-preview-finder?activeTab=dependencies Iterate through an array of search objects to retrieve preview data for multiple tracks efficiently. ```javascript const searches = [ { song: 'Bohemian Rhapsody', artist: 'Queen' }, { song: 'Imagine', artist: 'John Lennon' } ]; for (const search of searches) { const result = await spotifyPreviewFinder(search.song, search.artist, 1); if (result.success && result.results.length > 0) { console.log(`Found: ${result.results[0].name}`); } } ``` -------------------------------- ### Perform Spotify song searches Source: https://www.npmjs.com/package/spotify-preview-finder/v/2.1.0?activeTab=dependents Demonstrates basic, enhanced (artist-specific), and batch search patterns. These functions return song metadata including preview URLs, album information, and popularity scores. ```javascript require('dotenv').config(); const spotifyPreviewFinder = require('spotify-preview-finder'); async function example() { try { const result = await spotifyPreviewFinder('Shape of You', 3); if (result.success) { result.results.forEach(song => { console.log(`Song: ${song.name}`); console.log(`Preview URLs: ${song.previewUrls.join(', ')}`); }); } } catch (error) { console.error('Error:', error.message); } } async function enhancedSearch() { const result = await spotifyPreviewFinder('Shape of You', 'Ed Sheeran', 2); // ... handle result } ``` -------------------------------- ### Batch Song Search with spotify-preview-finder Source: https://www.npmjs.com/package/spotify-preview-finder/v/2.1.0?activeTab=versions Illustrates how to search for multiple songs in a single operation, including songs with and without specified artists. This is useful for retrieving information for a list of tracks efficiently. ```javascript require('dotenv').config(); const spotifyPreviewFinder = require('spotify-preview-finder'); async function batchSearch() { try { const searches = [ { song: 'Bohemian Rhapsody', artist: 'Queen' }, { song: 'Hotel California', artist: 'Eagles' }, { song: 'Imagine', artist: 'John Lennon' }, { song: 'Yesterday' } // Without artist for comparison ]; for (const search of searches) { let result; if (search.artist) { result = await spotifyPreviewFinder(search.song, search.artist, 1); console.log(`\n=== Searching: "${search.song}" by "${search.artist}" ===`); } else { result = await spotifyPreviewFinder(search.song, 1); console.log(`\n=== Searching: "${search.song}" (no artist specified) ===`); } if (result.success && result.results.length > 0) { const song = result.results[0]; console.log(`Found: ${song.name}`); console.log(`Album: ${song.albumName} (${song.releaseDate})`); console.log(`Popularity: ${song.popularity}/100`); if (song.previewUrls.length > 0) { console.log(`Preview URL: ${song.previewUrls[0]}`); } else { console.log('No preview URLs found'); } } else { console.log('No results found'); } } } catch (error) { console.error('Error:', error.message); } } batchSearch(); ``` -------------------------------- ### Enhanced Spotify Song Search with Artist using spotify-preview-finder Source: https://www.npmjs.com/package/spotify-preview-finder?activeTab=dependents Illustrates how to conduct a more accurate song search by including the artist's name along with the song title. This method enhances search precision and result ranking. It also shows how to set a specific limit for the number of results when an artist is provided. ```javascript await spotifyPreviewFinder('Shape of You', 'Ed Sheeran'); // Default limit of 5 await spotifyPreviewFinder('Shape of You', 'Ed Sheeran', 2); // Limit to 2 results ``` -------------------------------- ### Enhanced Song Search with Artist using spotify-preview-finder Source: https://www.npmjs.com/package/spotify-preview-finder/v/2.1.0?activeTab=versions Shows how to perform a more accurate song search by including both the song name and the artist's name. This method improves the reliability of the search results and retrieves track-specific information. ```javascript require('dotenv').config(); const spotifyPreviewFinder = require('spotify-preview-finder'); async function enhancedSearch() { try { // Search with both song name and artist for higher accuracy const result = await spotifyPreviewFinder('Shape of You', 'Ed Sheeran', 2); if (result.success) { console.log(`Search Query Used: ${result.searchQuery}`); result.results.forEach(song => { console.log(`\nFound: ${song.name}`); console.log(`Album: ${song.albumName}`); console.log(`Track ID: ${song.trackId}`); console.log('Preview URLs:'); song.previewUrls.forEach(url => console.log(`- ${url}`)); }); } else { console.error('Error:', result.error); } } catch (error) { console.error('Error:', error.message); } } enhancedSearch(); ``` -------------------------------- ### Search for Spotify song previews using JavaScript Source: https://www.npmjs.com/package/spotify-preview-finder/v/2.1.0?activeTab=versions Demonstrates how to use the spotifyPreviewFinder function to search for tracks. It supports both basic searches and enhanced searches by specifying an artist and result limit. ```javascript // Basic search (backward compatible) await spotifyPreviewFinder('Shape of You'); // Default limit of 5 await spotifyPreviewFinder('Shape of You', 3); // Limit to 3 results // Enhanced search with artist await spotifyPreviewFinder('Shape of You', 'Ed Sheeran'); // Default limit of 5 await spotifyPreviewFinder('Shape of You', 'Ed Sheeran', 2); // Limit to 2 results ``` -------------------------------- ### Spotify Preview Finder API Source: https://www.npmjs.com/package/spotify-preview-finder?activeTab=code This API endpoint allows you to search for songs on Spotify and retrieve preview URLs and other song details. You can perform a basic search by song name or an enhanced search by providing an artist name for more accurate results. ```APIDOC ## spotifyPreviewFinder ### Description Searches for songs on Spotify and returns preview URLs and song details. ### Method Function Call ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Function Parameters - **songName** (string) - **Required** - The name of the song to search for. - **artistOrLimit** (string|number, optional) - Either the artist name (string) for more accurate results or the maximum number of results (number) for backward compatibility. - **limit** (number, optional) - Maximum number of results to return (default: 5). Only used when `artistOrLimit` is an artist name. ### Request Example ```javascript // Basic search (backward compatible) await spotifyPreviewFinder('Shape of You'); // Default limit of 5 await spotifyPreviewFinder('Shape of You', 3); // Limit to 3 results // Enhanced search with artist await spotifyPreviewFinder('Shape of You', 'Ed Sheeran'); // Default limit of 5 await spotifyPreviewFinder('Shape of You', 'Ed Sheeran', 2); // Limit to 2 results ``` ### Response #### Success Response (200) Returns a Promise that resolves to an object with: - **success** (boolean) - Whether the request was successful. - **searchQuery** (string) - The actual search query used. - **results** (array) - Array of song objects containing: - **name** (string) - Song name with artist(s). - **spotifyUrl** (string) - Spotify URL for the song. - **previewUrls** (array) - Array of preview URLs. - **trackId** (string) - Spotify track ID. - **albumName** (string) - Album name. - **releaseDate** (string) - Release date. - **popularity** (number) - Popularity score (0-100). - **durationMs** (number) - Duration in milliseconds. - **error** (string) - Error message if success is false. #### Response Example ```json { "success": true, "searchQuery": "Shape of You", "results": [ { "name": "Shape of You - Ed Sheeran", "spotifyUrl": "https://open.spotify.com/track/7qiZfU4dY1lWllzX7mPBI3", "previewUrls": [ "https://p.scdn.co/mp3-preview/7339548839a263fd721d01eb3364a848cad16fa7" ], "trackId": "7qiZfU4dY1lWllzX7mPBI3", "albumName": "÷ (Deluxe)", "releaseDate": "2017-03-03", "popularity": 87, "durationMs": 233713 } ] } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.