Skip to content

Commit

Permalink
Playlists : Write track metadata to playlist files even when defining…
Browse files Browse the repository at this point in the history
… files with their Path only [#307]
  • Loading branch information
Zeugma440 committed Jan 28, 2025
1 parent 85d120c commit 984e56d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ATL.unit-test/Playlist/B4SIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void PLIO_W_B4S()
IList<string> filePaths = pls.FilePaths;
Assert.AreEqual(pathsToWrite.Count, filePaths.Count);
for (int i = 0; i < pathsToWrite.Count; i++) Assert.IsTrue(filePaths[i].EndsWith(pathsToWrite[i]));

if (Settings.DeleteAfterSuccess) File.Delete(testFileLocation);


Expand Down
27 changes: 20 additions & 7 deletions ATL.unit-test/Playlist/DPLIO.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ATL.Playlist;
using System.Xml;

namespace ATL.test.IO.Playlist
{
Expand All @@ -26,6 +25,13 @@ public void PLIO_W_DPL()
pls.FilePaths = pathsToWrite;
pls.Save();

double totalDuration = 0;
for (int i = 0; i < pathsToWrite.Count; i++)
{
var t = new Track(pathsToWrite[i]);
totalDuration += t.DurationMs;
}

using (FileStream fs = new FileStream(testFileLocation, FileMode.Open))
{
// Test if the default UTF-8 BOM has been written at the beginning of the file
Expand All @@ -39,8 +45,15 @@ public void PLIO_W_DPL()
Assert.AreEqual("DAUMPLAYLIST", sr.ReadLine());
Assert.AreEqual("topindex=0", sr.ReadLine());
Assert.AreEqual("saveplaypos=0", sr.ReadLine());
Assert.AreEqual("playtime=0", sr.ReadLine());
for (int i = 0; i < pathsToWrite.Count; i++) Assert.AreEqual(i + 1 + "*file*" + pathsToWrite[i], sr.ReadLine());
Assert.AreEqual("playtime=" + (long)totalDuration, sr.ReadLine());
for (int i = 0; i < pathsToWrite.Count; i++)
{
var t = new Track(pathsToWrite[i]);
Assert.AreEqual(i + 1 + "*file*" + pathsToWrite[i], sr.ReadLine());
Assert.AreEqual(i + 1 + "*title*" + t.Title, sr.ReadLine());
if (t.DurationMs > 0)
Assert.AreEqual(i + 1 + "*duration2*" + (long)t.DurationMs, sr.ReadLine());
}
Assert.IsTrue(sr.EndOfStream);
}
}
Expand Down Expand Up @@ -94,7 +107,7 @@ public void PLIO_W_DPL()
}

[TestMethod]
public void PLIO_PLIO_RW_Absolute_Relative_Path_ASX()
public void PLIO_PLIO_RW_Absolute_Relative_Path_DPL()
{
var testFileLocation = PLIO_RW_Absolute_Relative_Path("dpl");
try
Expand All @@ -108,7 +121,7 @@ public void PLIO_PLIO_RW_Absolute_Relative_Path_ASX()
sr.ReadLine();
sr.ReadLine();
sr.ReadLine();
for (int i = 0; i < 3; i++)
for (int i = 0; i < 4; i++)
{
string path;
switch (nbEntries)
Expand All @@ -135,10 +148,10 @@ public void PLIO_PLIO_RW_Absolute_Relative_Path_ASX()
sr.ReadLine(); // Duration
nbEntries++;
}
sr.ReadLine();
var hop = sr.ReadLine();
Assert.IsTrue(sr.EndOfStream);
}
Assert.AreEqual(4, nbEntries);
Assert.AreEqual(4, nbEntries - 1);
}
finally
{
Expand Down
4 changes: 3 additions & 1 deletion ATL.unit-test/Playlist/M3UIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ public void PLIO_W_M3U_Extended()
Assert.AreEqual("#EXTM3U", sr.ReadLine());
foreach (string s in pathsToWrite)
{
Assert.AreEqual("#EXTINF:-1," + Path.GetFileNameWithoutExtension(s), sr.ReadLine());
var t = new Track(s);
var duration = (t.Duration > 0) ? t.Duration : -1;
Assert.AreEqual("#EXTINF:" + duration + "," + t.Title, sr.ReadLine());
Assert.AreEqual(s, sr.ReadLine());
}
Assert.IsTrue(sr.EndOfStream);
Expand Down
6 changes: 4 additions & 2 deletions ATL.unit-test/Playlist/PLSIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ public void PLIO_W_PLS()
int counter = 1;
foreach (string s in pathsToWrite)
{
var t = new Track(s);
var duration = (t.Duration > 0) ? t.Duration : -1;
Assert.AreEqual("File" + counter + "=" + s, sr.ReadLine());
Assert.AreEqual("Title" + counter + "=" + System.IO.Path.GetFileNameWithoutExtension(s), sr.ReadLine());
Assert.AreEqual("Length" + counter + "=-1", sr.ReadLine());
Assert.AreEqual("Title" + counter + "=" + t.Title, sr.ReadLine());
Assert.AreEqual("Length" + counter + "=" + duration, sr.ReadLine());
sr.ReadLine();
counter++;
}
Expand Down
2 changes: 1 addition & 1 deletion ATL.unit-test/Playlist/PlaylistIOTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void PLIO_R(string fileName, IList<KeyValuePair<string, string>> pathRepl
}
}

public string PLIO_RW_Absolute_Relative_Path(string extension)
public static string PLIO_RW_Absolute_Relative_Path(string extension)
{
// == RESOURCE PREPARATION
// Create new playlist file on temp folder
Expand Down
2 changes: 1 addition & 1 deletion ATL/Playlist/PlaylistIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public bool Save()
}
else
{
trackList.Add(new Track(path, false));
trackList.Add(new Track(path));
}
}
save(fs, trackList);
Expand Down

0 comments on commit 984e56d

Please sign in to comment.