ytify-backend

🎵 ytify-backend

ytify-backend

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.

🌐 Backend BaseUrl: https://ytify-backend.vercel.app

API Status Node.js Express.js License

✨ Features

🚀 Quick Start

Installation

# Clone the repository
git clone https://github.com/Shashwat-CODING/ytify-backend.git
cd ytify-backend

# Install dependencies
npm install

# Start the server
npm start

The API will be available at http://localhost:5000

🌐 Frontend Demo

Experience the API in action with our live frontend demo:

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

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

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

Parameters:

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"

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:

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:

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-25T06: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:

2. Smart Content Filtering

3. Robust Error Handling

📊 Response Formats

Standard Success Response

{
  "success": true,
  "data": [...],
  "timestamp": "2025-10-16T04: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

ytify-backend/
├── js/                      # Main project directory
│   ├── 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
│   ├── icon.png           # Project icon
│   └── README.md          # This file

Available Scripts

# Development
npm run dev

# Production
npm start

# Test
npm test

Dependencies

🚀 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

📈 Performance Optimizations

🤝 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 on GitHub
  2. Create a new issue with detailed description
  3. Include logs and request/response examples
  4. Visit our live demo to test the API

🔄 Changelog

v2.0.0

v1.0.0


Made with ❤️ by Shashwat for the ytify community