Exemplo n.º 1
0
        public bool LoadImportFile(string _fileName)
        {
            m_importFile = null;
            if (File.Exists(_fileName))
            {
                progressMessage("Loading file....", true);
                switch (ImportFormat)
                {
                case ImportFormatType.M3U:
                    m_importFile = ImportFileM3U.loadM3UFile(_fileName);
                    break;

                case ImportFormatType.WPL:
                    m_importFile = ImportFileWPL.loadWPLFile(_fileName);
                    break;
                    //case ImportFormatType.XSPF:
                    // TODO
                    //  break;
                }
                if (m_importFile != null)
                {
                    updateSectionLocations();
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        public static ImportFileM3U loadM3UFile(string _fileName)
        {
            ImportFileM3U importFile = new ImportFileM3U()
            {
                FileName = _fileName
            };

            try
            {
                Directory.SetCurrentDirectory(Path.GetDirectoryName(_fileName));
                using (StreamReader sr = new StreamReader(_fileName))
                {
                    string m3uContent = sr.ReadToEnd() + "\n";
                    // Is this an extended playlist?
                    string extendedIndicator  = @"^\s*#EXTM3U";
                    string whitespaceOnlyLine = @"^\s*?\n";
                    string extendedInfo       = @"^\s*#EXTINF:(?<duration>[0-9]*)\s*?,(?<artist>[^\n-]*)?-?(?<title>[^\n]*)?";
                    importFile.ExtendedFormat = Regex.IsMatch(m3uContent, extendedIndicator);
                    if (importFile.ExtendedFormat)
                    {
                        m3uContent = Regex.Replace(m3uContent, extendedIndicator, "");
                    }
                    string      m3uContentClean = Regex.Replace(Regex.Replace(m3uContent, whitespaceOnlyLine, "", RegexOptions.Multiline), @"\r", "");
                    ImportEntry importEntry     = null;
                    foreach (Match line in Regex.Matches(m3uContentClean, @"^(.*)$", RegexOptions.Multiline))
                    {
                        if (!String.IsNullOrEmpty(line.Value))
                        {
                            Match info = Regex.Match(line.Value, extendedInfo);
                            if (info.Success)
                            {
                                importEntry = new ImportEntry()
                                {
                                    Owner = importFile, Artist = info.Groups["artist"].Value.Trim(), Title = info.Groups["title"].Value.Trim()
                                };
                                try
                                {
                                    importEntry.Duration = Convert.ToInt32(info.Groups["duration"].Value);
                                }
                                catch { }
                            }
                            else
                            {
                                // This is the file name for the new entry
                                if (importEntry == null)
                                {
                                    importEntry = new ImportEntry()
                                    {
                                        Owner = importFile
                                    };
                                }
                                importEntry.FileName = line.Value;
                                importFile.Entries.Add(importEntry);
                                importEntry = null;
                            }
                        }
                    }
                }
            }
            catch { }
            return(importFile);
        }