Beispiel #1
0
        protected virtual PlaylistElement AddElement()
        {
            var element = new PlaylistElement();

            Elements.Add(element);
            return(element);
        }
Beispiel #2
0
 public override void Load(StreamReader stream, bool validateHeader)
 {
     Xspf.Playlist playlist = new Xspf.Playlist();
     playlist.DefaultBaseUri = BaseUri;
     playlist.Load(stream);
     Title = playlist.Title;
     foreach (Xspf.Track track in playlist.Tracks)
     {
         PlaylistElement element = AddElement();
         element.Uri = track.GetLocationAt(0);
     }
 }
Beispiel #3
0
        private void ParseExtended(PlaylistElement element, string line)
        {
            string split = line.Substring(8).TrimStart(',');

            string [] parts = split.Split(new char [] { ',' }, 2);

            if (parts.Length == 2)
            {
                element.Duration = SecondsStringToTimeSpan(parts[0]);
                element.Title    = parts[1].Trim();
            }
            else
            {
                element.Title = split.Trim();
            }
        }
Beispiel #4
0
        private void LoadEntry(XmlTextReader xml_reader)
        {
            PlaylistElement element = AddElement();

            do
            {
                try {
                    xml_reader.Read();
                } catch {
                    xml_reader.Skip();
                }

                if (xml_reader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                switch (xml_reader.LocalName.ToLower())
                {
                case "title":
                    xml_reader.Read();
                    element.Title = xml_reader.Value;
                    break;

                case "ref":
                    // asf links say they are http, but are mmsh instead
                    string uri_aux = xml_reader["HREF"] ?? xml_reader["href"];
                    if (uri_aux.StartsWith("http", StringComparison.CurrentCultureIgnoreCase))
                    {
                        uri_aux = "mmsh" + uri_aux.Substring(4);
                    }

                    element.Uri = ResolveUri(uri_aux);
                    break;

                case "duration":
                    try {
                        xml_reader.Read();
                        element.Duration = TimeSpan.Parse(xml_reader.Value);
                    } catch {
                    }
                    break;
                }
            } while (!xml_reader.EOF && xml_reader.Depth > 1);
        }
Beispiel #5
0
        public override void Load(StreamReader reader, bool validateHeader)
        {
            string          line;
            PlaylistElement element = null;

            while ((line = reader.ReadLine()) != null)
            {
                line = line.Trim();

                if (line.Length == 0)
                {
                    continue;
                }

                bool extinf = line.StartsWith("#EXTINF:");

                if (!extinf && line[0] == '#')
                {
                    continue;
                }
                else if (extinf)
                {
                    element = AddElement();
                    try {
                        ParseExtended(element, line);
                    } catch {
                    }
                    continue;
                }
                else if (element == null)
                {
                    element = AddElement();
                }

                try {
                    element.Uri = ResolveUri(line);
                } catch {
                    Elements.Remove(element);
                }

                element = null;
            }
        }
Beispiel #6
0
        public override void Load(StreamReader reader, bool validateHeader)
        {
            string          line;
            PlaylistElement element = AddElement();

            while ((line = reader.ReadLine()) != null)
            {
                if (line.StartsWith("ref01", StringComparison.CurrentCultureIgnoreCase) ||
                    line.StartsWith("ref1", StringComparison.CurrentCultureIgnoreCase))
                {
                    string uri_aux = line.Substring(line.IndexOf("=") + 1).Trim();

                    if (uri_aux.StartsWith("http", StringComparison.CurrentCultureIgnoreCase))
                    {
                        uri_aux = "mmsh" + uri_aux.Substring(4);
                    }

                    element.Uri = ResolveUri(uri_aux);
                    break;
                }
            }
        }
Beispiel #7
0
        public override void Load(StreamReader reader, bool validateHeader)
        {
            string line;

            if (validateHeader && !MagicHandler(reader))
            {
                throw new InvalidPlaylistException();
            }

            while ((line = reader.ReadLine()) != null)
            {
                line = line.Trim();

                if (line.Length == 0)
                {
                    continue;
                }

                int eq_offset    = line.IndexOf('=');
                int index_offset = 0;

                if (eq_offset <= 0)
                {
                    continue;
                }

                PlsType element_type = PlsType.Unknown;

                if (line.StartsWith("File"))
                {
                    element_type = PlsType.File;
                    index_offset = 4;
                }
                else if (line.StartsWith("Title"))
                {
                    element_type = PlsType.Title;
                    index_offset = 5;
                }
                else if (line.StartsWith("Length"))
                {
                    element_type = PlsType.Length;
                    index_offset = 6;
                }
                else
                {
                    continue;
                }

                try {
                    int index = Int32.Parse(line.Substring(index_offset, eq_offset - index_offset),
                                            ApplicationContext.InternalCultureInfo.NumberFormat) - 1;
                    string          value_string = line.Substring(eq_offset + 1).Trim();
                    PlaylistElement element      = index < Elements.Count
                        ? Elements[index]
                        : AddElement();

                    switch (element_type)
                    {
                    case PlsType.File:
                        element.Uri = ResolveUri(value_string);
                        break;

                    case PlsType.Title:
                        element.Title = value_string;
                        break;

                    case PlsType.Length:
                        element.Duration = SecondsStringToTimeSpan(value_string);
                        break;
                    }
                } catch {
                    continue;
                }
            }
        }
 protected virtual PlaylistElement AddElement ()
 {
     var element = new PlaylistElement ();
     Elements.Add(element);
     return element;
 }
 private void AssertEqual (PlaylistElement e1, PlaylistElement e2)
 {
     Assert.AreEqual (e1.Title, e2.Title);
     Assert.AreEqual (e1.Duration, e2.Duration);
     Assert.AreEqual (e1.Uri.ToString (), e2.Uri.ToString ());
 }
        private void ParseExtended(PlaylistElement element, string line)
        {
            string split = line.Substring(8).TrimStart(',');
            string [] parts = split.Split(new char [] { ',' }, 2);

            if(parts.Length == 2) {
                element.Duration = SecondsStringToTimeSpan (parts[0]);
                element.Title = parts[1].Trim ();
            } else {
                element.Title = split.Trim ();
            }
        }