private static string GetFilePath(StringBuilder builder, TrackViewModel track, string downloadPath, FileFormat fileFormat)
{
// Change ReleaseDate format to yyyy-MM-dd (Added by Core Dream Studios)
DateTime formattedDate = track.ReleaseDate;
var formattedDateString = formattedDate.ToString("yyyy-MM-dd");
builder.Clear();
builder.Append(formattedDateString);
builder.Append(" - ");
builder.Append(track.ArtistsTitle);
builder.Append(" - ");
builder.Append(track.Title);
if (!string.IsNullOrWhiteSpace(track.Version))
{
builder.Append('(');
builder.Append(track.Version);
builder.Append(')');
}
builder.Append(GetFileExtension(fileFormat));
var fileName = builder.ToString().SanitizeAsFileName();
var archivedFolderPath = $@"{downloadPath}\{formattedDateString} - {track.CatalogId} - {track.Title}";
// Create a subfolder inside the users download path based on the year, catalog id then the artist.
if (!Directory.Exists(archivedFolderPath))
Directory.CreateDirectory(archivedFolderPath);
// Added a ability to download coverart.
// Credit to @mtreit (https://github.com/treit)
// Credit to @angius (https://github.com/Atulin)
var cover = $"https://cdx.monstercat.com/?width={3000}&encoding=jpg&url=https://www.monstercat.com/release/{track.CatalogId}/cover";
DownloadCoverArtAsync(cover, archivedFolderPath);
return Path.Combine(archivedFolderPath, fileName!);
}
private static async Task DownloadCoverArtAsync(string coverURL, string downloadPath)
{
var _client = new HttpClient();
using var stream = await _client.GetStreamAsync(coverURL);
using var fs = new FileStream($@"{downloadPath}\cover.jpg", FileMode.Create);
stream.CopyTo(fs);
}
private static string GetFilePath(StringBuilder builder, TrackViewModel track, string downloadPath, FileFormat fileFormat)
{
// Change ReleaseDate format to yyyy-MM-dd (Added by Core Dream Studios)
DateTime formattedDate = track.ReleaseDate;
var formattedDateString = formattedDate.ToString("yyyy-MM-dd");
builder.Clear();
builder.Append(formattedDateString);
builder.Append(" - ");
builder.Append(track.ArtistsTitle);
builder.Append(" - ");
builder.Append(track.Title);
if (!string.IsNullOrWhiteSpace(track.Version))
{
builder.Append('(');
builder.Append(track.Version);
builder.Append(')');
}
builder.Append(GetFileExtension(fileFormat));
var fileName = builder.ToString().SanitizeAsFileName();
var archivedFolderPath = $@"{downloadPath}\{formattedDateString} - {track.CatalogId} - {track.Title}";
// Create a subfolder inside the users download path based on the year, catalog id then the artist.
if (!Directory.Exists(archivedFolderPath))
Directory.CreateDirectory(archivedFolderPath);
// Added a ability to download coverart.
// Credit to @mtreit (https://github.com/treit)
// Credit to @angius (https://github.com/Atulin)
var cover = $"https://cdx.monstercat.com/?width={3000}&encoding=jpg&url=https://www.monstercat.com/release/{track.CatalogId}/cover";
DownloadCoverArtAsync(cover, archivedFolderPath);
return Path.Combine(archivedFolderPath, fileName!);
}
private static async Task DownloadCoverArtAsync(string coverURL, string downloadPath)
{
var _client = new HttpClient();
using var stream = await _client.GetStreamAsync(coverURL);
using var fs = new FileStream($@"{downloadPath}\cover.jpg", FileMode.Create);
stream.CopyTo(fs);
}