Exemple #1
0
        static bool ConvertFile(string path)
        {
            bool fileExists = File.Exists(path);

            if (fileExists == false)
            {
                Console.WriteLine($"File \"{path}\" does not exist");
                return(false);
            }

            using (StreamReader file = File.OpenText(path))
            {
                try
                {
                    var legacy   = PlaylistConverter.DeserializeLegacyPlaylist(file);
                    var playlist = PlaylistConverter.ConvertLegacyPlaylist(legacy);

                    string newPath = path.Replace(".bplist", ".blist").Replace(".json", ".blist");
                    using (FileStream fs = File.Open(newPath, FileMode.OpenOrCreate))
                    {
                        PlaylistLib.SerializeStream(playlist, fs);
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Exception in {path}");
                    Console.WriteLine(ex.ToString());
                    return(false);
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                ExitMessage("Please drag a .bplist file onto this .exe", 1);
            }

            string path       = args[0];
            bool   fileExists = File.Exists(path);

            if (!fileExists)
            {
                ExitMessage("The specified file does not exist!", 1);
            }

            string text     = File.ReadAllText(path);
            var    legacy   = PlaylistConverter.DeserializeLegacyPlaylist(text);
            var    playlist = PlaylistConverter.ConvertLegacyPlaylist(legacy);

            string newPath = path.Replace(".bplist", ".blist");

            using (FileStream fs = File.Open(newPath, FileMode.OpenOrCreate))
            {
                using (MemoryStream ms = PlaylistLib.SerializeStream(playlist))
                {
                    ms.CopyTo(fs);
                    fs.Flush();
                }
            }
        }
        public async Task <PlaylistDto> CreateAsync(PlaylistDto item)
        {
            var result = _context.Playlists.Add(PlaylistConverter.Convert(item));
            await _context.SaveChangesAsync();

            return(PlaylistConverter.Convert(result.Entity));
        }
Exemple #4
0
        public async Task <List <PlaylistViewModel> > GetAllPlaylistAsync(
            CancellationToken ct = default(CancellationToken))
        {
            var playlists = PlaylistConverter.ConvertList(await _playlistRepository.GetAllAsync(ct));

            return(playlists);
        }
Exemple #5
0
        public async Task <PlaylistViewModel> GetPlaylistByIdAsync(int id,
                                                                   CancellationToken ct = default(CancellationToken))
        {
            var playlistViewModel = PlaylistConverter.Convert(await _playlistRepository.GetByIdAsync(id, ct));

            playlistViewModel.Tracks = await GetTrackByPlaylistIdIdAsync(playlistViewModel.PlaylistId, ct);

            return(playlistViewModel);
        }
        public async Task <bool> UpdateAsync(PlaylistDto item)
        {
            if (item == null)
            {
                return(false);
            }
            _context.Playlists.Update(PlaylistConverter.Convert(item));
            await _context.SaveChangesAsync();

            return(true);
        }
Exemple #7
0
        public static Playlist AddLegacyPlaylist(string file)
        {
            using (StreamReader reader = File.OpenText(file))
            {
                var leg       = PlaylistConverter.DeserializeLegacyPlaylist(reader);
                var converted = PlaylistConverter.ConvertLegacyPlaylist(leg);

                AddPlaylistToLC(converted);
                return(converted);
            }
        }
        private void Generate(string name)
        {
            //PlaylistInfo
            var item = project.LibraryGroups[0].Playlists.GetByName(name);

            //Serialiser object
            Serialiser <PlaylistType> _ser = Serialiser <PlaylistType> .Xml;

            //Playlist Converter
            PlaylistConverter converter = new PlaylistConverter();

            //UFE Playlist
            PlaylistType ufeItem = converter.Convert(item);

            //Serialize playlist
            _ser.Serialize(ufeItem, LocalFilePathMapping.GetFile(FileType.Playlist, ufeItem.Id));
        }
        private void PlaylistSelectBtn_Click(object sender, RoutedEventArgs e)
        {
            //Open new window
            //Catch all .pll files and display them
            //Return Playlist

            PlaylistConverter PC = new PlaylistConverter();

            OpenFileDialog ofd = new OpenFileDialog
            {
                Filter           = "Playlist files | *.pll",
                InitialDirectory = Path.Combine(Environment.CurrentDirectory, "jsonFiles")
            };

            if (ofd.ShowDialog() == true)
            {
                MainWindow.CurrentPlaylist = PC.GetPllFromFile(ofd.FileName);
                Playlist.ItemsSource       = PC.GetPllFromFile(ofd.FileName).Songs;

                SongFileRightBtn.Text = MainWindow.CurrentPlaylist.PlaylistName;
            }
        }
        public async Task <PlaylistDto> GetByIdAsync(Guid id)
        {
            var playlist = PlaylistConverter.Convert(await _context.Playlists.FindAsync(id));

            return(playlist);
        }
 public async Task <List <PlaylistDto> > GetAllAsync()
 {
     return(PlaylistConverter.Convert(await _context.Playlists.ToListAsync()));
 }
Exemple #12
0
        public static Dictionary <string, Playlist> LoadAllPlaylistsFromFolders(string[] paths)
        {
            if (!isLoading)
            {
                isLoading = true;
                Logger.log.Info("LOADER ::: Loading playlists.");
                Stopwatch sw = new Stopwatch();
                sw.Start();
                Dictionary <string, Playlist> playlists = new Dictionary <string, Playlist>();

                foreach (var path in paths)
                {
                    Directory.CreateDirectory(path);
                    string[] filePaths = Directory.GetFiles(path, "*.blist", SearchOption.AllDirectories);

                    foreach (var fPath in filePaths)
                    {
                        try
                        {
                            using (FileStream fs = new FileStream(fPath, FileMode.Open, FileAccess.Read))
                            {
                                Playlist plist = PlaylistLib.Deserialize(fs);

                                playlists.Add(fPath, plist);
                                if (!AllPlaylists.ContainsKey(fPath))
                                {
                                    AllPlaylists.Add(fPath, plist);
                                }
                            }
                        }
                        catch
                        {
                            Logger.log.Error("Error loading playlist at: " + fPath);
                        }
                    }

                    //Legacy Conversion (bplist)
                    var legacyPathsBP = Directory.GetFiles(path, "*.bplist", SearchOption.AllDirectories);
                    foreach (var filePath in legacyPathsBP)
                    {
                        try
                        {
                            using (StreamReader reader = File.OpenText(filePath))
                            {
                                var leg       = PlaylistConverter.DeserializeLegacyPlaylist(reader);
                                var converted = PlaylistConverter.ConvertLegacyPlaylist(leg);

                                /*
                                 * var fileName = Path.GetFileNameWithoutExtension(filePath);
                                 * var newFilePath = path + fileName + "_CFB.blist";
                                 * OverwritePlaylist(filePath, converted);
                                 * playlists.Add(newFilePath, converted);
                                 * if (!AllPlaylists.ContainsKey(newFilePath))
                                 *  AllPlaylists.Add(newFilePath, converted);
                                 * File.Move(filePath, newFilePath);
                                 */
                                if (!AllPlaylists.ContainsKey(filePath))
                                {
                                    AllPlaylists.Add(filePath, converted);
                                }
                                playlists.Add(filePath, converted);
                                Logger.log.Debug("Converted Playlist " + converted.Title);
                            }
                        }
                        catch (Exception e)
                        {
                            string st = "";
                            if (e.GetType() == typeof(InvalidBase64Exception))
                            {
                                st += "Invalid Image: " + e.Message;
                            }
                            else if (e.GetType() == typeof(InvalidMapHashException))
                            {
                                st += "Invalid Hash <<<" + (e as InvalidMapHashException).Hash + ">>>";
                            }
                            else if (e.GetType() == typeof(InvalidMapKeyException))
                            {
                                st += "Invalid Key <<<" + (e as InvalidMapKeyException).Key + ">>>";
                            }
                            else
                            {
                                st += "Other: " + e.Message;
                            }
                            Logger.log.Error("Error converting playlist: " + Path.GetFileName(filePath) + ". Why? " + st);
                        }
                    }

                    //Legacy Conversion (json)
                    var legacyPathsJSON = Directory.GetFiles(path, "*.json", SearchOption.AllDirectories);
                    foreach (var filePath in legacyPathsJSON)
                    {
                        if (!filePath.Contains("SongBrowserPluginFavorites") && !filePath.Contains("favorites.json"))
                        {
                            try
                            {
                                using (StreamReader reader = File.OpenText(filePath))
                                {
                                    var leg       = PlaylistConverter.DeserializeLegacyPlaylist(reader);
                                    var converted = PlaylistConverter.ConvertLegacyPlaylist(leg);

                                    /*
                                     * var fileName = Path.GetFileNameWithoutExtension(filePath);
                                     * var newFilePath = path + fileName + "_CFB.blist";
                                     * OverwritePlaylist(filePath, converted);
                                     * playlists.Add(newFilePath, converted);
                                     * if (!AllPlaylists.ContainsKey(newFilePath))
                                     *  AllPlaylists.Add(newFilePath, converted);
                                     * File.Move(filePath, newFilePath);
                                     */
                                    if (!AllPlaylists.ContainsKey(filePath))
                                    {
                                        AllPlaylists.Add(filePath, converted);
                                    }
                                    playlists.Add(filePath, converted);
                                    Logger.log.Debug("Converted Playlist " + converted.Title);
                                }
                            }
                            catch (Exception e)
                            {
                                string st = "";
                                if (e.GetType() == typeof(InvalidBase64Exception))
                                {
                                    st += "Invalid Image: " + e.Message;
                                }
                                else if (e.GetType() == typeof(InvalidMapHashException))
                                {
                                    st += "Invalid Hash <<<" + (e as InvalidMapHashException).Hash + ">>>";
                                }
                                else if (e.GetType() == typeof(InvalidMapKeyException))
                                {
                                    st += "Invalid Key <<<" + (e as InvalidMapKeyException).Key + ">>>";
                                }
                                else
                                {
                                    st += "Other: " + e.Message;
                                }
                                Logger.log.Error("Error converting playlist: " + Path.GetFileName(filePath) + ". Why? " + st);
                            }
                        }
                    }
                }

                foreach (var pl in playlists)
                {
                    var n = ScriptableObject.CreateInstance <CustomPlaylistSO>();
                    n.playlist = pl.Value;
                    n.SetupCover();
                    PlaylistCore.instance.LoadedPlaylistSO.Add(n);
                }

                PlaylistsLoaded?.Invoke(playlists);
                Logger.log.Info("LOADER ::: Finished loading " + playlists.Count + " playlists. Took: " + sw.Elapsed.Seconds + "." + sw.Elapsed.Milliseconds / 10 + " seconds.");
                isLoading = false;
                return(playlists);
            }
            else
            {
                return(null);
            }
        }