Ejemplo n.º 1
0
        public Task <Uri> GetTrackAsync(PlsParser pls, ContentType contentType, CancellationToken cancellationToken)
        {
            ICollection <PlsTrack> tracks = pls.Tracks;
            PlsTrack plsTrack             = PlsSegmentManagerPolicy.SelectTrack(tracks);

            if (null == plsTrack)
            {
                return(TaskEx.FromResult <Uri>((Uri)null));
            }
            if (tracks.Count > 1)
            {
                Debug.WriteLine("PlsSegmentManagerPolicy.GetTrackAsync() multiple tracks are not supported");
            }
            if (null == plsTrack.File)
            {
                Debug.WriteLine("PlsSegmentManagerPolicy.GetTrackAsync() track does not have a file");
            }
            Uri result;

            if (Uri.TryCreate(pls.BaseUrl, plsTrack.File, out result))
            {
                return(TaskEx.FromResult <Uri>(result));
            }
            Debug.WriteLine("PlsSegmentManagerPolicy.GetTrackAsync() invalid track file: " + plsTrack.File);
            return(TaskEx.FromResult <Uri>((Uri)null));
        }
Ejemplo n.º 2
0
        void HandleTrack(string line, string key, string value)
        {
            var index = FindStartOfTrackNumber(key);

            if (index < 0)
            {
                Debug.WriteLine("PlsParser.HandleTrack() unable to find track number: " + line);
                return;
            }

            var name = key.Substring(0, index + 1).Trim();
            var track = key.Substring(index + 1, key.Length - (index + 1));

            int number;
            if (!int.TryParse(track, NumberStyles.Integer, CultureInfo.InvariantCulture, out number))
            {
                Debug.WriteLine("PlsParser.HandleTrack() invalid track number: " + line);
                return;
            }

            PlsTrack plsTrack;
            if (!_tracks.TryGetValue(number, out plsTrack))
            {
                plsTrack = new PlsTrack();
                _tracks[number] = plsTrack;
            }

            if (string.Equals("File", name))
            {
                if (null != plsTrack.File)
                {
                    Debug.WriteLine("PlsParser.Parser() duplicate file property for entry {0}: {1}", number, line);
                    return;
                }

                plsTrack.File = value;
            }
            else if (string.Equals("Title", name))
            {
                if (null != plsTrack.Title)
                {
                    Debug.WriteLine("PlsParser.Parser() duplicate title property for entry {0}: {1}", number, line);
                    return;
                }

                plsTrack.Title = value;
            }
            else if (string.Equals("Length", name))
            {
                if (plsTrack.Length.HasValue)
                {
                    Debug.WriteLine("PlsParser.Parser() duplicate length property for entry {0}: {1}", number, line);
                    return;
                }

                decimal length;

                if (!decimal.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out length))
                {
                    Debug.WriteLine("PlsParser.Parser() invalid length property for entry {0}: {1}", number, line);
                    return;
                }

                try
                {
                    plsTrack.Length = TimeSpan.FromSeconds((double)length);
                }
                catch (InvalidCastException)
                {
                    Debug.WriteLine("PlsParser.Parser() invalid numeric length property for entry {0}: {1}", number, line);
                }
            }
            else
                Debug.WriteLine("PlsParser.Parse() unknown property: " + line);
        }
Ejemplo n.º 3
0
        private void HandleTrack(string line, string key, string value)
        {
            int startOfTrackNumber = PlsParser.FindStartOfTrackNumber(key);

            if (startOfTrackNumber < 0)
            {
                Debug.WriteLine("PlsParser.HandleTrack() unable to find track number: " + line);
            }
            else
            {
                string b = key.Substring(0, startOfTrackNumber + 1).Trim();
                int    result1;
                if (!int.TryParse(key.Substring(startOfTrackNumber + 1, key.Length - (startOfTrackNumber + 1)), NumberStyles.Integer, (IFormatProvider)CultureInfo.InvariantCulture, out result1))
                {
                    Debug.WriteLine("PlsParser.HandleTrack() invalid track number: " + line);
                }
                else
                {
                    PlsTrack plsTrack;
                    if (!this._tracks.TryGetValue(result1, out plsTrack))
                    {
                        plsTrack = new PlsTrack();
                        this._tracks[result1] = plsTrack;
                    }
                    if (string.Equals("File", b))
                    {
                        if (null != plsTrack.File)
                        {
                            Debug.WriteLine("PlsParser.Parser() duplicate file property for entry {0}: {1}", (object)result1, (object)line);
                        }
                        else
                        {
                            plsTrack.File = value;
                        }
                    }
                    else if (string.Equals("Title", b))
                    {
                        if (null != plsTrack.Title)
                        {
                            Debug.WriteLine("PlsParser.Parser() duplicate title property for entry {0}: {1}", (object)result1, (object)line);
                        }
                        else
                        {
                            plsTrack.Title = value;
                        }
                    }
                    else if (string.Equals("Length", b))
                    {
                        if (plsTrack.Length.HasValue)
                        {
                            Debug.WriteLine("PlsParser.Parser() duplicate length property for entry {0}: {1}", (object)result1, (object)line);
                        }
                        else
                        {
                            Decimal result2;
                            if (!Decimal.TryParse(value, NumberStyles.Number, (IFormatProvider)CultureInfo.InvariantCulture, out result2))
                            {
                                Debug.WriteLine("PlsParser.Parser() invalid length property for entry {0}: {1}", (object)result1, (object)line);
                            }
                            else
                            {
                                try
                                {
                                    plsTrack.Length = new TimeSpan?(TimeSpan.FromSeconds((double)result2));
                                }
                                catch (InvalidCastException ex)
                                {
                                    Debug.WriteLine("PlsParser.Parser() invalid numeric length property for entry {0}: {1}", (object)result1, (object)line);
                                }
                            }
                        }
                    }
                    else
                    {
                        Debug.WriteLine("PlsParser.Parse() unknown property: " + line);
                    }
                }
            }
        }