public async Task <string> GetChNameAsync(string chid) { string result = null; if (string.IsNullOrEmpty(chid)) { return(result); } string html = null; try { //データー取得 html = await _wc.DownloadStringTaskAsync(Props.NicoChannelUrl + chid).Timeout(_wc.timeout); //< meta property = "og:title" content = "旅部(旅部) - ニコニコチャンネル:バラエティ" > result = Regex.Match(html, "\"og:title\" *content *= *\"([^\"]*)\"", RegexOptions.Compiled).Groups[1].Value; result = Regex.Replace(result, "(.*) - ニコニコチャンネル:(.*)$", "$1"); } catch (WebException Ex) { DebugWrite.WriteWebln(nameof(GetChNameAsync), Ex); return(result); } catch (Exception Ex) //その他のエラー { DebugWrite.Writeln(nameof(GetChNameAsync), Ex); return(result); } return(result); }
public async Task <string> GetCommNameAsync(string commid) { string result = null; if (string.IsNullOrEmpty(commid)) { return(result); } string html = null; try { //データー取得 html = await _wc.DownloadStringTaskAsync(Props.NicoCommUrl + commid).Timeout(_wc.timeout); //< meta property = "og:title" content = "プログラムを作ってみるコミュニティ-ニコニコミュニティ" > result = Regex.Match(html, "\"og:title\" *content *= *\"([^\"]*)\"", RegexOptions.Compiled).Groups[1].Value; result = Regex.Replace(result, "(.*)-ニコニコミュニティ$", "$1"); } catch (WebException Ex) { if (Ex.Status == WebExceptionStatus.ProtocolError) { var errres = (HttpWebResponse)Ex.Response; if (errres != null) { if (errres.StatusCode == HttpStatusCode.Forbidden) //403 { //データー取得 //< meta property = "og:title" content = "プログラムを作ってみるコミュニティ-ニコニコミュニティ" > using (var ds = errres.GetResponseStream()) using (var sr = new StreamReader(ds)) { var rs = sr.ReadToEnd(); result = Regex.Match(rs, "\"og:title\" *content *= *\"([^\"]*)\"", RegexOptions.Compiled).Groups[1].Value; result = Regex.Replace(result, "(.*)-ニコニコミュニティ$", "$1"); return(result); } } } } DebugWrite.WriteWebln(nameof(GetCommNameAsync), Ex); return(result); } catch (Exception Ex) //その他のエラー { DebugWrite.Writeln(nameof(GetCommNameAsync), Ex); return(result); } return(result); }
public async Task <System.Drawing.Image> CreateImageAsync(string url) { System.Drawing.Image img = null; try { using (var wc = new WebClientEx()) { wc.Headers.Add(HttpRequestHeader.UserAgent, Props.UserAgent); wc.Proxy = null; wc.timeout = 30000; using (var fs = await wc.OpenReadTaskAsync(url).Timeout(wc.timeout)) { img = System.Drawing.Image.FromStream(fs); } } } catch (WebException Ex) { if (Ex.Status == WebExceptionStatus.ProtocolError) { var errres = (HttpWebResponse)Ex.Response; if (errres != null) { if (errres.StatusCode == HttpStatusCode.NotFound) { using (var fs = new FileStream(Props.GetDefaultThumbnail("comm"), FileMode.Open, FileAccess.Read)) { img = System.Drawing.Image.FromStream(fs); } return(img); } } } DebugWrite.WriteWebln(nameof(CreateImageAsync), Ex); return(img); } catch (Exception Ex) //その他のエラー { DebugWrite.Writeln(nameof(CreateImageAsync), Ex); return(img); } return(img); }
public static void OpenWeb(string liveurl, string browserpath, bool b_flg) { if (string.IsNullOrEmpty(liveurl)) { return; } Process process = null; try { if (b_flg) { Process.Start(liveurl); } else if (File.Exists(browserpath)) { int num = browserpath.LastIndexOf("\\"); if (num < 0) { Process.Start(browserpath, liveurl); } else { process = new Process(); process.StartInfo.FileName = browserpath; process.StartInfo.Arguments = liveurl; process.StartInfo.WorkingDirectory = browserpath.Substring(0, num + 1); process.Start(); } } else { var ttt = browserpath + "がありません"; } } catch (Exception Ex) { DebugWrite.Writeln(nameof(OpenWeb), Ex); } }
public async Task <GetStreamInfo> GetStreamInfo2Async(string liveid, string userid) { var gsi = new GetStreamInfo(); gsi.Status = "fail"; gsi.Error = "not_permitted"; try { //データー取得 gsi.LiveId = liveid; gsi.Provider_Id = userid; //ニコキャスかどうかの判定 var providertype = "unama"; gsi.Provider_Type = providertype; var html = await _wc.DownloadStringTaskAsync(Props.NicoLiveUrl + liveid).Timeout(_wc.timeout); providertype = Regex.Match(html, "\"content_type\":\"([^\"]*)\"", RegexOptions.Compiled).Groups[1].Value; gsi.Provider_Type = providertype; if (html.IndexOf("window.NicoGoogleTagManagerDataLayer = [];") > 0) { //コミュ限定・有料放送 var ttt = Regex.Match(html, "<title>([^<]*)</title>", RegexOptions.Compiled).Groups[1].Value; ttt = Regex.Replace(ttt, "(.*) - (ニコニコ生放送|実験放送)$", "$1"); gsi.Title = WebUtility.HtmlDecode(ttt); ttt = Regex.Match(html, "<meta +name=\"description\" +content=\"([^\"]*)\"/>", RegexOptions.Compiled).Groups[1].Value; gsi.Description = WebUtility.HtmlDecode(ttt); ttt = Regex.Match(html, "<meta +itemprop=\"thumbnail\" +content=\"([^\"]*)\"", RegexOptions.Compiled).Groups[1].Value; gsi.Community_Thumbnail = WebUtility.HtmlDecode(ttt); gsi.Community_Only = "1"; ttt = RgxComm.Match(html).Groups[1].Value; gsi.Community_Id = GetStreamInfo.GetChNo(ttt); ttt = RgxComm.Match(html).Groups[2].Value; gsi.Community_Title = WebUtility.HtmlDecode(ttt); gsi.Provider_Id = providertype; gsi.Provider_Name = "公式生放送"; if (providertype == "user") { ttt = RgxUser.Match(html).Groups[1].Value; gsi.Provider_Id = GetStreamInfo.GetChNo(ttt); ttt = RgxUser.Match(html).Groups[2].Value; gsi.Provider_Name = WebUtility.HtmlDecode(ttt); } else if (providertype == "channel" || providertype == "official") { ttt = RgxChName.Match(html).Groups[1].Value; gsi.Community_Id = GetStreamInfo.GetChNo(ttt); ttt = RgxChName.Match(html).Groups[2].Value; gsi.Community_Title = WebUtility.HtmlDecode(ttt); ttt = RgxChUser.Match(html).Groups[1].Value; if (!string.IsNullOrEmpty(ttt)) { gsi.Provider_Name = WebUtility.HtmlDecode(ttt); } } gsi.Status = "ok"; } else { var ttt = WebUtility.HtmlDecode(Regex.Match(html, "<script +id=\"embedded-data\" +data-props=\"([^\"]*)\"></script>", RegexOptions.Compiled).Groups[1].Value); //Clipboard.SetText(ttt); var dprops = JObject.Parse(ttt); ttt = Regex.Match(html, "<title>([^<]*)</title>", RegexOptions.Compiled).Groups[1].Value; ttt = Regex.Replace(ttt, "(.*) - (ニコニコ生放送|実験放送)$", "$1"); gsi.Title = WebUtility.HtmlDecode(ttt); //Clipboard.SetText(dprops.ToString()); var dprogram = (JObject)dprops["program"]; //gsi.LiveId = dprogram["nicoliveProgramId"].ToString(); //gsi.Title = dprogram["title"].ToString(); gsi.Description = dprogram["description"].ToString(); gsi.Provider_Id = providertype; gsi.Provider_Name = "公式生放送"; gsi.Community_Thumbnail = dprogram["thumbnail"]["small"].ToString(); JToken aaa; if (dprogram.TryGetValue("supplier", out aaa)) { gsi.Provider_Name = dprogram["supplier"]["name"].ToString(); if (providertype == "user") { gsi.Provider_Id = GetStreamInfo.GetChNo(dprogram["supplier"]["pageUrl"].ToString()); } } gsi.Community_Only = dprogram["isFollowerOnly"].ToString(); gsi.Community_Id = providertype; gsi.Community_Title = "公式生放送"; if (dprops["socialGroup"].Count() > 0) { gsi.Community_Id = dprops["socialGroup"]["id"].ToString(); gsi.Community_Title = dprops["socialGroup"]["name"].ToString(); //gsi.Community_Thumbnail = dprops["socialGroup"]["thumbnailSmallImageUrl"].ToString(); } gsi.Status = "ok"; } } catch (WebException Ex) { DebugWrite.WriteWebln(nameof(GetStreamInfo2Async), Ex); gsi.Error = Ex.Status.ToString(); return(gsi); } catch (Exception Ex) //その他のエラー { DebugWrite.Writeln(nameof(GetStreamInfo2Async), Ex); gsi.Error = Ex.Message; return(gsi); } return(gsi); }
public async Task <IList <GetStreamInfo> > ReadCateApiAsync(string url, string cate, DateTime now) { var min_time = now.AddMinutes(-8); //var max_time = now.AddMinutes(5); var lgsi = new List <GetStreamInfo>(); if (string.IsNullOrEmpty(url)) { return(lgsi); } try { var i = 0; var end_flg = false; while (i < 9 && end_flg == false) { var cateurl = string.Format(url, cate, i.ToString()); var xhtml = await _wc.DownloadStringTaskAsync(cateurl).Timeout(_wc.timeout); if (string.IsNullOrEmpty(xhtml)) { break; } var data = JObject.Parse(xhtml); if ((string )data["meta"]["status"] != "200" || data["data"].Count() < 1) { end_flg = true; break; } foreach (var item in data["data"]) { if ((string )item["liveCycle"] != "ON_AIR") { continue; } var gsi = new GetStreamInfo(); gsi.Title = (string )item["title"]; gsi.LiveId = (string )item["id"]; gsi.Col12 = GetUnixMsecToDateTime(item["beginAt"].ToString()); gsi.Start_Time = gsi.Col12.ToString(); Debug.WriteLine(gsi.LiveId + ": " + gsi.Start_Time.ToString()); gsi.Description = ""; gsi.Community_Thumbnail = (string )item["socialGroup"]["thumbnailUrl"]; gsi.Community_Title = (string )item["socialGroup"]["name"]; gsi.Community_Id = (string )item["socialGroup"]["id"]; gsi.Community_Only = item["isFollowerOnly"].ToString().ToLower(); gsi.Provider_Type = (string )item["providerType"]; gsi.Provider_Name = (string )item["programProvider"]["name"]; gsi.Provider_Id = ""; if ((string )item["providerType"] == "community") { gsi.Provider_Id = (string )item["programProvider"]["id"]; } gsi.Col15 = cate; if (gsi.Col12 < min_time) { end_flg = true; break; } lgsi.Add(gsi); } i++; await Task.Delay(1000); } } catch (WebException Ex) { DebugWrite.WriteWebln(nameof(ReadCateApiAsync), Ex); return(lgsi); } catch (Exception Ex) //その他のエラー { DebugWrite.Writeln(nameof(ReadCateApiAsync), Ex); return(lgsi); } return(lgsi); }