Skip to content

Advanced Lavalink/Lavaplayer Search Plugin/Module

License

Notifications You must be signed in to change notification settings

topi314/LavaSearch

Repository files navigation

LavaSearch

LavaSearch is an advanced search module for Lavaplayer and Lavalink. It returns a better search result than the default search support of Lavaplayer/Lavalink.

You can use this module with Lavaplayer or as a plugin for Lavalink v4 beta 3 or higher. Other plugins can link into this module to provide additional search sources.

Table of Contents

Supported Sources

  • LavaSrc (YouTube, YouTubeMusic, Deezer, Spotify, AppleMusic)

Add your own

Lavaplayer Usage

Replace x.y.z with the latest version number

Snapshot builds are available in https://maven.topi.wtf/snapshots with the short commit hash as the version

Using in Gradle:

Gradle
repositories {
  maven {
    url "https://maven.topi.wtf/releases"
  }
}

dependencies {
  implementation "com.github.topi314.lavasearch:lavasearch:x.y.z"
}

Using in Maven:

Maven
<repositories>
  <repository>
    <url>https://maven.topi.wtf/releases</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>com.github.topi314.lavasearch</groupId>
    <artifactId>lavasearch</artifactId>
    <version>x.y.z</version>
  </dependency>
</dependencies>

Usage

Create new SearchManager

var searchManager = new SearchManager();

//register sources
searchManager.registerSearchManager(source);

Basic usage

var query = "ytmsearch:bla bla";
var types = List.of(
        AudioSearchResult.Type.TRACK,
        AudioSearchResult.Type.PLAYLIST,
        AudioSearchResult.Type.ALBUM,
        AudioSearchResult.Type.ARTIST,
        AudioSearchResult.Type.TEXT
);


AudioSearchResult searchResult = searchManager.loadSearch(query, types);

Lavalink Usage

This plugin requires Lavalink v4 or greater

To install this plugin either download the latest release and place it into your plugins folder or add the following into your application.yml

Note For a full application.yml example see here

Replace x.y.z with the latest version number

lavalink:
  plugins:
    - dependency: "com.github.topi314.lavasearch:lavasearch-plugin:x.y.z"
      repository: "https://maven.lavalink.dev/releases" # this is optional for lavalink v4.0.0-beta.5 or greater
      snapshot: false # set to true if you want to use snapshot builds (see below)

Snapshot builds are available in https://maven.lavalink.dev/snapshots with the short commit hash as the version

API

LavaSearch adds a new endpoint to Lavalink, GET /v4/loadsearch. This endpoint is used to search for tracks, albums, artists, playlists & text.

The endpoint accepts the following query parameters:

Parameter Type Description
query string The search query
types string The types to search for, can be one or more of track, album, artist, playlist or text

The endpoint returns a search result JSON object

Search Result Object

Note

The tracks field of playlists are always empty

Field Type Description
tracks array of Track objects An array of tracks, only present if track is in types
albums array of Playlist objects An array of albums, only present if album is in types
artists array of Playlist objects An array of artists, only present if artist is in types
playlists array of Playlist objects An array of playlists, only present if playlist is in types
texts array of Text objects An array of text results, only present if text is in types
plugin object Addition result data provided by plugins
Example Payload
{
  "tracks": [
    {
      "encoded": "QAAB/gMAB0FuaW1hbHMACkFyY2hpdGVjdHMAAAAAAAO5IAAKMTA5MDUzODA4MgABACNodHRwczovL2RlZXplci5jb20vdHJhY2svMTA5MDUzODA4MgEAAAAAAAAAAAA==",
      "info": {
        "identifier": "1090538082",
        "isSeekable": true,
        "author": "Architects",
        "length": 244000,
        "isStream": false,
        "position": 0,
        "title": "Animals",
        "uri": "https://deezer.com/track/1090538082",
        "sourceName": "deezer",
        "artworkUrl": "https://e-cdns-images.dzcdn.net/images/cover/f63fc26eda9ed39f84c1a533e2716f46/1000x1000-000000-80-0-0.jpg",
        "isrc": null
      },
      "pluginInfo": {}
    }
  ],
  "albums": [
    {
      "info": {
        "name": "For Those That Wish To Exist",
        "selectedTrack": -1
      },
      "pluginInfo": {},
      "tracks": []
    }
  ],
  "artists": [
    {
      "info": {
        "name": "Architects's Top Tracks",
        "selectedTrack": -1
      },
      "pluginInfo": {},
      "tracks": []
    }
  ],
  "playlists": [
    {
      "info": {
        "name": "100% Architects",
        "selectedTrack": -1
      },
      "pluginInfo": {},
      "tracks": []
    }
  ],
  "texts": [
    {
      "text": "Architects",
      "plugin": {}
    }
  ],
  "plugin": {}
}

If no results are found the endpoint returns a http status code of 204 No Content

Text Object

Field Type Description
text string The title of the text result
plugin object Addition result data provided by plugins