public override async Task <List <StreamClass> > DownloadLiveAsync() { var result = new List <StreamClass>(); try { XDocument xDocument = XDocument.Parse(MyUtility.RemoveSpecialChars(await new MyHttpClient().GetStringAsync(url_, null))); result = (from array in xDocument.Root.Element("results").Elements("array") let owner = array.Element("userName").Value let title = array.Element("title").Value let description = array.Element("description").Value let start_time = MyUtility.FormatDate(array.Element("createdAt").Value, dateFormat_, timeZoneInfo_) let url = array.Element("url").Value let listener = MyUtility.TryParseOrDefault <string, int>(int.TryParse, array.Element("currentNumberOfViewers").Value) select new StreamClass(title, url, owner, listener, start_time)).ToList(); } catch (HttpClientException innerException) { throw innerException; } catch (Exception innerException2) { throw innerException2; } return(result); }
public override async Task <List <StreamClass> > DownloadLiveAsync() { var result = new List <StreamClass>(); try { XDocument xDocument = XDocument.Parse(MyUtility.RemoveSpecialChars(await new MyHttpClient().GetStringAsync(url_, null))); XNamespace ns = "http://www.w3.org/2005/Atom"; XNamespace ct = "http://gae.cavelis.net"; result = (from entry in xDocument.Root.Elements(ns + "entry") let owner = entry.Element(ns + "author").Element(ns + "name").Value let title = entry.Element(ns + "title").Value let description = entry.Element(ns + "summary").Value let start_time = MyUtility.FormatDate(entry.Element(ct + "start_date").Value, dateFormat_, isUniversal_, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal) let url = entry.Element(ns + "id").Value let listener = MyUtility.TryParseOrDefault <string, int>(int.TryParse, entry.Element(ct + "listener").Value) select new StreamClass(title, url, owner, listener, start_time)).ToList(); } catch (HttpClientException innerException) { throw innerException; } catch (Exception innerException2) { throw innerException2; } return(result); }
public override async Task <List <StreamClass> > DownloadLiveAsync() { var result = new List <StreamClass>(); string json = MyUtility.RemoveSpecialChars(await new MyHttpClient().GetStringAsync(url_, null)); using (XmlDictionaryReader reader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(json), XmlDictionaryReaderQuotas.Max)) { XDocument xDocument = XDocument.Load(reader); result.AddRange((from item in xDocument.Root.Element("channel").Elements("item") let owner = item.Element("name").Value let title = item.Element("title").Value let start_time = MyUtility.FormatDate(item.Element("start").Value, dateFormat_, isUniversal_, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None) let url = "http://live.fc2.com/" + item.Element("id").Value + '/' let listener = MyUtility.TryParseOrDefault <string, int>(int.TryParse, item.Element("count").Value) where owner.Trim() != string.Empty && owner != "匿名" select new StreamClass(title, url, owner, listener, start_time)).ToList()); } return(result); }
public override async Task <List <StreamClass> > DownloadLiveAsync() { var result = new List <StreamClass>(); for (int i = 0; i < RATE_LIMIT; i++) { //参考URL //https://stackoverflow.com/questions/45622188/get-value-from-twitch-api //日本語の配信を100配信ずつ(仕様上最大)取得 param_["offset"] = (i * OFFSET).ToString(); string json = MyUtility.RemoveSpecialChars(await new MyHttpClient().GetStringAsync(url_, param_)); using (XmlDictionaryReader reader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(json), XmlDictionaryReaderQuotas.Max)) { XDocument xDocument = XDocument.Load(reader); result.AddRange((from item in xDocument.Root.Element("streams").Elements("item") let channel = item.Element("channel") let owner = channel.Element("name").Value let title = MyUtility.RemoveCRLF(channel.Element("status").Value) let start_time = MyUtility.FormatDate(item.Element("created_at").Value, dateFormat_, isUniversal_) let url = "https://www.twitch.tv/" + channel.Element("name").Value + '/' let listener = MyUtility.TryParseOrDefault <string, int>(int.TryParse, item.Element("viewers").Value) where !result.Exists(x => x.Owner == owner) select new StreamClass(title, url, owner, listener, start_time)).ToList()); ////配信がなくなったらループを抜ける if (xDocument.Root.Element("streams").Elements("item").Count() < OFFSET) { break; } } } return(result); }