示例#1
0
        public MediaPath(string name, Uri path, MediaPath parent)
        {
            RealName = name;
            _path    = path;
            Parent   = parent;

#if DEBUG
            Debug.WriteLine($"MediaPath created: {Title} ({Path})");
#endif
        }
示例#2
0
        public MediaPath[] Expand()
        {
            MediaPath[] result = null;

            if (!Children.Any())
            {
                result = new MediaPath[0];
            }
            else if (Children.All(x => !(x is Playlist) && (x.RealName == RealName || string.IsNullOrEmpty(x.RealName) || x.RealName.StartsWith("#EXTINF"))))
            {
                result = new[] { this };
            }
            else if (Children.All(x => !(x is Playlist)))
            {
                result = Children;
            }
            else
            {
                result =
                    Children
                    .Where(x => x is Playlist)
                    .SelectMany(x => (x as Playlist).Expand())
                    .Union(Children.Where(x => !(x is Playlist)))
                    .ToArray();
            }

            if (Parent == null)
            {
                var cnt = 0;

                foreach (var item in result)
                {
                    if ((cnt = result.Count(x => x.Title == item.Title)) > 1)
                    {
                        item.RealName = string.Format("{0} ({1})", item.Title, cnt);
                    }
                }

                result = result.OrderBy(x => x.Title).ToArray();
            }

            return(result);
        }
        private static MediaPath FromPathInternal(string path, string name, MediaPath parent, Action <string> itemLoaded, CancellationToken cancellationToken, bool?isPlaylist = null)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            var uri = GetUri(path);

            if (uri != null)
            {
                itemLoaded?.Invoke(uri.OriginalString);

                if (!IsAbsolute(uri))
                {
                    if (parent == null)
                    {
                        return(null);
                    }

                    uri = new Uri(new Uri(WithoutQuery(parent.GetUri())), uri);
                }

                var pathType = GetPathType(uri);

                if (isPlaylist != null) // We can specify the file type
                {
                    pathType = isPlaylist.Value ? PathType.M3U8 : PathType.Other;
                }

                if (pathType == PathType.Other) // Если это не файл плейлиста, то это файл или путь к потоку
                {
                    return(new MediaPath(name, uri, parent));
                }
                else
                {
                    var stream = ToStream(uri);
                    if (stream != null)
                    {
                        var items          = LowLevelLoader.FromStream(stream);
                        var newPl          = new Playlist(name, uri, parent);
                        var innerPlaylists = items
                                             .Select(x =>
                                                     FromPathInternal(
                                                         x.Path,
                                                         x.Name?.Replace("&amp;", "&") ?? x.TvgName?.Replace("&amp;", "&"),
                                                         newPl,
                                                         itemLoaded,
                                                         cancellationToken))
                                             .Where(x => x != null)
                                             .ToArray();

                        if (innerPlaylists.Length == 1)
                        {
                            return(innerPlaylists.FirstOrDefault());
                        }

                        newPl.Children = innerPlaylists;

                        return(newPl);
                    }
                }
            }
            return(null);
        }
示例#4
0
 public Playlist(string name, Uri path, MediaPath parent) : base(name, path, parent)
 {
     // Do nothing
 }