예제 #1
0
        public async Task <Updates> Updates(ISession session)
        {
            try
            {
                Updates upds = new Updates();
                upds.Items = new List <Episode>();
                if (!UpdateHistory.IsLoaded)
                {
                    UpdateHistory.Load();
                }
                DaiSukiSession s = session as DaiSukiSession;
                if (s == null)
                {
                    return new Updates {
                               ErrorMessage = "Invalid Session", Status = ResponseStatus.InvalidArgument
                    }
                }
                ;
                Shows sws = await Shows(s, false);

                if (sws.Status != ResponseStatus.Ok)
                {
                    Updates k = new Updates();

                    sws.PropagateError(k);
                    return(k);
                }
                int                     cnt = Convert.ToInt32(GetAuthSetting(DaiSukiPluginInfo.MaxFollowItems));
                List <Show>             avs = sws.Items.Take(cnt).ToList();
                List <Task <Episodes> > ms  = new List <Task <Episodes> >();
                foreach (Show sh in avs)
                {
                    ms.Add(Episodes(s, sh));
                }
                string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                if (ms.Count > 0)
                {
                    while (ms.Count > 0)
                    {
                        int max = 5;
                        if (ms.Count < 5)
                        {
                            max = ms.Count;
                        }
                        Task <Episodes>[] tsks = new Task <Episodes> [max];
                        for (int x = 0; x < max; x++)
                        {
                            tsks[x] = ms[0];
                            ms.Remove(ms[0]);
                        }
                        await Task.WhenAll(tsks);

                        for (int x = max - 1; x >= 0; x--)
                        {
                            if (tsks[x].Result != null)
                            {
                                if (tsks[x].Result.Items.Count > 0)
                                {
                                    Episode ep = tsks[x].Result.Items.OrderByDescending(a => a.Index).First();
                                    ep.UniqueTag = DaiSukiPluginInfo.PluginName + "|" + ep.ShowName + "|" +
                                                   ep.EpisodeAlpha;
                                    if (UpdateHistory.Exists(ep.UniqueTag))
                                    {
                                        Episode c =
                                            JsonConvert.DeserializeObject <Episode>(UpdateHistory.Get(ep.UniqueTag));
                                        upds.Items.Add(c);
                                    }
                                    else
                                    {
                                        ep.DateTime = datetime;
                                        UpdateHistory.Add(ep.UniqueTag, JsonConvert.SerializeObject(ep));
                                        upds.Items.Add(ep);
                                    }
                                }
                            }
                        }
                    }
                    UpdateHistory.Save();
                }
                return(upds);
            }
            catch (Exception e)
            {
                return(new Updates {
                    ErrorMessage = e.ToString(), Status = ResponseStatus.SystemError
                });
            }
        }
예제 #2
0
        private async Task <Episode> GetEpisodeUpdate(CrunchySession s, Episode placeholder, string datetime)
        {
            try
            {
                WebStream ws = await WebStream.Get(placeholder.PluginMetadata["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))
                    {
                        ws?.Dispose();
                        return(null);
                    }
                    StreamReader rd  = new StreamReader(ws);
                    string       dta = rd.ReadToEnd();
                    rd.Dispose();
                    Episodes eps = new Episodes();
                    eps.Items = new List <Episode>();
                    Show show = new Show();
                    show.PluginName = placeholder.PluginName;
                    show.Id         = placeholder.ShowId;

                    MatchCollection scol      = seasonregex.Matches(dta);
                    int             seasonnum = scol.Count;
                    if (scol.Count == 0)
                    {
                        AddEpisodes(eps, show, dta, String.Empty, 1, true);
                    }
                    else
                    {
                        Match sma = scol[0];
                        if (sma.Success)
                        {
                            string data      = sma.Value;
                            string seasoname = sma.Groups["season"].Value;
                            AddEpisodes(eps, show, data, seasoname, seasonnum, true);
                        }
                    }
                    if (eps.Items.Count == 0)
                    {
                        ws?.Dispose();
                        return(null);
                    }
                    Episode ep = eps.Items[0];
                    placeholder.PluginMetadata["Url"] = ep.PluginMetadata["Url"];
                    placeholder.ImageUri       = ep.ImageUri;
                    placeholder.Description    = ep.Description;
                    placeholder.EpisodeAlpha   = ep.EpisodeAlpha;
                    placeholder.EpisodeNumeric = ep.EpisodeNumeric;
                    placeholder.Id             = ep.Id;
                    placeholder.SeasonAlpha    = ep.SeasonAlpha;
                    placeholder.SeasonNumeric  = ep.SeasonNumeric;
                    placeholder.Name           = ep.Name;
                    placeholder.DateTime       = datetime;
                    UpdateHistory.Add(placeholder.UniqueTag, JsonConvert.SerializeObject(placeholder));
                    ws?.Dispose();
                    return(placeholder);
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(null);
        }