Esempio n. 1
0
        public OfficalLiveNiconamaRtmpConnection(PlayerStatusResponse res)
            : base(res)
        {
            // res.Stream.ContentsのValueに入ってる値
            // アニメなどの高画質放送
            // "case:sp:akamai%3Artmp%3A%2F%2Fnlakmjpk.live.nicovideo.jp%3A1935%2Flive%2Cnlarr_25%40s28582,mobile:akamai%3Artmp%3A%2F%2Fnlakmjpk.live.nicovideo.jp%3A1935%2Flive%2Cnlarr_26%40s18564,premium:akamai%3Artmp%3A%2F%2Fnlakmjpk.live.nicovideo.jp%3A1935%2Flive%2Cnlarr_26%40s18564,default:akamai%3Artmp%3A%2F%2Fnlakmjpk.live.nicovideo.jp%3A1935%2Flive%2Cnlarr_25%40s28582"
            // その他の公式放送
            // "case:sp:limelight%3Artmp%3A%2F%2Fsmilevideo.fc.llnwd.net%3A1935%2Fsmilevideo%2Cs_lv276840177,mobile:limelight%3Artmp%3A%2F%2Fsmilevideo.fc.llnwd.net%3A1935%2Fsmilevideo%2Cs_lv276840177_sub1,premium:limelight%3Artmp%3A%2F%2Fsmilevideo.fc.llnwd.net%3A1935%2Fsmilevideo%2Cs_lv276840177_sub1,default:limelight%3Artmp%3A%2F%2Fsmilevideo.fc.llnwd.net%3A1935%2Fsmilevideo%2Cs_lv276840177"

            var content      = res.Stream.Contents.ElementAt(0);
            var splited      = content.Value.Split(',');
            var decodedSplit = splited.Select(x => WebUtility.UrlDecode(x)).ToList();

            var contentInfoList = decodedSplit.Select(x =>
            {
                var uriFragments = x.Split(':');

                if (uriFragments.Length == 6)
                {
                    uriFragments = uriFragments.Skip(1).ToArray();
                }

                if (uriFragments.Length == 5)
                {
                    var type         = uriFragments[0];
                    var serverType   = uriFragments[1];
                    var uriAndLiveId = string.Join(":", uriFragments.Skip(2)).Split(',');
                    var uri          = uriAndLiveId[0];
                    var sliveId      = uriAndLiveId[1];

                    return(new LiveContentInfo()
                    {
                        PlayEnvType = type,
                        ServerType = serverType,
                        RtmpUri = uri,
                        sLiveId = sliveId
                    });
                }
                else
                {
                    throw new Exception();
                }
            });

            var ticket   = PlayerStatus.Stream.Tickets.ElementAt(0);
            var playpath = $"{ticket.Key}?{ticket.Value}";

            var contentInfo = contentInfoList.First();

            BaseUri = contentInfo.RtmpUri;
            sLiveId = contentInfo.sLiveId;

            RtmpUri = new RtmpUri(BaseUri);

            RtmpUri.Instance = playpath;
        }
Esempio n. 2
0
        private async Task OpenRtmpConnection(PlayerStatusResponse res)
        {
            await CloseRtmpConnection();

            using (var releaser = await _RtmpClientAssignLock.LockAsync())
            {
                if (_RtmpClient == null)
                {
                    _RtmpClient = new NicovideoRtmpClient();

                    _RtmpClient.Started += _RtmpClient_Started;
                    _RtmpClient.Stopped += _RtmpClient_Stopped;

                    await _RtmpClient.ConnectAsync(res);
                }
            }
        }
        public static INicoVideoRtmpConnection MakeConnectionImpl(PlayerStatusResponse res)
        {
            var isLive = !res.Program.IsArchive;

            switch (res.Program.CommunityType)
            {
            case Mntone.Nico2.Live.CommunityType.Official:
                if (isLive)
                {
                    return(new OfficalLiveNiconamaRtmpConnection(res));
                }
                else
                {
                    return(new OfficalArchiveNiconamaRtmpConnection(res));
                }

            case Mntone.Nico2.Live.CommunityType.Channel:
                if (isLive)
                {
                    return(new ChannelLiveNiconamaRtmpConnection(res));
                }
                else
                {
                    return(new ChannelArchiveNiconamaRtmpConnection(res));
                }

            case Mntone.Nico2.Live.CommunityType.Community:
                if (isLive)
                {
                    return(new CommunityLiveNiconamaRtmpConnection(res));
                }
                else
                {
                    return(new CommunityArchiveNiconamaRtmpConnection(res));
                }

            default:
                break;
            }

            throw new NotSupportedException();
        }
Esempio n. 4
0
        public async Task ConnectAsync(PlayerStatusResponse res)
        {
            _Connection = new NetConnection();

            _ConnectionImpl = NicoVideoRtmpConnectionHelper.MakeConnectionImpl(res);

            _Connection.StatusUpdated += new EventHandler <NetStatusUpdatedEventArgs>(OnNetConnectionStatusUpdated);


            var uri     = _ConnectionImpl.Uri;
            var command = _ConnectionImpl.Command;

            if (command != null)
            {
                await _Connection.ConnectAsync(_ConnectionImpl.Uri, command);
            }
            else
            {
                await _Connection.ConnectAsync(_ConnectionImpl.Uri);
            }
        }
        public ChannelLiveNiconamaRtmpConnection(PlayerStatusResponse res) : base(res)
        {
            var uri     = PlayerStatus.Stream.RtmpUrl.OriginalString;
            var rtmpUri = new RtmpUri(uri);
            var pp      = uri.Split('/');

            rtmpUri.App      = string.Join("/", pp[3], pp[4]);
            rtmpUri.Instance = PlayerStatus.Program.Id;
            _Uri             = rtmpUri;

            _NlPlayNoticeCommand = MakeNLPlayNoticeCommand();

            _Command              = new NetConnectionConnectCommand(Uri.App);
            _Command.SwfUrl       = "http://live.nicovideo.jp/nicoliveplayer.swf?160530135720";
            _Command.PageUrl      = "http://live.nicovideo.jp/watch/" + PlayerStatus.Program.Id;
            _Command.FlashVersion = "WIN 23,0,0,162";

            // TcUrl は RtmpUriのInstanceを省いた文字列
            _Command.TcUrl = $"{Uri.Scheme.ToString().ToLower()}://{Uri.Host}:{Uri.Port}/{Uri.App}";
            // Rtmpのconnectメソッドのextrasとして PlayerStatus.Stream.Ticket の値を追加
            _Command.OptionalUserArguments = AmfValue.CreateStringValue($"{PlayerStatus.Stream.Ticket}");
        }
Esempio n. 6
0
        private async Task OpenRtmpConnection(PlayerStatusResponse res)
        {
            await CloseRtmpConnection();

            using (var releaser = await _RtmpClientAssignLock.LockAsync())
            {
                if (_RtmpClient == null)
                {
                    _RtmpClient = new NicovideoRtmpClient();

                    _RtmpClient.Started += _RtmpClient_Started;
                    _RtmpClient.Stopped += _RtmpClient_Stopped;

                    try
                    {
                        await _RtmpClient.ConnectAsync(res);
                    }
                    catch (Exception ex)
                    {
                        _RtmpClient.Started -= _RtmpClient_Started;
                        _RtmpClient.Stopped -= _RtmpClient_Stopped;
                        _RtmpClient.Dispose();
                        _RtmpClient = null;
                        _EnsureStartLiveTimer?.Dispose();
                        _EnsureStartLiveTimer = null;

                        Debug.WriteLine("CAN NOT play Rtmp, Stop ensure open timer. : " + res.Stream.RtmpUrl);

                        FailedOpenLive?.Invoke(this, new FailedOpenLiveEventArgs()
                        {
                            Exception = ex,
                            Message   = "動画引用放送は未対応です"
                        });
                    }
                }
            }
        }
Esempio n. 7
0
 public NiconamaRtmpConnectionBase(PlayerStatusResponse res)
 {
     PlayerStatus = res;
 }
 public ChannelArchiveNiconamaRtmpConnection(PlayerStatusResponse res)
     : base(res)
 {
 }
 public CommunityLiveNiconamaRtmpConnection(PlayerStatusResponse res)
     : base(res)
 {
 }