mirror of
https://github.com/sphildreth/roadie
synced 2024-11-25 21:50:22 +00:00
31 lines
No EOL
944 B
C#
31 lines
No EOL
944 B
C#
using Roadie.Library.Models;
|
|
using System.Collections.Generic;
|
|
|
|
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);
|
|
}
|
|
}
|
|
} |