roadie/Roadie.Api.Library/Utility/M3uHelper.cs
2018-12-26 13:39:13 -06:00

32 lines
971 B
C#

using Roadie.Library.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace Roadie.Library.Utility
{
/// <summary>
/// Helper to work with M3U files
/// <seealso cref="https://en.wikipedia.org/wiki/M3U"/>
/// </summary>
public static class M3uHelper
{
/// <summary>
/// For the given collection of tracks generate a M3U file in a single string
/// </summary>
public static string M3uContentForTracks(IEnumerable<TrackList> tracks)
{
var result = new List<string>
{
"#EXTM3U"
};
foreach (var track in tracks)
{
result.Add($"#EXTINF:{ track.Duration },{ track.Artist.Artist.Text} - { track.Track.Text }");
result.Add($"{ track.TrackPlayUrl }");
result.Add(string.Empty);
}
return string.Join("\r\n", result);
}
}
}