Skip to content

TrevTV/TidalSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TidalSharp

A .NET Tidal (partial) API wrapper and track downloading library.

Dependencies

  • Newtonsoft.Json for every API call
  • TagLibSharp for applying metadata to decrypted track data (client.Downloader.ApplyMetadataToTrackBytes())

Overview

TidalSharp is built around a core class, TidalClient. That class itself does very little, under it is Downloader and API.

  • Downloader provides functions for downloading tracks by their ID, as well as applying metadata. It requires you to be signed in.
  • API is an (incomplete) wrapper for the backend API used by Tidal. It requires you to be signed in.

All API calls return a Newtonsoft.JSON JObject as I did not want to deal with parsing everything into model classes since there are many different API endpoints.

In addition to TidalClient, there is TidalURL which is a class for parsing Tidal URLs into their entity type and ID.

Examples

Logging in

// a config dir isn't required, but allows persistence
string dataDir = Path.Combine(Directory.GetCurrentDirectory(), "TidalSharpData");

var client = new TidalClient(dataDir: dataDir);
Console.WriteLine($"Current logged in state (should be False): " + await client.IsLoggedIn());

bool hasExistingLogin = await client.Login();

if (!hasExistingLogin)
{
    Console.WriteLine("No existing user data.");

    var url = client.GetPkceLoginUrl();
    Console.WriteLine(url);

    Console.WriteLine("Enter resulting url: ");
    var resultUrl = Console.ReadLine()!;

    await client.Login(resultUrl);
}

Console.WriteLine("Should be logged in, ensuring...");

bool loggedIn = await client.IsLoggedIn();
if (!loggedIn)
    Console.WriteLine("Failed to login.");
else
    Console.WriteLine("Successful.");

Downloading an Album by URL

var client = new TidalClient();
await client.Login();
var urlData = TidalURL.Parse("https://listen.tidal.com/album/345739416");
var tracksInAlbum = await urlData.GetAssociatedTracks(client);

foreach (var track in tracksInAlbum)
{
    var trackData = await client.Downloader.GetRawTrackBytes(track, TidalSharp.Data.AudioQuality.LOSSLESS);
    await client.Downloader.ApplyMetadataToTrackBytes(track, trackData); // if you want metadata
    File.WriteAllBytes(Path.Combine(Environment.CurrentDirectory, $"{track}{trackData.FileExtension}"), trackData.Data);
}
// Saves metadata-applied M4As of every track in GLOOM DIVISION by I DONT KNOW HOW BUT THEY FOUND ME to your current working directory

Credits

About

A .NET Tidal API wrapper and track downloading library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages