コード例 #1
0
        private IEnumerable <LinkedChild> GetPlsItems(Stream stream)
        {
            var content  = new PlsContent();
            var playlist = content.GetFromStream(stream);

            return(playlist.PlaylistEntries.Select(i => new LinkedChild
            {
                Path = i.Path,
                Type = LinkedChildType.Manual
            }));
        }
コード例 #2
0
ファイル: PlsTests.cs プロジェクト: xxbiohazrdxx/PlaylistsNET
        public void GetFromStream_ReadPlaylistAndCompareWithObject_Equal()
        {
            PlsContent  content  = new PlsContent();
            PlsPlaylist playlist = new PlsPlaylist();

            playlist.Version = 2;
            playlist.PlaylistEntries.Add(new PlsPlaylistEntry()
            {
                Length = TimeSpan.Zero,
                Nr     = 1,
                Path   = "http://stream3.polskieradio.pl:8902/",
                Title  = null,
            });
            playlist.PlaylistEntries.Add(new PlsPlaylistEntry()
            {
                Length = TimeSpan.FromSeconds(-1),
                Nr     = 2,
                Path   = "http://stream.polskastacja.pl/ps43_mp3?player_group=PS_EXT_MP3",
                Title  = "Server1-> >>> P O L S K A S T A C J A <<<- Ballady Rockowe",
            });
            playlist.PlaylistEntries.Add(new PlsPlaylistEntry()
            {
                Length = TimeSpan.FromSeconds(5720),
                Nr     = 3,
                Path   = "/home/uzytkownik/muzyka-1.mp3",
                Title  = "Myslovitz - Sprzedawcy Marzeń",
            });
            playlist.PlaylistEntries.Add(new PlsPlaylistEntry()
            {
                Length = TimeSpan.Zero,
                Nr     = 4,
                Path   = "Weird Al - This Is The Life.mp3",
                Title  = "Weird Al Yankovic - This is the Life",
            });

            var stream = Helpers.ReadStream("Playlist2.pls");
            var file   = content.GetFromStream(stream);

            stream.Dispose();
            Assert.AreEqual(playlist.PlaylistEntries.Count, file.PlaylistEntries.Count);
            Assert.AreEqual(playlist.NumberOfEntries, file.NumberOfEntries);
            Assert.AreEqual(playlist.Version, file.Version);

            Assert.AreEqual(playlist.PlaylistEntries[0].Path, file.PlaylistEntries[0].Path);
            Assert.AreEqual(playlist.PlaylistEntries[1].Path, file.PlaylistEntries[1].Path);
            Assert.AreEqual(playlist.PlaylistEntries[2].Path, file.PlaylistEntries[2].Path);
            Assert.AreEqual(playlist.PlaylistEntries[3].Path, file.PlaylistEntries[3].Path);

            Assert.AreEqual(playlist.PlaylistEntries[0].Title, file.PlaylistEntries[0].Title);
            Assert.AreEqual(playlist.PlaylistEntries[1].Title, file.PlaylistEntries[1].Title);
            Assert.AreEqual(playlist.PlaylistEntries[2].Title, file.PlaylistEntries[2].Title);
            Assert.AreEqual(playlist.PlaylistEntries[3].Title, file.PlaylistEntries[3].Title);

            Assert.AreEqual(playlist.PlaylistEntries[0].Length, file.PlaylistEntries[0].Length);
            Assert.AreEqual(playlist.PlaylistEntries[1].Length, file.PlaylistEntries[1].Length);
            Assert.AreEqual(playlist.PlaylistEntries[2].Length, file.PlaylistEntries[2].Length);
            Assert.AreEqual(playlist.PlaylistEntries[3].Length, file.PlaylistEntries[3].Length);

            Assert.AreEqual(playlist.PlaylistEntries[0].Nr, file.PlaylistEntries[0].Nr);
            Assert.AreEqual(playlist.PlaylistEntries[1].Nr, file.PlaylistEntries[1].Nr);
            Assert.AreEqual(playlist.PlaylistEntries[2].Nr, file.PlaylistEntries[2].Nr);
            Assert.AreEqual(playlist.PlaylistEntries[3].Nr, file.PlaylistEntries[3].Nr);
            stream.Dispose();
        }
コード例 #3
0
ファイル: MediaResolver.cs プロジェクト: Tommmciu/TS3AudioBot
        private R <Playlist, LocalStr> GetPlaylistContent(Stream stream, string url, Uid owner, string mime = null)
        {
            string name = null;
            List <PlaylistItem> items;

            mime = mime.ToLowerInvariant();
            url  = url.ToLowerInvariant();
            string anyId = mime ?? url;

            switch (anyId)
            {
            case ".m3u":
            {
                var parser = new M3uContent();
                var list   = parser.GetFromStream(stream);

                items = new List <PlaylistItem>(
                    from e in list.PlaylistEntries
                    select new PlaylistItem(new AudioResource(e.Path, e.Title, ResolverFor)));
                break;
            }

            case ".m3u8":
            case "application/mpegurl":
            case "application/x-mpegurl":
            case "audio/mpegurl":
            case "audio/x-mpegurl":
            case "application/vnd.apple.mpegurl":
            case "application/vnd.apple.mpegurl.audio":
            {
                var parser = new M3u8Content();
                var list   = parser.GetFromStream(stream);

                items = new List <PlaylistItem>(
                    from e in list.PlaylistEntries
                    select new PlaylistItem(new AudioResource(e.Path, e.Title, ResolverFor)));
                break;
            }

            case ".pls":
            case "audio/x-scpls":
            case "application/x-scpls":
            case "application/pls+xml":
            {
                var parser = new PlsContent();
                var list   = parser.GetFromStream(stream);

                items = new List <PlaylistItem>(
                    from e in list.PlaylistEntries
                    select new PlaylistItem(new AudioResource(e.Path, e.Title, ResolverFor)));
                break;
            }

            case ".wpl":
            {
                var parser = new WplContent();
                var list   = parser.GetFromStream(stream);

                items = new List <PlaylistItem>(
                    from e in list.PlaylistEntries
                    select new PlaylistItem(new AudioResource(e.Path, e.TrackTitle, ResolverFor)));
                name = list.Title;
                break;
            }

            case ".zpl":
            {
                var parser = new ZplContent();
                var list   = parser.GetFromStream(stream);

                items = new List <PlaylistItem>(
                    from e in list.PlaylistEntries
                    select new PlaylistItem(new AudioResource(e.Path, e.TrackTitle, ResolverFor)));
                name = list.Title;
                break;
            }

            // ??
            case "application/jspf+json":
            // ??
            case "application/xspf+xml":
            default:
                return(new LocalStr(strings.error_media_file_not_found));                // TODO Loc "media not supported"
            }

            if (string.IsNullOrEmpty(name))
            {
                var index = url.LastIndexOfAny(new[] { '\\', '/' });
                name = index >= 0 ? url.Substring(index) : url;
            }
            return(new Playlist(name, owner, Enumerable.Empty <Uid>(), items));
        }