A powerful Node.js/Express.js API that provides access to multiple music streaming services including YouTube Music, YouTube Search, Last.fm, Saavn, Piped, and Invidious. Perfect for building music applications, playlists, and discovery features.
API Status Node.js Express.js License
- π΅ YouTube Music Integration - Search songs, albums, artists, playlists
- π YouTube Search - Search videos, channels, playlists with suggestions
- π§ Last.fm Integration - Get similar tracks and music recommendations
- πΆ Saavn API - Search and stream music from JioSaavn
- πΊ Piped & Invidious - Alternative YouTube streaming sources
- π¨ Channel Feeds - Get latest videos from YouTube channels
- π± RESTful API - Clean, well-documented endpoints
- π CORS Support - Cross-origin resource sharing enabled
- π Comprehensive Logging - Detailed request/response logging
# Clone the repository git clone https://github.com/Shashwat-CODING/ytify-backend.git cd Music/js # Install dependencies npm install # Start the server npm start
The API will be available at http://localhost:5000
Create a .env
file:
PORT=5000 NODE_ENV=development LASTFM_API_KEY=your_lastfm_api_key
http://localhost:5000
GET /health
Search for songs, albums, artists, and playlists on YouTube Music.
GET /api/search?q={query}&filter={type}&limit={number}
Parameters:
q
(required): Search queryfilter
(optional):songs
,albums
,artists
,playlists
,videos
limit
(optional): Number of results (default: 20)
Example:
curl "http://localhost:5000/api/search?q=edm&filter=songs&limit=10"
Response:
{ "success": true, "results": [ { "id": "dQw4w9WgXcQ", "title": "Never Gonna Give You Up", "artist": "Rick Astley", "duration": "3:33", "thumbnail": "https://i.ytimg.com/vi/dQw4w9WgXcQ/hqdefault.jpg", "type": "song" } ] }
Search YouTube videos, channels, and playlists.
GET /api/yt_search?q={query}&filter={type}&limit={number}
Example:
curl "http://localhost:5000/api/yt_search?q=music&filter=videos&limit=5"
Get search suggestions for autocomplete features.
GET /api/search/suggestions?q={query}
Example:
curl "http://localhost:5000/api/search/suggestions?q=edm"
Get streaming URLs from multiple sources (Saavn, Piped, Invidious).
GET /api/stream?id={videoId}&title={title}&artist={artist}
Parameters:
id
(required): YouTube video IDtitle
(optional): Song title for Saavn matchingartist
(optional): Artist name for Saavn matching
Example:
curl "http://localhost:5000/api/stream?id=dQw4w9WgXcQ&title=Never%20Gonna%20Give%20You%20Up&artist=Rick%20Astley"
Response:
{ "success": true, "service": "saavn", "instance": "saavn.dev", "streamingUrls": [ { "url": "https://...", "quality": "320kbps", "format": "mp3" } ], "metadata": { "title": "Never Gonna Give You Up", "artist": "Rick Astley", "duration": "3:33" } }
Get similar tracks using Last.fm recommendations.
GET /api/similar?title={title}&artist={artist}&limit={number}
Example:
curl "http://localhost:5000/api/similar?title=Shape%20of%20You&artist=Ed%20Sheeran&limit=5"
Get latest videos from subscribed channels (requires auth token).
GET /api/feed?authToken={token}&preview={boolean}
Get latest videos from specified channels.
GET /api/feed/unauthenticated?channels={channelIds}&preview={boolean}
Parameters:
channels
(required): Comma-separated channel IDspreview
(optional): Limit to 5 videos per channel
Example:
curl "http://localhost:5000/api/feed/unauthenticated?channels=UCuAXFkgsw1L7xaCfnd5JJOw,UCBJycsmduvYEL83R_U4JriQ&preview=1"
Alternative endpoint format for channel feeds.
GET /api/feed/channels={channelIds}?preview={boolean}
Example:
curl "http://localhost:5000/api/feed/channels=UCuAXFkgsw1L7xaCfnd5JJOw,UCBJycsmduvYEL83R_U4JriQ?preview=1"
Response:
[ { "id": "dQw4w9WgXcQ", "authorId": "UCuAXFkgsw1L7xaCfnd5JJOw", "duration": "3:33", "author": "Rick Astley", "views": "1.2B", "uploaded": "2009εΉ΄10ζ25ζ₯T06:57:33.000Z", "title": "Never Gonna Give You Up" } ]
Fetch detailed information about an album.
GET /api/album/{albumId}
Example:
curl "http://localhost:5000/api/album/MPREb_qTDpBqltt6c"
Response:
{ "success": true, "album": { "id": "MPREb_qTDpBqltt6c", "playlistId": "OLAK5uy_mwBKAsTr40eAsSEDTgy6iiEoI2edmH9q8", "title": "Releases for you", "artist": "Nseeb", "year": "2025", "thumbnail": "https://lh3.googleusercontent.com/...", "tracks": [ { "id": "K9R7KcaettM", "title": "I Really Do...", "artist": "Nseeb", "duration": "3:14", "thumbnail": "https://i.ytimg.com/vi/K9R7KcaettM/hqdefault.jpg", "videoId": "K9R7KcaettM" } ] } }
The API automatically fetches and caches streaming instances from remote sources:
- Piped Instances:
https://raw.githubusercontent.com/n-ce/Uma/main/dynamic_instances.json
- Invidious Instances: Same source as Piped
- Saavn API: Uses
saavn.dev
for reliable access
- Shorts Detection: Automatically filters out YouTube Shorts from feeds
- Duration Parsing: Handles various duration formats (MM:SS, HH:MM:SS)
- Play Count Filtering: Distinguishes between artist names and play counts
- Service Fallbacks: If one service fails, tries alternatives
- Timeout Management: Configurable timeouts for all requests
- Retry Logic: Automatic retries for failed requests
- Comprehensive Logging: Detailed logs for debugging
{ "success": true, "data": [...], "timestamp": "2025εΉ΄10ζ16ζ₯T04:52:24.045Z" }
{ "success": false, "error": "Error message", "code": "ERROR_CODE" }
{ "success": true, "results": [...], "pagination": { "page": 1, "limit": 20, "total": 100, "hasMore": true } }
js/
βββ app.js # Main Express application
βββ api/
β βββ app.js # Vercel serverless entry point
βββ lib/ # Custom libraries
β βββ ytmusicapi.js # YouTube Music API
β βββ youtube-search.js # YouTube Search API
β βββ lastfm_api.js # Last.fm integration
β βββ get_youtube_song.js # YouTube song helper
βββ routes/
β βββ api.js # Main API routes
βββ vercel.json # Vercel configuration
βββ package.json # Dependencies
βββ README.md # This file
# Development npm run dev # Production npm start # Test npm test
- Express.js: Web framework
- Axios: HTTP client
- CORS: Cross-origin resource sharing
- Helmet: Security middleware
- Morgan: Logging middleware
The API is configured for Vercel deployment:
- Connect your GitHub repository to Vercel
- The
vercel.json
configuration will handle the deployment - Environment variables can be set in Vercel dashboard
LASTFM_API_KEY=your_lastfm_api_key NODE_ENV=production
- CORS Configuration: Properly configured for cross-origin requests
- Input Validation: All inputs are validated and sanitized
- Rate Limiting: Built-in rate limiting (configurable)
- Security Headers: Helmet.js for security headers
- Error Handling: No sensitive information in error responses
- Parallel Processing: Multiple API calls run in parallel
- Caching: Instance data is cached to reduce API calls
- Timeout Management: Prevents hanging requests
- Efficient Parsing: Optimized JSON parsing and data extraction
- Memory Management: Proper cleanup of large responses
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.
For issues and questions:
- Check the existing issues
- Create a new issue with detailed description
- Include logs and request/response examples
- Added Last.fm integration
- Added Saavn, Piped, and Invidious streaming
- Added channel feed endpoints
- Added album details endpoint
- Improved error handling and logging
- Added dynamic instance management
- Initial release with YouTube Music and YouTube Search
- Basic search and suggestion functionality
- RESTful API design
Made with β€οΈ for the music community