Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This repository holds the backend API and services that power Ytify which is a platform (or service) that enables users to (e.g.) stream, search, and manage YouTube-like video content

Notifications You must be signed in to change notification settings

Shashwat-CODING/ytify-backend

Repository files navigation

🎡 Music API - Comprehensive Music Streaming API

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

✨ Features

  • 🎡 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

πŸš€ Quick Start

Installation

# 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

Environment Variables (Optional)

Create a .env file:

PORT=5000
NODE_ENV=development
LASTFM_API_KEY=your_lastfm_api_key

πŸ“š API Documentation

Base URL

http://localhost:5000

Health Check

GET /health

🎡 Music Search & Discovery

1. YouTube Music Search

Search for songs, albums, artists, and playlists on YouTube Music.

GET /api/search?q={query}&filter={type}&limit={number}

Parameters:

  • q (required): Search query
  • filter (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"
 }
 ]
}

2. YouTube Search

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"

3. Search Suggestions

Get search suggestions for autocomplete features.

GET /api/search/suggestions?q={query}

Example:

curl "http://localhost:5000/api/search/suggestions?q=edm"

🎧 Music Streaming

1. Stream Music

Get streaming URLs from multiple sources (Saavn, Piped, Invidious).

GET /api/stream?id={videoId}&title={title}&artist={artist}

Parameters:

  • id (required): YouTube video ID
  • title (optional): Song title for Saavn matching
  • artist (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"
 }
}

2. Similar Tracks

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"

πŸ“Ί Channel Feeds

1. Authenticated Channel Feed

Get latest videos from subscribed channels (requires auth token).

GET /api/feed?authToken={token}&preview={boolean}

2. Unauthenticated Channel Feed

Get latest videos from specified channels.

GET /api/feed/unauthenticated?channels={channelIds}&preview={boolean}

Parameters:

  • channels (required): Comma-separated channel IDs
  • preview (optional): Limit to 5 videos per channel

Example:

curl "http://localhost:5000/api/feed/unauthenticated?channels=UCuAXFkgsw1L7xaCfnd5JJOw,UCBJycsmduvYEL83R_U4JriQ&preview=1"

3. Path-style Channel Feed

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"
 }
]

🎡 Album & Playlist Management

1. Get Album Details

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"
 }
 ]
 }
}

πŸ”§ Advanced Features

1. Dynamic Instance Management

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

2. Smart Content Filtering

  • 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

3. Robust Error Handling

  • 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

πŸ“Š Response Formats

Standard Success Response

{
 "success": true,
 "data": [...],
 "timestamp": "2025εΉ΄10月16ζ—₯T04:52:24.045Z"
}

Error Response

{
 "success": false,
 "error": "Error message",
 "code": "ERROR_CODE"
}

Pagination Response

{
 "success": true,
 "results": [...],
 "pagination": {
 "page": 1,
 "limit": 20,
 "total": 100,
 "hasMore": true
 }
}

πŸ› οΈ Development

Project Structure

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

Available Scripts

# Development
npm run dev
# Production
npm start
# Test
npm test

Dependencies

  • Express.js: Web framework
  • Axios: HTTP client
  • CORS: Cross-origin resource sharing
  • Helmet: Security middleware
  • Morgan: Logging middleware

πŸš€ Deployment

Vercel Deployment

The API is configured for Vercel deployment:

  1. Connect your GitHub repository to Vercel
  2. The vercel.json configuration will handle the deployment
  3. Environment variables can be set in Vercel dashboard

Environment Variables for Vercel

LASTFM_API_KEY=your_lastfm_api_key
NODE_ENV=production

πŸ”’ Security Features

  • 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

πŸ“ˆ Performance Optimizations

  • 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

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“„ License

MIT License - see LICENSE file for details.

πŸ†˜ Support

For issues and questions:

  1. Check the existing issues
  2. Create a new issue with detailed description
  3. Include logs and request/response examples

πŸ”„ Changelog

v2.0.0

  • 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

v1.0.0

  • Initial release with YouTube Music and YouTube Search
  • Basic search and suggestion functionality
  • RESTful API design

Made with ❀️ for the music community

About

This repository holds the backend API and services that power Ytify which is a platform (or service) that enables users to (e.g.) stream, search, and manage YouTube-like video content

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /