Пример #1
0
        private static List <WinampPlaylistItem> ReloadPlaylist()
        {
            lock (threadLock)
            {
                //Generate an updated winamp.m3u
                WinAmpController.Playlist_GenerateWinampM3U();

                //Create a new blank list
                List <WinampPlaylistItem> oWinampPlaylist = new List <WinampPlaylistItem>();

                string strLineInput = string.Empty;

                //Read Current Playlist File until EOF
                using (StreamReader oSrPlaylist = new StreamReader(Functions.ReadLocalFileToMemoryStream(AppConfiguration.configWinampPlaylistDirectory + "winamp.m3u")))
                {
                    while ((strLineInput = oSrPlaylist.ReadLine()) != null)
                    {
                        if (strLineInput.Substring(0, 7) == "#EXTINF")
                        {
                            //Extended Information Found

                            //Declare Blank Item
                            WinampPlaylistItem oItem = new WinampPlaylistItem();

                            oItem.SongID      = oWinampPlaylist.Count;
                            oItem.DisplayName = strLineInput.Substring(strLineInput.IndexOf(",") + 1);

                            //Read Next Line, which is the file name
                            strLineInput   = oSrPlaylist.ReadLine();
                            oItem.FileName = strLineInput.Substring(strLineInput.LastIndexOf("\\") + 1);
                            oItem.FilePath = strLineInput.Substring(0, strLineInput.LastIndexOf("\\") + 1);

                            //Add Item to the playlist
                            oWinampPlaylist.Add(oItem);
                        }
                        else if (strLineInput.Substring(0, 7) == "#EXTM3U")
                        {
                            //Beginning of Playlist, do nothing.
                        }
                        else
                        {
                            //Extended Information Found

                            //Declare Blank Item
                            WinampPlaylistItem oItem = new WinampPlaylistItem();
                            oItem.SongID      = oWinampPlaylist.Count;
                            oItem.DisplayName = strLineInput.Substring(strLineInput.LastIndexOf("\\") + 1);
                            oItem.FileName    = strLineInput.Substring(strLineInput.LastIndexOf("\\") + 1);
                            oItem.FilePath    = strLineInput.Substring(0, strLineInput.LastIndexOf("\\") + 1);

                            //Add Item to the playlist
                            oWinampPlaylist.Add(oItem);
                        }
                    }
                }
                return(oWinampPlaylist);
            }
        }
Пример #2
0
        /// <summary>
        ///     Processes the passed script for any script tags including Library and Playlist items
        /// </summary>
        /// <param name="sFileContent">string -- Script to be parsed</param>
        /// <param name="sInputVariable">string -- Input Variable, usually search term</param>
        /// <param name="blIsAdmin">bool -- Is the current user requesting this page a WWWinamp Admin</param>
        /// <returns>string -- Parsed script</returns>
        private static string ProcessScriptTags(string sFileContent, string sInputVariable, bool blIsAdmin)
        {
            try
            {
                //Look for Strings
                StringBuilder sParsedOutput = new StringBuilder(sFileContent);
                sParsedOutput.Replace("|PLAYLIST|", GeneratePlaylist());
                sParsedOutput.Replace("|LIBRARY|", GenerateLibrary(sInputVariable));
                sParsedOutput.Replace("|PLAYING_STATUS|", WinAmpController.WinAmpStatus("PLAYING_STATUS"));
                sParsedOutput.Replace("|CURRENT_SONG_TITLE|", WinampPlaylist.PlaylistItems[WinampPlaylist.CurrentPosition].DisplayName);
                sParsedOutput.Replace("|CURRENT_SONG_NUMBER|", WinampPlaylist.CurrentPosition.ToString());
                sParsedOutput.Replace("|CURRENT_SONG_BITRATE|", WinAmpController.WinAmpStatus("CURRENT_SONG_BITRATE"));
                sParsedOutput.Replace("|CURRENT_SONG_SAMPLERATE|", WinAmpController.WinAmpStatus("CURRENT_SONG_SAMPLERATE"));
                sParsedOutput.Replace("|CURRENT_SONG_LENGTH|", WinAmpController.WinAmpStatus("CURRENT_SONG_LENGTH"));
                sParsedOutput.Replace("|CURRENT_SONG_ELAPSED|", WinAmpController.WinAmpStatus("CURRENT_SONG_ELAPSED"));
                sParsedOutput.Replace("|STATUS_ADMIN|", blIsAdmin.ToString());
                sParsedOutput.Replace("|LIBRARY_SIZE|", LibraryController.dbMediaLibrary.Count.ToString());
                sParsedOutput.Replace("|SEARCH_RESULTS_SIZE|", Library_CountResults(sInputVariable));
                sParsedOutput.Replace("|PLAYLIST_SIZE|", WinampPlaylist.PlaylistItems.Count.ToString());
                sParsedOutput.Replace("|PLAYLIST_REMAINING|", WinampPlaylist.CurrentPosition.ToString());
                sParsedOutput.Replace("|CONFIG_RESULTSPERPAGE|", AppConfiguration.configWWWinampHTTPResultsPerPage.ToString());

                if (!blIsAdmin)
                {
                    //If the person IS logged in as Admin, Do not show them HTML between these tags
                    sParsedOutput.Replace("|!ADM|", "");
                    sParsedOutput.Replace("|/!ADM|", "");
                    return(FilterAdmin(sParsedOutput));
                }
                else
                {
                    //If the person IS NOT logged in as Admin, Do not show them HTML between these tags
                    sParsedOutput.Replace("|ADM|", "");
                    sParsedOutput.Replace("|/ADM|", "");
                    return(FilterNonAdmin(sParsedOutput));
                }
            }
            catch (Exception e)
            {
                LogHandler.LogError(e);
                return("Error Occured while Parsing Script");
            }
        }