Skip to content

Search on YouTube and/or SoundCloud for tracks and get their metadata

License

Notifications You must be signed in to change notification settings

s-frei/TrackSearch

Repository files navigation

TrackSearch


Contributions welcome License GitHub release (latest by date) Maven Central release
Functionality Test State Latest

What is it ?

TrackSearch is for searching track metadata on different sources, like YouTube and SoundCloud for now.

Note: TrackSearch isn't using any API-Key, it uses the public API (like your browser).

Supported sources

Since TrackSearch focuses on searching for music (although YouTube offers more than music) I decided to add following providers for now:

youtube soundcloud

There could be more added if there are interesting sources to go for.

Current features 🔎

  • search
  • paging
  • multiple clients asynchronous
  • metadata like: duration, channel, views, thumbnail, ...

Stream

With release 1.0.0 the capability of getting all available audio formats and the actual stream URL was removed, as it takes too much effort to maintain it and there are other huge projects that offer that with a large community like yt-dlp.

To get the stripped functionality back use e.g.:

yt-dlp -J <url> | jq '.formats | map(select(.vcodec == "none"))'

I decided against implementing a simple wrapper to bring back the stripped functionalities as usage will differ from user to user.

How to use it ? 📚

Dependency

TrackSearch is available on Maven Central:

<dependency>
    <groupId>io.sfrei</groupId>
    <artifactId>tracksearch</artifactId>
    <version>1.0.0</version>
</dependency>
implementation("io.sfrei:tracksearch:1.0.0")

on GitHub Packages or directly from GitHub Releases.

Getting started

// Client to search on all available sources asynchronous
MultiTrackSearchClient searchClient = new MultiSearchClient();

// Client for explicit source
TrackSearchClient<SoundCloudTrack> explicitClient = new SoundCloudClient();

try {
    TrackList<Track> tracksForSearch = searchClient.getTracksForSearch("<your keywords>");
    Track track = tracksForSearch.get(0);

    final String url = track.getUrl();
    final String title = track.getTitle();
    final Duration duration = track.getDuration();

    final TrackMetadata trackMetadata = track.getTrackMetadata();
    final String channelName = trackMetadata.channelName();
    final String channelUrl = trackMetadata.channelUrl();
    final String thumbNailUrl = trackMetadata.thumbNailUrl();
    final Long streamAmount = trackMetadata.streamAmount();

    // Get next tracks page
    TrackList<Track> nextTracks = tracksForSearch.next();

    // Get a track for URL
    SoundCloudTrack trackForUrl = explicitClient.getTrack("<soundcloud-url>");

} catch (TrackSearchException e) {
    // Damn
}

For more information check the related interface documentation or have a look into the tests.

Why is this done ?

I haven't found anything which is capable of doing this kind of stuff, except it offered something similar and could be abused for this, or it wasn't written in Java.

Develop 🔨

Note: JDK 17 is required! (sdk env install)

Fire up following in your shell:

Build

$ ./mvnw clean install

Test

The simple test runs daily to get notified when something is not working. Test it on your own:

$ ./mvnw test

For detailed test (about ~250 tracks for each client):

$ ./mvnw test -P detailed-client-test

Contributing 🤝

Feel free to contribute! - How?