コード例 #1
0
        public NicoNicoLiveContent GetPage()
        {
            try {
                var a = NicoNicoWrapperMain.Session.GetAsync(LiveUrl).Result;

                var doc = new HtmlDocument();
                doc.LoadHtml2(a);

                var content = new NicoNicoLiveContent();

                var hide = doc.DocumentNode.SelectSingleNode("//div[@class='hide']");

                //ゲートじゃない
                if (hide != null)
                {
                    var json = DynamicJson.Parse(Regex.Match(a, "Nicolive_JS_Conf.Watch = ({.*})").Groups[1].Value);

                    string xml = HttpUtility.UrlDecode(json.GPS.value_by_gps);

                    var xmldoc = new HtmlDocument();
                    xmldoc.LoadHtml2(xml);

                    var stream = xmldoc.DocumentNode.SelectSingleNode("//stream");

                    var status = new NicoNicoGetPlayerStatus();

                    status.Id               = stream.SelectSingleNode("id").InnerText;
                    status.Title            = json.Player.videoTitle;
                    status.Description      = stream.SelectSingleNode("child::description").InnerText;
                    status.Description      = SetEncodeHtml + HttpUtility.HtmlDecode(status.Description) + "</body>";
                    status.ProviderType     = stream.SelectSingleNode("provider_type").InnerText;
                    status.DefaultCommunity = stream.SelectSingleNode("default_community").InnerText;

                    status.IsOwner      = stream.SelectSingleNode("is_owner").InnerText == "1";
                    status.OwnerId      = stream.SelectSingleNode("owner_id").InnerText;
                    status.OwnerName    = stream.SelectSingleNode("owner_name").InnerText;
                    status.WatchCount   = stream.SelectSingleNode("watch_count").InnerText;
                    status.CommentCount = stream.SelectSingleNode("comment_count").InnerText;
                    status.BaseTime     = stream.SelectSingleNode("base_time").InnerText;
                    status.StartTime    = stream.SelectSingleNode("start_time").InnerText;
                    status.EndTime      = stream.SelectSingleNode("end_time").InnerText;

                    status.Archive = stream.SelectSingleNode("archive").InnerText == "1";
                    if (status.Archive)
                    {
                        content.Type    = LivePageType.TimeShift;
                        status.QueSheet = new List <QueSheet>();

                        foreach (var que in stream.SelectNodes("quesheet/que"))
                        {
                            var sheet = new QueSheet();

                            sheet.Vpos    = que.Attributes["vpos"].Value;
                            sheet.Mail    = que.Attributes["mail"].Value;
                            sheet.Content = que.InnerText;

                            status.QueSheet.Add(sheet);
                        }
                    }
                    else
                    {
                        content.Type        = LivePageType.Live;
                        status.ContentsList = new List <Contents>();

                        foreach (var que in stream.SelectNodes("contents_list/contents"))
                        {
                            var contents = new Contents();

                            contents.Id           = que.Attributes["id"].Value;
                            contents.DisableAudio = que.Attributes["disableAudio"].Value == "1";
                            contents.DisableVideo = que.Attributes["disableVideo"].Value == "1";
                            contents.StartTime    = que.Attributes["start_time"].Value;

                            contents.Content = que.InnerText;

                            status.ContentsList.Add(contents);
                        }
                    }
                    status.ThumbNailUrl = stream.SelectSingleNode("picture_url").InnerText;

                    status.RoomLabel  = xmldoc.DocumentNode.SelectSingleNode("//user/room_label").InnerText;
                    status.SeetNumber = xmldoc.DocumentNode.SelectSingleNode("//user/room_seetno").InnerText;
                    status.UserId     = xmldoc.DocumentNode.SelectSingleNode("//user/user_id").InnerText;

                    status.RtmpUrl = xmldoc.DocumentNode.SelectSingleNode("//rtmp/url").InnerText;
                    status.Ticket  = xmldoc.DocumentNode.SelectSingleNode("//rtmp/ticket").InnerText;

                    status.MesseageServerUrl  = xmldoc.DocumentNode.SelectSingleNode("//ms/addr").InnerText;
                    status.MesseageServerPort = int.Parse(xmldoc.DocumentNode.SelectSingleNode("//ms/port").InnerText);
                    status.ThreadId           = xmldoc.DocumentNode.SelectSingleNode("//ms/thread").InnerText;


                    content.GetPlayerStatus = status;

                    content.Title       = status.Title;
                    content.Description = status.Description;

                    return(content);
                }


                var ichiba = doc.DocumentNode.SelectSingleNode("//div[@class='ichiba']").InnerHtml;


                //タイムシフト試聴ゲート
                if (ichiba != null)
                {
                    var lefcom = doc.DocumentNode.SelectSingleNode("//div[@class='lefcom']");

                    if (lefcom != null)
                    {
                        content.Type    = LivePageType.TimeShiftGate;
                        content.EndTime = lefcom.InnerHtml.Replace("<br>", "").Trim();
                    }
                    else
                    {
                        content.Type = LivePageType.Gate;
                    }

                    content.Id          = GetValue("id", ichiba);
                    content.Title       = GetValue("title", ichiba);
                    content.Description = SetEncodeHtml + doc.DocumentNode.SelectSingleNode("//div[@class='text_area']").InnerHtml.Trim() + "</body>";
                    content.Description = content.Description.Replace("target=\"_blank\"", "");

                    content.ThumbNailUrl = doc.DocumentNode.SelectSingleNode("//meta[@itemprop='thumbnail']").Attributes["content"].Value;

                    var hmf = doc.DocumentNode.SelectSingleNode("//div[@class='hmf']");
                    content.StartTime = hmf.SelectSingleNode("child::div[@class='kaijo']").InnerHtml.Trim();

                    content.VisitorsAndComments = hmf.SelectSingleNode("child::div[@id='comment_area" + content.Id + "']").InnerHtml.Trim();
                    content.VisitorsAndComments = content.VisitorsAndComments.Split(new string[] { "<br>" }, StringSplitOptions.None)[1].Trim();
                    return(content);
                }


                ;

                return(content);
            } catch (RequestTimeout) {
                return(null);
            }
        }
コード例 #2
0
ファイル: NicoNicoLive.cs プロジェクト: mrtska/SRNicoNico
        public NicoNicoLiveContent GetPage()
        {
            try {

                var a = NicoNicoWrapperMain.Session.GetAsync(LiveUrl).Result;

                var doc = new HtmlDocument();
                doc.LoadHtml2(a);

                var content = new NicoNicoLiveContent();

                var hide = doc.DocumentNode.SelectSingleNode("//div[@class='hide']");

                //ゲートじゃない
                if(hide != null) {

                    var json = DynamicJson.Parse(Regex.Match(a, "Nicolive_JS_Conf.Watch = ({.*})").Groups[1].Value);

                    string xml = HttpUtility.UrlDecode(json.GPS.value_by_gps);

                    var xmldoc = new HtmlDocument();
                    xmldoc.LoadHtml2(xml);

                    var stream = xmldoc.DocumentNode.SelectSingleNode("//stream");

                    var status = new NicoNicoGetPlayerStatus();

                    status.Id = stream.SelectSingleNode("id").InnerText;
                    status.Title = json.Player.videoTitle;
                    status.Description = stream.SelectSingleNode("child::description").InnerText;
                    status.Description = SetEncodeHtml + HttpUtility.HtmlDecode(status.Description) + "</body>";
                    status.ProviderType = stream.SelectSingleNode("provider_type").InnerText;
                    status.DefaultCommunity = stream.SelectSingleNode("default_community").InnerText;

                    status.IsOwner = stream.SelectSingleNode("is_owner").InnerText == "1";
                    status.OwnerId = stream.SelectSingleNode("owner_id").InnerText;
                    status.OwnerName = stream.SelectSingleNode("owner_name").InnerText;
                    status.WatchCount = stream.SelectSingleNode("watch_count").InnerText;
                    status.CommentCount = stream.SelectSingleNode("comment_count").InnerText;
                    status.BaseTime = stream.SelectSingleNode("base_time").InnerText;
                    status.StartTime = stream.SelectSingleNode("start_time").InnerText;
                    status.EndTime = stream.SelectSingleNode("end_time").InnerText;

                    status.Archive = stream.SelectSingleNode("archive").InnerText == "1";
                    if(status.Archive) {

                        content.Type = LivePageType.TimeShift;
                        status.QueSheet = new List<QueSheet>();

                        foreach(var que in stream.SelectNodes("quesheet/que")) {

                            var sheet = new QueSheet();

                            sheet.Vpos = que.Attributes["vpos"].Value;
                            sheet.Mail = que.Attributes["mail"].Value;
                            sheet.Content = que.InnerText;

                            status.QueSheet.Add(sheet);
                        }
                    } else {

                        content.Type = LivePageType.Live;
                        status.ContentsList = new List<Contents>();

                        foreach(var que in stream.SelectNodes("contents_list/contents")) {

                            var contents = new Contents();

                            contents.Id = que.Attributes["id"].Value;
                            contents.DisableAudio = que.Attributes["disableAudio"].Value == "1";
                            contents.DisableVideo = que.Attributes["disableVideo"].Value == "1";
                            contents.StartTime = que.Attributes["start_time"].Value;

                            contents.Content = que.InnerText;

                            status.ContentsList.Add(contents);
                        }
                    }
                    status.ThumbNailUrl = stream.SelectSingleNode("picture_url").InnerText;

                    status.RoomLabel = xmldoc.DocumentNode.SelectSingleNode("//user/room_label").InnerText;
                    status.SeetNumber = xmldoc.DocumentNode.SelectSingleNode("//user/room_seetno").InnerText;
                    status.UserId = xmldoc.DocumentNode.SelectSingleNode("//user/user_id").InnerText;

                    status.RtmpUrl = xmldoc.DocumentNode.SelectSingleNode("//rtmp/url").InnerText;
                    status.Ticket = xmldoc.DocumentNode.SelectSingleNode("//rtmp/ticket").InnerText;

                    status.MesseageServerUrl = xmldoc.DocumentNode.SelectSingleNode("//ms/addr").InnerText;
                    status.MesseageServerPort = int.Parse(xmldoc.DocumentNode.SelectSingleNode("//ms/port").InnerText);
                    status.ThreadId = xmldoc.DocumentNode.SelectSingleNode("//ms/thread").InnerText;

                    content.GetPlayerStatus = status;

                    content.Title = status.Title;
                    content.Description = status.Description;

                    return content;
                }

                var ichiba = doc.DocumentNode.SelectSingleNode("//div[@class='ichiba']").InnerHtml;

                //タイムシフト試聴ゲート
                if(ichiba != null) {

                    var lefcom = doc.DocumentNode.SelectSingleNode("//div[@class='lefcom']");

                    if(lefcom != null) {

                        content.Type = LivePageType.TimeShiftGate;
                        content.EndTime = lefcom.InnerHtml.Replace("<br>", "").Trim();
                    } else {

                        content.Type = LivePageType.Gate;
                    }

                    content.Id = GetValue("id", ichiba);
                    content.Title = GetValue("title", ichiba);
                    content.Description = SetEncodeHtml + doc.DocumentNode.SelectSingleNode("//div[@class='text_area']").InnerHtml.Trim() + "</body>";
                    content.Description = content.Description.Replace("target=\"_blank\"", "");

                    content.ThumbNailUrl = doc.DocumentNode.SelectSingleNode("//meta[@itemprop='thumbnail']").Attributes["content"].Value;

                    var hmf = doc.DocumentNode.SelectSingleNode("//div[@class='hmf']");
                    content.StartTime = hmf.SelectSingleNode("child::div[@class='kaijo']").InnerHtml.Trim();

                    content.VisitorsAndComments = hmf.SelectSingleNode("child::div[@id='comment_area" + content.Id + "']").InnerHtml.Trim();
                    content.VisitorsAndComments = content.VisitorsAndComments.Split(new string[] { "<br>" }, StringSplitOptions.None)[1].Trim();
                    return content;
                }

                ;

                return content;
            } catch(RequestTimeout) {

                return null;
            }
        }