From 503037f10b583867421fac7c30df64105ac3ca45 Mon Sep 17 00:00:00 2001 From: Florian Kuepper Date: Fri, 21 Dec 2012 21:43:18 +0100 Subject: [PATCH] Added conversion of usdx-playlists. Just copy *.upl files to playlist-folder. *.upl-Files will be removed after conversion! --- Vocaluxe/Base/CPlaylists.cs | 80 ++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/Vocaluxe/Base/CPlaylists.cs b/Vocaluxe/Base/CPlaylists.cs index 917314e6..ef5c245e 100644 --- a/Vocaluxe/Base/CPlaylists.cs +++ b/Vocaluxe/Base/CPlaylists.cs @@ -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 files = new List(); + 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 } }