Esempio n. 1
0
        //public static Dictionary<HosterSites, List<AnimeInfo>> FetchVideoHosterLinks(AnimeIDS ids, Action<int, string, string, int> action)
        //{
        //    try
        //    {
        //        Dictionary<HosterSites, List<AnimeInfo>> urls = new Dictionary<HosterSites, List<AnimeInfo>>();

        //        var max = ids.IDs.Aggregate((l, r) => l.Value.Count > r.Value.Count ? l : r).Key;
        //        var all = ids.IDs.Sum(t => t.Value.Count);
        //        var cnt = 0;
        //        var index = 0;
        //        //Parallel.ForEach(ids.IDs.Keys, (key) =>
        //        foreach (var key in ids.IDs.Keys)
        //        {
        //            Parallel.For(0, ids.IDs[key].Count, (i) =>
        //            {
        //                try
        //                {
        //                    var info = GetAnimeInfo(ids.IDs[key][i].Id, key);
        //                    info.Title = ids.Title;
        //                    info.Cover = ids.Cover;
        //                    if (urls.ContainsKey(key))
        //                    {
        //                        urls[key].Add(info);
        //                    }
        //                    else
        //                    {
        //                        urls.Add(key, new List<AnimeInfo> { info });
        //                    }
        //                    if (max == key)
        //                    {
        //                        action?.Invoke(cnt, "Loading Episode " +
        //                            cnt + "/" + ids.IDs[key].Count, ids.Title, all);
        //                        index++;
        //                    }
        //                    cnt++;
        //                }
        //                catch (Exception x)
        //                {
        //                }
        //            });
        //        }
        //        return urls;
        //    }
        //    catch (Exception x)
        //    {
        //    }
        //    return null;
        //}

        public static AnimeInfo GetAnimeInfo(string url, HosterSites key)
        {
            using (var wc = new WebClient())
            {
                var id = new Uri(url).Segments.Last();
                wc.Proxy = null;
                var str = "https://www1.9anime.to/ajax/episode/info?ts=" + Unix_Timestamp + "&id=" + id + "&server=" + (int)key;
                str = wc.DownloadString(str);

                var info = JsonConvert.DeserializeObject <AnimeInfo>(str);
                info.Hoster    = key;
                info.Anime9_ID = id;
                if (key == HosterSites.StreamangoHD)
                {
                }
                return(info);
            }
        }
Esempio n. 2
0
        //public static string GetEntry(HosterSites key)
        //{
        //    if (VideoSITES.ContainsKey(key))
        //    {
        //        return VideoSITES[key].Trim() + key;
        //    }
        //    return "Unknown" + key;
        //}

        //public static Task<VideoInfo> GetUrl(AnimeInfo info)
        //{
        //    return Task.Run(() =>
        //    {
        //        var t = YtDl_GetLink(info.URL);
        //        VideoInfo vi = new VideoInfo
        //        {
        //            Index = int.Parse(info.Index),
        //            File = getName(info.URL),
        //            Path = "",
        //            url = t
        //        };
        //        return vi;
        //    });
        //}

        //public static Dictionary<HosterSites, List<AnimeInfo>> Fetch(string url, Action<int, string, string, int> action)
        //{
        //    var dict = Fetch9AnimeIDs(url, action);
        //    return FetchVideoHosterLinks(dict, action);
        //}

        //        DownloadInfo dli = new DownloadInfo
        //        {
        //            VideoInfo = new VideoInfo
        //            {
        //                Index = i,
        //                File = getName(url),
        //                Path = DirPath,
        //                url = url
        //            }
        //        };
        //        var t = new Task(() => _download(dli, action));
        //        tasks.Add(t);
        //        t.Start();
        //        if (tasks.Count >= Math.Min(list.Length, Math.Max(0, Parallel_Downloads)))
        //        {
        //            int idx = Task.WaitAny(tasks.ToArray());
        //            tasks.RemoveAt(idx);
        //        }
        //    }
        //    if (tasks.Count > 0)
        //    {
        //        foreach (var tsk in tasks)
        //        {
        //            if (tsk.Status == TaskStatus.Created)
        //                tsk.Start();
        //        }
        //        Task.WaitAll(tasks.ToArray());
        //    }
        //}
        public static AnimeIDS Fetch9AnimeIDs(string url, Action <int, string, string, int> action, params int[] indices)
        {
            //https://www1.9anime.to/watch/that-time-i-got-reincarnated-as-a-slime.yoqz/jk7p83
            //https://www1.9anime.to/ajax/film/servers/yoqz?ts=1541923200

            action?.Invoke(0, "Loading Website", url.GetLast("/"), 1);
            var uri   = new Uri(url.Trim('/'));
            var uriid = uri.Segments.Last().GetBetweenN(".");
            var t1    = Task.Run(async() =>
            {
                using (WebClient wc = new WebClient())
                {
                    wc.Proxy = null;
                    wc.DownloadProgressChanged += (o, e) =>
                    {
                        action?.Invoke(e.ProgressPercentage, "Loading Website " + (e.BytesReceived / 1024) + "kiB", url.GetLast("/"), 100);
                    };
                    var raw = await wc.DownloadStringTaskAsync(new Uri("https://www1.9anime.to/ajax/film/servers/" + uriid));

                    return(Newtonsoft.Json.Linq.JToken.Parse(raw).Value <string>("html"));
                }
            });
            var t2 = Task.Run(() =>
            {
                using (WebClient wc = new WebClient())
                {
                    wc.Proxy = null;
                    return(wc.DownloadString(url));
                }
            });

            Task.WaitAll(t1, t2);
            var apiHtml  = t1.Result;
            var siteHtml = t2.Result;

            var cover = siteHtml.GetBetween("class=\"thumb col-md-5 hidden-sm hidden-xs", "alt=")
                        .GetBetween("src=", "\"");

            var title = siteHtml.GetBetween("og:title", ">").Replace("content=", "").Trim('"');

            title = title.GetBetween("Watch", "in HD").Trim();

            var data = new Dictionary <HosterSites, List <AnimeEpisodes> >();

            using (StringReader sr = new StringReader(apiHtml))
            {
                HosterSites key = 0;
                while (true)
                {
                    var line = sr.ReadLine()?.Trim();
                    if (line == null)
                    {
                        break;
                    }
                    if (line.Contains("class=\"server "))
                    {
                        var tk = sr.ReadLine()?.Trim()?.GetBetween("data-name=", "\"");
                        if (int.TryParse(tk, out int k))
                        {
                            key = (HosterSites)k;
                            if (!Enum.IsDefined(typeof(HosterSites), key))
                            {
                                key = 0;
                            }
                            else
                            {
                                while (!sr.ReadLine().Contains("<ul class="))
                                {
                                    ;
                                }
                                data.Add(key, new List <AnimeEpisodes>());
                                while (true)
                                {
                                    var li = sr.ReadLine()?.Trim();
                                    if (li == null)
                                    {
                                        break;
                                    }
                                    else if (li.Contains("</div>"))
                                    {
                                        break;
                                    }
                                    else if (li.Contains("<li>"))
                                    {
                                        var epi = new AnimeEpisodes();
                                        while (true)
                                        {
                                            var l0 = sr.ReadLine();
                                            if (l0.Contains("data-id="))
                                            {
                                                epi.Id = l0.GetBetween("data-id=", "\"");
                                            }
                                            else if (l0.Contains("data-base="))
                                            {
                                                epi.Index = int.Parse(l0.GetBetween("data-base=", "\""));
                                            }
                                            if (epi.Index >= 0 && !string.IsNullOrEmpty(epi.Id))
                                            {
                                                break;
                                            }
                                            if (li.Equals("</li>"))
                                            {
                                                break;
                                            }
                                        }
                                        data[key].Add(epi);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            action?.Invoke(-1, "", "", 0);
            return(new AnimeIDS
            {
                URL = url,
                IDs = data,
                Title = title,
                Cover = cover
            });
        }