private static string SerializePlaylist(IPlaylist playlist, Format fileFormat)
        {
            switch (fileFormat)
            {
            case Format.XSPF:
                var xspfSerializer = new XspfSerializer();
                var xspfPl         = new XspfPlaylist(playlist);
                return(xspfSerializer.Serialize(xspfPl));

            case Format.WPL:
                var wplSerializer = new WplSerializer();
                var wplPlaylist   = new WplPlaylist(playlist);
                return(wplSerializer.Serialize(wplPlaylist));

            case Format.M3U:
                var m3USerializer = new M3uSerializer();
                var m3UPlaylist   = new M3uPlaylist(playlist);
                return(m3USerializer.Serialize(m3UPlaylist));

            case Format.ASX:
                var asxSerializer = new AsxSerializer();
                var asxPlaylist   = new AsxPlaylist(playlist);
                return(asxSerializer.Serialize(asxPlaylist));

            case Format.PLS:
                var plsSerializer = new PlsSerializer();
                var plsPlaylist   = new PlsPlaylist(playlist);
                return(plsSerializer.Serialize(plsPlaylist));
            }

            return(String.Empty);
        }
        public void Serialize_EmptyPlaylist_ReturnsEmptyPlaylistStr()
        {
            var serializer = new M3uSerializer();

            var output = serializer.Serialize(new M3uPlaylist());

            output.Should().MatchRegex("^#EXTM3U8?");
        }
        public void Serialize_NullInput_ThrowsException()
        {
            var serializer = new M3uSerializer();

            Action act = () => serializer.Serialize(null);

            act.Should().Throw <ArgumentNullException>();
        }
        public void Serialize_HasAMedia_MediaIsCorrectlyFormated()
        {
            var playlist = new M3uPlaylist();

            playlist.Add(new M3uItem("foo", 42.42m));
            var serializer = new M3uSerializer();

            var output = serializer.Serialize(playlist);

            output.Should().MatchRegex($"#EXTINF:42.42{newlinePattern}foo{newlinePattern}");
        }
Beispiel #5
0
        public async Task ExecuteResultAsync(ActionContext context)
        {
            var channels       = _playlist.ToDomainChannels().Where(x => x.CurrentSourceUrl != null);
            var playlistString = M3uSerializer.Serialize(channels);
            var playListBytes  = Encoding.UTF8.GetBytes(playlistString);

            var response = context.HttpContext.Response;

            response.ContentType = "audio/x-mpegurl";
            response.StatusCode  = StatusCodes.Status200OK;
            await context.HttpContext.Response.Body.WriteAsync(playListBytes);
        }
        public void Serialize_HasAMediaWithNormalTitle_TitleIsTrimmedAndAdded()
        {
            var playlist = new M3uPlaylist();

            playlist.Add(new M3uItem("foo", 0)
            {
                Title = "\t Foo \t"
            });
            var serializer = new M3uSerializer();

            var output = serializer.Serialize(playlist);

            output.Should().MatchRegex($"#EXTINF:0, Foo{newlinePattern}");
        }
        public void Serialize_HasAMediaWithWhitespaceTitle_TitleIsIgnored()
        {
            var playlist = new M3uPlaylist();

            playlist.Add(new M3uItem("foo", 0)
            {
                Title = " \t"
            });
            var serializer = new M3uSerializer();

            var output = serializer.Serialize(playlist);

            output.Should().MatchRegex($"#EXTINF:0{newlinePattern}");
        }
Beispiel #8
0
 public void Serialize_NullInput_ThrowsException()
 {
     Assert.Throws <ArgumentNullException>(() => serializer.Serialize(null));
 }