private async void _NicoLiveCommentReciever_CommentRecieved(Chat chat) { await HohoemaApp.UIDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { _LiveComments.Insert(0, chat); }); if (chat.User_id == BroadcasterId) { if (chat.Text.Contains("href")) { var root = XDocument.Parse(chat.Text); var anchor = root.Element("a"); if (anchor != null) { var href = anchor.Attribute("href"); var link = href.Value; if (chat.Text.Contains("次")) { var liveId = link.Split('/').LastOrDefault(); if (NiconicoRegex.IsLiveId(liveId)) { // TODO: liveIdの放送情報を取得して、配信者が同一ユーザーかチェックする using (var releaser = await _NextLiveSubscriveLock.LockAsync()) { await HohoemaApp.UIDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { NextLiveId = liveId; NextLive?.Invoke(this, NextLiveId); }); } } } // TODO: linkをブラウザで開けるようにする } } } }
private async void NextLiveSubscribe(object state = null) { await HohoemaApp.UIDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { bool isDone = false; using (var releaser = await _NextLiveSubscriveLock.LockAsync()) { isDone = NextLiveId != null; } if (isDone) { Debug.WriteLine("exit detect next live. (success with operation comment) : " + NextLiveId); await StopNextLiveSubscribe(); return; } // コミュニティページを取得して、放送中のLiveIdを取得する try { var commuDetail = await HohoemaApp.ContentFinder.GetCommunityDetail(BroadcasterCommunityId); // this.LiveIdと異なるLiveIdが一つだけの場合はそのIDを次の枠として処理 var liveIds = commuDetail.CommunitySammary.CommunityDetail.CurrentLiveList.Select(x => x.LiveId); foreach (var nextLiveId in liveIds) { if (nextLiveId != LiveId) { using (var releaser = await _NextLiveSubscriveLock.LockAsync()) { NextLiveId = nextLiveId; PermanentDisplayText = "*次枠を検出しました → " + NextLiveId; NextLive?.Invoke(this, NextLiveId); Debug.WriteLine("exit detect next live. (success) : " + NextLiveId); isDone = true; } break; } } } catch { Debug.WriteLine("exit detect next live. (failed community page access)"); await StopNextLiveSubscribe(); await HohoemaApp.UIDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { PermanentDisplayText = "コミュニティ情報が取得できませんでした"; }); return; } // this.LiveIdと異なるLiveIdが複数ある場合は、それぞれの放送情報を取得して、 // 放送主のIDがBroadcasterIdと一致する方を次の枠として選択する // (配信タイトルの似てる方で選択してもよさそう?) // 定期チェックの終了時刻 using (var releaser = await _NextLiveSubscriveLock.LockAsync()) { if (NextLiveSubscribeStartTime + NextLiveSubscribeDuration < DateTime.Now) { isDone = true; PermanentDisplayText = "コミュニティ情報が取得できませんでした"; Debug.WriteLine("detect next live time over"); } } if (isDone) { await StopNextLiveSubscribe(); return; } }); }