Skip to content

Commit

Permalink
HTTP(S) resources (online streams) support for playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeugma440 committed Nov 23, 2022
1 parent 68a54b8 commit 0f83075
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 141 deletions.
29 changes: 14 additions & 15 deletions ATL.test/Playlist/ASXIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ public void PLIO_R_ASX()
{
var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation);
var filePaths = theReader.FilePaths;
var tracks = theReader.Tracks;

Assert.IsNotInstanceOfType(theReader, typeof(ATL.Playlist.IO.DummyIO));
Assert.AreEqual(4, filePaths.Count);
foreach (var s in filePaths)
Assert.AreEqual(5, filePaths.Count);
foreach (string s in theReader.FilePaths)
{
Assert.IsTrue(System.IO.File.Exists(s));
if (!s.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) Assert.IsTrue(System.IO.File.Exists(s));
}

foreach (var t in tracks)
foreach (Track t in theReader.Tracks)
{
Assert.IsTrue(t.Duration > 0);
// Ensure the track has been parsed when it points to a file
if (!t.Path.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) Assert.IsTrue(t.Duration > 0);
}
}
finally
Expand All @@ -45,10 +44,12 @@ public void PLIO_W_ASX()
IList<string> pathsToWrite = new List<string>();
pathsToWrite.Add(TestUtils.GetResourceLocationRoot() + "aaa.mp3");
pathsToWrite.Add(TestUtils.GetResourceLocationRoot() + "bbb.mp3");
pathsToWrite.Add("http://this-is-a-stre.am:8405/live");

IList<Track> tracksToWrite = new List<Track>();
tracksToWrite.Add(new Track(Path.Combine(TestUtils.GetResourceLocationRoot() + "MP3","empty.mp3")));
tracksToWrite.Add(new Track(Path.Combine(TestUtils.GetResourceLocationRoot() + "MOD","mod.mod")));
tracksToWrite.Add(new Track("http://this-is-a-stre.am:8405/live"));


string testFileLocation = TestUtils.CreateTempTestFile("test.asx");
Expand Down Expand Up @@ -88,12 +89,11 @@ public void PLIO_W_ASX()
}
}

Assert.AreEqual(3, parents.Count);
Assert.AreEqual(4, parents.Count);

IList<string> filePaths = pls.FilePaths;
Assert.AreEqual(2, filePaths.Count);
Assert.AreEqual(pathsToWrite[0], filePaths[0]);
Assert.AreEqual(pathsToWrite[1], filePaths[1]);
Assert.AreEqual(pathsToWrite.Count, filePaths.Count);
for (int i = 0; i < pathsToWrite.Count; i++) Assert.IsTrue(filePaths[i].EndsWith(pathsToWrite[i]));


// Test Track writing
Expand Down Expand Up @@ -123,12 +123,11 @@ public void PLIO_W_ASX()
}
}
}
Assert.AreEqual(3, parents.Count);
Assert.AreEqual(4, parents.Count);

IList<Track> tracks = pls.Tracks;
Assert.AreEqual(2, tracks.Count);
Assert.AreEqual(tracksToWrite[0].Path, tracks[0].Path);
Assert.AreEqual(tracksToWrite[1].Path, tracks[1].Path);
Assert.AreEqual(tracksToWrite.Count, tracks.Count);
for (int i = 0; i < tracksToWrite.Count; i++) Assert.AreEqual(tracksToWrite[i].Path, tracks[i].Path);
}
finally
{
Expand Down
31 changes: 19 additions & 12 deletions ATL.test/Playlist/B4SIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ public void PLIO_R_B4S()
{
var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation);
var filePaths = theReader.FilePaths;
var tracks = theReader.Tracks;
Assert.IsNotInstanceOfType(theReader, typeof(ATL.Playlist.IO.DummyIO));
Assert.AreEqual(3, filePaths.Count);
foreach (var s in filePaths) Assert.IsTrue(System.IO.File.Exists(s));
foreach (var t in tracks) Assert.IsTrue(t.Duration > 0);
Assert.AreEqual(4, filePaths.Count);
foreach (string s in theReader.FilePaths)
{
if (!s.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) Assert.IsTrue(System.IO.File.Exists(s));
}
foreach (Track t in theReader.Tracks)
{
// Ensure the track has been parsed when it points to a file
if (!t.Path.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) Assert.IsTrue(t.Duration > 0);
}
}
finally
{
Expand All @@ -37,10 +43,12 @@ public void PLIO_W_B4S()
IList<string> pathsToWrite = new List<string>();
pathsToWrite.Add("aaa.mp3");
pathsToWrite.Add("bbb.mp3");
pathsToWrite.Add("http://this-is-a-stre.am:8405/live");

IList<Track> tracksToWrite = new List<Track>();
tracksToWrite.Add(new Track(Path.Combine(TestUtils.GetResourceLocationRoot() + "MP3","empty.mp3")));
tracksToWrite.Add(new Track(Path.Combine(TestUtils.GetResourceLocationRoot() + "MOD","mod.mod")));
tracksToWrite.Add(new Track("http://this-is-a-stre.am:8405/live"));


string testFileLocation = TestUtils.CreateTempTestFile("test.b4s");
Expand Down Expand Up @@ -80,12 +88,12 @@ public void PLIO_W_B4S()
}
}

Assert.AreEqual(4, parents.Count);
Assert.AreEqual(5, parents.Count);

IList<string> filePaths = pls.FilePaths;
Assert.AreEqual(2, filePaths.Count);
Assert.IsTrue(filePaths[0].EndsWith(pathsToWrite[0]));
Assert.IsTrue(filePaths[1].EndsWith(pathsToWrite[1]));
Assert.AreEqual(pathsToWrite.Count, filePaths.Count);
for (int i = 0; i < pathsToWrite.Count; i++) Assert.IsTrue(filePaths[i].EndsWith(pathsToWrite[i]));


// Test Track writing
pls.Tracks = tracksToWrite;
Expand Down Expand Up @@ -115,12 +123,11 @@ public void PLIO_W_B4S()
}
}
}
Assert.AreEqual(4, parents.Count);
Assert.AreEqual(5, parents.Count);

IList<Track> tracks = pls.Tracks;
Assert.AreEqual(2, tracks.Count);
Assert.AreEqual(tracksToWrite[0].Path, tracks[0].Path);
Assert.AreEqual(tracksToWrite[1].Path, tracks[1].Path);
Assert.AreEqual(tracksToWrite.Count, tracks.Count);
for (int i = 0; i < tracksToWrite.Count; i++) Assert.AreEqual(tracksToWrite[i].Path, tracks[i].Path);
}
finally
{
Expand Down
36 changes: 22 additions & 14 deletions ATL.test/Playlist/DPLIO.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ATL.Playlist;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;

Expand All @@ -15,12 +16,19 @@ public void PLIO_R_DPL()

try
{
IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation);
IPlaylistIO theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation);

Assert.IsNotInstanceOfType(pls, typeof(ATL.Playlist.IO.DummyIO));
Assert.AreEqual(4, pls.FilePaths.Count);
foreach (string s in pls.FilePaths) Assert.IsTrue(File.Exists(s));
foreach (Track t in pls.Tracks) Assert.IsTrue(t.Duration > 0); // Ensures the track has been parsed
Assert.IsNotInstanceOfType(theReader, typeof(ATL.Playlist.IO.DummyIO));
Assert.AreEqual(5, theReader.FilePaths.Count);
foreach (string s in theReader.FilePaths)
{
if (!s.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) Assert.IsTrue(System.IO.File.Exists(s));
}
foreach (Track t in theReader.Tracks)
{
// Ensure the track has been parsed when it points to a file
if (!t.Path.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) Assert.IsTrue(t.Duration > 0);
}
}
finally
{
Expand All @@ -34,10 +42,12 @@ public void PLIO_W_DPL()
IList<string> pathsToWrite = new List<string>();
pathsToWrite.Add("aaa.mp3");
pathsToWrite.Add("bbb.mp3");
pathsToWrite.Add("http://this-is-a-stre.am:8405/live");

IList<Track> tracksToWrite = new List<Track>();
tracksToWrite.Add(new Track(Path.Combine(TestUtils.GetResourceLocationRoot() + "MP3", "empty.mp3")));
tracksToWrite.Add(new Track(Path.Combine(TestUtils.GetResourceLocationRoot() + "MOD", "mod.mod")));
tracksToWrite.Add(new Track("http://this-is-a-stre.am:8405/live"));


string testFileLocation = TestUtils.CreateTempTestFile("test.dpl");
Expand All @@ -62,15 +72,13 @@ public void PLIO_W_DPL()
Assert.AreEqual("topindex=0", sr.ReadLine());
Assert.AreEqual("saveplaypos=0", sr.ReadLine());
Assert.AreEqual("playtime=0", sr.ReadLine());
Assert.AreEqual("1*file*aaa.mp3", sr.ReadLine());
Assert.AreEqual("2*file*bbb.mp3", sr.ReadLine());
for (int i = 0; i < pathsToWrite.Count; i++) Assert.AreEqual(i + 1 + "*file*" + pathsToWrite[i], sr.ReadLine());
Assert.IsTrue(sr.EndOfStream);
}
}
IList<string> filePaths = pls.FilePaths;
Assert.AreEqual(2, filePaths.Count);
Assert.IsTrue(filePaths[0].EndsWith(pathsToWrite[0]));
Assert.IsTrue(filePaths[1].EndsWith(pathsToWrite[1]));
Assert.AreEqual(pathsToWrite.Count, filePaths.Count);
for (int i = 0; i < pathsToWrite.Count; i++) Assert.IsTrue(filePaths[i].EndsWith(pathsToWrite[i]));


// Test Track writing
Expand All @@ -88,17 +96,17 @@ public void PLIO_W_DPL()
{
Assert.AreEqual(counter + "*file*" + t.Path, sr.ReadLine());
Assert.AreEqual(counter + "*title*" + t.Title, sr.ReadLine());
Assert.AreEqual(counter + "*duration2*" + (long)t.DurationMs, sr.ReadLine());
if (t.DurationMs > 0)
Assert.AreEqual(counter + "*duration2*" + (long)t.DurationMs, sr.ReadLine());
counter++;
}
sr.ReadLine();
Assert.IsTrue(sr.EndOfStream);
}

IList<Track> tracks = pls.Tracks;
Assert.AreEqual(2, tracks.Count);
Assert.AreEqual(tracksToWrite[0].Path, tracks[0].Path);
Assert.AreEqual(tracksToWrite[1].Path, tracks[1].Path);
Assert.AreEqual(tracksToWrite.Count, tracks.Count);
for (int i = 0; i < tracksToWrite.Count; i++) Assert.AreEqual(tracksToWrite[i].Path, tracks[i].Path);
}
finally
{
Expand Down
61 changes: 34 additions & 27 deletions ATL.test/Playlist/M3UIO.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ATL.Playlist;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;

Expand All @@ -12,7 +13,7 @@ public class M3UIO
public void PLIO_R_M3U()
{
var pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist_simple.m3u");

Assert.IsNotInstanceOfType(pls, typeof(ATL.Playlist.IO.DummyIO));
Assert.AreEqual(1, pls.FilePaths.Count);
foreach (var s in pls.FilePaths) Assert.IsTrue(System.IO.File.Exists(s));
Expand All @@ -21,23 +22,30 @@ public void PLIO_R_M3U()
var replacements = new List<KeyValuePair<string, string>>();
var resourceRoot = TestUtils.GetResourceLocationRoot(false);
replacements.Add(new KeyValuePair<string, string>("$PATH", resourceRoot));

// No disk path => on Windows this skips drive name, e.g. "C:" (not required on *nix)
var noDiskPath = Path.DirectorySeparatorChar != '\\'
? resourceRoot
: resourceRoot.Substring(2, resourceRoot.Length - 2);

replacements.Add(new KeyValuePair<string, string>("$NODISK_PATH", noDiskPath));

var testFileLocation = TestUtils.CopyFileAndReplace(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist_fullPath.m3u", replacements);
try
{
pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation);

Assert.IsNotInstanceOfType(pls, typeof(ATL.Playlist.IO.DummyIO));
Assert.AreEqual(3, pls.FilePaths.Count);
foreach (var s in pls.FilePaths) Assert.IsTrue(File.Exists(s));
foreach (var t in pls.Tracks) Assert.IsTrue(t.Duration > 0); // Ensures the track has been parsed
Assert.AreEqual(4, pls.FilePaths.Count);
foreach (string s in pls.FilePaths)
{
if (!s.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) Assert.IsTrue(File.Exists(s));
}
foreach (Track t in pls.Tracks)
{
// Ensure the track has been parsed when it points to a file
if (!t.Path.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) Assert.IsTrue(t.Duration > 0);
}
}
finally
{
Expand All @@ -51,6 +59,7 @@ public void PLIO_W_M3U_Simple()
IList<string> pathsToWrite = new List<string>();
pathsToWrite.Add("aaa.mp3");
pathsToWrite.Add("bbb.mp3");
pathsToWrite.Add("http://this-is-a-stre.am:8405/live");

bool defaultSetting = ATL.Settings.M3U_useExtendedFormat;

Expand All @@ -71,17 +80,14 @@ public void PLIO_W_M3U_Simple()

using (StreamReader sr = new StreamReader(fs))
{
Assert.AreEqual("aaa.mp3", sr.ReadLine());
Assert.AreEqual("bbb.mp3", sr.ReadLine());
foreach (string s in pathsToWrite) Assert.AreEqual(s, sr.ReadLine());
Assert.IsTrue(sr.EndOfStream);
}
}


IList<string> filePaths = pls.FilePaths;
Assert.AreEqual(2, filePaths.Count);
Assert.IsTrue(filePaths[0].EndsWith(pathsToWrite[0]));
Assert.IsTrue(filePaths[1].EndsWith(pathsToWrite[1]));
Assert.AreEqual(pathsToWrite.Count, filePaths.Count);
for (int i = 0; i < pathsToWrite.Count; i++) Assert.IsTrue(filePaths[i].EndsWith(pathsToWrite[i]));
}
finally
{
Expand All @@ -98,10 +104,12 @@ public void PLIO_W_M3U_Extended()
IList<string> pathsToWrite = new List<string>();
pathsToWrite.Add("aaa.mp3");
pathsToWrite.Add("bbb.mp3");
pathsToWrite.Add("http://this-is-a-stre.am:8405/live");

IList<Track> tracksToWrite = new List<Track>();
tracksToWrite.Add(new Track(Path.Combine(TestUtils.GetResourceLocationRoot() + "MP3","empty.mp3")));
tracksToWrite.Add(new Track(Path.Combine(TestUtils.GetResourceLocationRoot() + "MOD","mod.mod")));
tracksToWrite.Add(new Track(Path.Combine(TestUtils.GetResourceLocationRoot() + "MP3", "empty.mp3")));
tracksToWrite.Add(new Track(Path.Combine(TestUtils.GetResourceLocationRoot() + "MOD", "mod.mod")));
tracksToWrite.Add(new Track("http://this-is-a-stre.am:8405/live"));


string testFileLocation = TestUtils.CreateTempTestFile("test.m3u");
Expand All @@ -118,17 +126,17 @@ public void PLIO_W_M3U_Extended()
using (StreamReader sr = new StreamReader(fs))
{
Assert.AreEqual("#EXTM3U", sr.ReadLine());
Assert.AreEqual("#EXTINF:-1,aaa", sr.ReadLine());
Assert.AreEqual("aaa.mp3", sr.ReadLine());
Assert.AreEqual("#EXTINF:-1,bbb", sr.ReadLine());
Assert.AreEqual("bbb.mp3", sr.ReadLine());
foreach (string s in pathsToWrite)
{
Assert.AreEqual("#EXTINF:-1," + Path.GetFileNameWithoutExtension(s), sr.ReadLine());
Assert.AreEqual(s, sr.ReadLine());
}
Assert.IsTrue(sr.EndOfStream);
}

IList<string> filePaths = pls.FilePaths;
Assert.AreEqual(2, filePaths.Count);
Assert.IsTrue(filePaths[0].EndsWith(pathsToWrite[0]));
Assert.IsTrue(filePaths[1].EndsWith(pathsToWrite[1]));
Assert.AreEqual(pathsToWrite.Count, filePaths.Count);
for (int i = 0; i < pathsToWrite.Count; i++) Assert.IsTrue(filePaths[i].EndsWith(pathsToWrite[i]));


// Test Track writing
Expand All @@ -138,9 +146,9 @@ public void PLIO_W_M3U_Extended()
using (StreamReader sr = new StreamReader(fs))
{
Assert.AreEqual("#EXTM3U", sr.ReadLine());
foreach(Track t in tracksToWrite)
foreach (Track t in tracksToWrite)
{
string line = "#EXTINF:" + t.Duration + ",";
string line = "#EXTINF:" + ((t.Duration > 0) ? t.Duration : -1) + ",";
if (t.Artist != null && t.Artist.Length > 0) line += t.Artist + " - ";
line += t.Title;
Assert.AreEqual(line, sr.ReadLine());
Expand All @@ -150,9 +158,8 @@ public void PLIO_W_M3U_Extended()
}

IList<Track> tracks = pls.Tracks;
Assert.AreEqual(2, tracks.Count);
Assert.AreEqual(tracksToWrite[0].Path, tracks[0].Path);
Assert.AreEqual(tracksToWrite[1].Path, tracks[1].Path);
Assert.AreEqual(tracksToWrite.Count, tracks.Count);
for (int i = 0; i < tracksToWrite.Count; i++) Assert.AreEqual(tracksToWrite[i].Path, tracks[i].Path);
}
finally
{
Expand Down
Loading

0 comments on commit 0f83075

Please sign in to comment.