Added conversion of usdx-playlists. Just copy *.upl files to playlist-folder. *.upl-Files will be removed after conversion!

This commit is contained in:
Florian Kuepper committed 2012-12-21 21:43:18 +01:00
1 parent 7f4a657aa4
commit 503037f10b
1 file changed
+78 -2
+78 -2
View File
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.XPath;
@@ -44,6 +45,22 @@ namespace Vocaluxe.Base
public static void Init()
{
LoadPlaylists();
ConvertUSDXPlaylists();
SortPlaylistsByName();
}
public static void ConvertUSDXPlaylists()
{
List<string> files = new List<string>();
files.AddRange(Helper.ListFiles(CSettings.sFolderPlaylists, "*.upl", true, true));
foreach (string file in files)
{
CPlaylistFile playlist = ConvertUSDXPlaylist(file);
_Playlists.Add(playlist);
SavePlaylist(_Playlists.Count - 1);
}
}
public static void LoadPlaylists()
@@ -57,8 +74,6 @@ namespace Vocaluxe.Base
CPlaylistFile playlist = new CPlaylistFile(file);
_Playlists.Add(playlist);
}
SortPlaylistsByName();
}
public static string GetPlaylistName(int PlaylistID)
@@ -197,6 +212,67 @@ namespace Vocaluxe.Base
{
return String.Compare(a.PlaylistName, b.PlaylistName);
}
private static CPlaylistFile ConvertUSDXPlaylist(string file)
{
CPlaylistFile pl = new CPlaylistFile();
CSong[] AllSongs = CSongs.AllSongs;
if (!File.Exists(file))
return null;
StreamReader sr;
try
{
sr = new StreamReader(file, Encoding.Default, true);
int pos = -1;
string line;
while((line = sr.ReadLine()) != null)
{
pos = line.IndexOf(":");
if (pos > 0)
{
//Name or comment
if (line[0] == '#')
{
string Identifier = line.Substring(1, pos - 1).Trim();
string Value = line.Substring(pos + 1, line.Length - pos - 1).Trim();
if (Identifier.ToUpper() == "NAME")
{
pl.PlaylistName = Value;
}
}
//Song
else
{
string Artist = line.Substring(0, pos - 1).Trim();
string Title = line.Substring(pos + 1, line.Length - pos - 1).Trim();
bool found = false;
for (int s = 0; s < AllSongs.Length; s++)
{
if (AllSongs[s].Artist == Artist && AllSongs[s].Title == Title)
{
pl.AddSong(AllSongs[s].ID);
found = true;
break;
}
}
if (!found)
CLog.LogError("Can't find song '" + Title + "' from '" + Artist + "' in playlist file: " + file);
}
}
}
sr.Close();
File.Delete(file);
}
catch
{
return null;
}
return pl;
}
#endregion
}
}