public async Task<Shows> Shows(ISession session, ShowType type) { if(type==ShowType.Anime) return await Shows(session); Shows s = new Shows(); s.Status = ResponseStatus.Ok; return s; }
public async Task<Shows> Shows(ISession session, ShowType type) { try { CrunchySession s = session as CrunchySession; if (s == null) return new Shows { ErrorMessage = "Invalid Session", Status = ResponseStatus.InvalidArgument }; Shows ret = new Shows(); ret.Items = new List<Show>(); string url = string.Format(LibSet[ShowUrlS], ShowFromType(type)); WebStream ws = await WebStream.Get(url,null,LibSet[UserAgentS],null,s.cookies.ToCookieCollection(),SocketTimeout,true,null,_info.ProxyFromGlobalRequirements(_global)); if (ws != null && ws.StatusCode == HttpStatusCode.OK) { if (!VerifyLogin(ws.Cookies)) SetLoginError(ret); else { StreamReader rd = new StreamReader(ws); string dta = rd.ReadToEnd(); rd.Dispose(); MatchCollection col = showregex.Matches(dta); Dictionary<string, Show> ls = new Dictionary<string, Show>(); foreach (Match m in col) { if (m.Success) { Show cs = new Show(); cs.Id = int.Parse(m.Groups["id"].Value).ToString(); if (!ls.ContainsKey(cs.Id)) { cs.Name = m.Groups["title"].Value; cs.Type = type; cs.PluginName = CrunchyPluginInfo.PluginName; cs.PluginMetadata.Add("Url", new Uri("http://www.crunchyroll.com" + m.Groups["url"].Value).ToString()); ls.Add(cs.Id, cs); } } } col = show2regex.Matches(dta); foreach (Match m in col) { if (m.Success) { string id = int.Parse(m.Groups["id"].Value).ToString(); Show ccd = ls[id]; ccd.Description = Regex.Unescape(m.Groups["desc"].Value); } } ret.Items = ls.Values.OrderBy(a => a.Name).Cast<Show>().ToList(); ret.Status = ResponseStatus.Ok; } } else { SetWebError(ret); } ws?.Dispose(); return ret; } catch (Exception e) { return new Shows {ErrorMessage = e.ToString(), Status = ResponseStatus.SystemError}; } }
private async Task<Shows> Shows(ISession session, bool order) { try { DaiSukiSession s = session as DaiSukiSession; if (s == null) return new Shows { ErrorMessage = "Invalid Session", Status = ResponseStatus.InvalidArgument }; Shows ret = new Shows(); ret.Items = new List<Show>(); WebStream ws = await WebStream.Get("http://www.daisuki.net/bin/wcm/searchAnimeAPI?api=anime_list&searchOptions=¤tPath=%2Fcontent%2Fdaisuki%2Fus%2Fen", null, LibSet[UserAgentS], null, s.cookies.ToCookieCollection(), SocketTimeout, true, null, _info.ProxyFromGlobalRequirements(_global)); if (ws != null && ws.StatusCode == HttpStatusCode.OK) { if (!VerifyLogin(ws.Cookies)) SetLoginError(ret); else { StreamReader rd = new StreamReader(ws); string dta = rd.ReadToEnd(); BaseResponse<Anime> animes = JsonConvert.DeserializeObject<BaseResponse<Anime>>(dta); rd.Dispose(); if (animes.Response == null || animes.Response.Count == 0) { if (animes.Error != null) { ret.ErrorMessage = animes.Error; ret.Status=ResponseStatus.WebError; return ret; } SetWebError(ret); ws?.Dispose(); return ret; } foreach (Anime a in animes.Response) { Show cs=new Show(); cs.PluginName = DaiSukiPluginInfo.PluginName; cs.Id = a.Id.ToString(); cs.Type=ShowType.Anime; cs.Description = a.Synopsis; cs.Name = a.Title; cs.PluginMetadata.Add("Url", new Uri("http://www.daisuki.net/anime/detail/"+a.AdId).ToString()); ret.Items.Add(cs); } if (order) ret.Items = ret.Items.OrderBy(a => a.Name).ToList(); ret.Status = ResponseStatus.Ok; } } else { SetWebError(ret); } ws?.Dispose(); return ret; } catch (Exception e) { return new Shows { ErrorMessage = e.ToString(), Status = ResponseStatus.SystemError }; } }