Esempio n. 1
0
        public async Task GetAnimeProfile(JObject query)
        {
            DebugHandler.TraceMessage("GetAnimeProfile Called.", DebugSource.TASK, DebugType.ENTRY_EXIT);
            DebugHandler.TraceMessage("Query: " + query.ToString(), DebugSource.TASK, DebugType.PARAMETERS);

            string             id   = query.Value <string>("id");
            JsonKitsuAnimeInfo info = await AnimeProfileHandler.GetAnimeProfile(id);

            await WebSocketHandler.SendMessage(info.ToJson());
        }
Esempio n. 2
0
        public async Task <JsonKitsuAnimeInfo> GetFullAnime(string animeId)
        {
            DebugHandler.TraceMessage("GetFullAnime Called", DebugSource.TASK, DebugType.ENTRY_EXIT);
            DebugHandler.TraceMessage("Anime ID: " + animeId, DebugSource.TASK, DebugType.PARAMETERS);

            string anime = await Get("episodes?filter[mediaType]=Anime&filter[media_id]=" + animeId);


            JsonKitsuAnimeInfo jsonKitsuAnimeInfo = new JsonKitsuAnimeInfo
            {
                anime_info       = await GetAnime(animeId),
                anime_relations  = await GetRelations(animeId),
                anime_episodes   = await GetEpisodes(animeId),
                anime_categories = await GetCategories(animeId),
                anime_genres     = await GetGenres(animeId)
            };


            return(jsonKitsuAnimeInfo);
        }
Esempio n. 3
0
        public async Task <JsonKitsuAnimeInfo> GetAnimeProfile(string id)
        {
            DebugHandler.TraceMessage("GetAnimeProfile called", DebugSource.TASK, DebugType.ENTRY_EXIT);
            DebugHandler.TraceMessage("Anime ID: " + id, DebugSource.TASK, DebugType.PARAMETERS);

            JsonKitsuAnimeInfo result = await KitsuHandler.GetFullAnime(id);

            int seasonNumber = result.anime_episodes[0]["attributes"].Value <int>("seasonNumber");


            DebugHandler.TraceMessage("ANIME INFO: " + id + ", ANIME SEASON: " + seasonNumber, DebugSource.TASK, DebugType.INFO);
            DebugHandler.TraceMessage(result.ToJson(), DebugSource.TASK, DebugType.INFO);

            List <string> animeTitles = new List <string>();

            JObject titles = result.anime_info["data"][0]["attributes"].Value <JObject>("titles");

            DebugHandler.TraceMessage("START PARSING ALL TITLES", DebugSource.TASK, DebugType.INFO);

            foreach (KeyValuePair <string, JToken> title in titles)
            {
                if (!animeTitles.Contains(title.Value.ToString()))
                {
                    DebugHandler.TraceMessage("ADDED (LOCALIZED) TITLE: " + title.Value.ToString(), DebugSource.TASK, DebugType.INFO);
                    animeTitles.Add(title.Value.ToString());
                }
            }

            foreach (string title in result.anime_info["data"][0]["attributes"].Value <JArray>("abbreviatedTitles"))
            {
                if (!animeTitles.Contains(title))
                {
                    DebugHandler.TraceMessage("ADDED (NON-LOCALIZED) TITLE: " + title, DebugSource.TASK, DebugType.INFO);
                    animeTitles.Add(title);
                }
            }


            DebugHandler.TraceMessage("PARSED ANIME TITLES: " + id, DebugSource.TASK, DebugType.INFO);

            JObject niblResults = new JObject();

            foreach (string title in animeTitles)
            {
                DebugHandler.TraceMessage("SEARCHING NIBL FOR: " + title, DebugSource.TASK, DebugType.INFO);
                Dictionary <string, string> parsed = WeebFileNameParser.ParseFullString(title);

                string searchQuery = parsed["MainAnimeTitle"];

                if (parsed["SubAnimeTitle"].Length > 0)
                {
                    searchQuery += " " + parsed["SubAnimeTitle"];
                }


                JObject nibl_result = await NiblHandler.SearchNibl(searchQuery);

                DebugHandler.TraceMessage("FINISHED SEARCHING NIBL FOR: " + title, DebugSource.TASK, DebugType.INFO);
                if (nibl_result.ContainsKey("packs"))
                {
                    if (nibl_result.Value <JArray>("packs").Count > 0)
                    {
                        if (niblResults.ContainsKey("packs"))
                        {
                            DebugHandler.TraceMessage("nibl results already contains packs", DebugSource.TASK, DebugType.INFO);

                            JArray old      = niblResults.Value <JArray>("packs");
                            JArray newarray = nibl_result.Value <JArray>("packs");
                            old.Merge(newarray);
                            niblResults["packs"] = old;
                        }
                        else
                        {
                            DebugHandler.TraceMessage("nibl results does not contain packs", DebugSource.TASK, DebugType.INFO);
                            niblResults = nibl_result;
                        }
                    }
                    else
                    {
                        DebugHandler.TraceMessage("NO RESULTS FROM NIBL", DebugSource.TASK, DebugType.INFO);
                    }
                }
                else
                {
                    DebugHandler.TraceMessage("NO RESULTS FROM NIBL AT ALL", DebugSource.TASK, DebugType.INFO);
                }
            }

            Dictionary <string, Dictionary <int, List <JObject> > > resolutions = new Dictionary <string, Dictionary <int, List <JObject> > >()
            {
                { "UNKNOWN", new Dictionary <int, List <JObject> >() },
                { "480P", new Dictionary <int, List <JObject> >() },
                { "720P", new Dictionary <int, List <JObject> >() },
                { "1080P", new Dictionary <int, List <JObject> >() }
            };

            foreach (JObject pack in niblResults.Value <JArray>("packs"))
            {
                string resolution = "UNKONWN";

                if (pack.ContainsKey("Video_Resolution"))
                {
                    resolution = pack.Value <string>("Video_Resolution");
                }

                if (!resolutions.ContainsKey(resolution))
                {
                    if (pack.ContainsKey("Episode"))
                    {
                        resolutions.Add(resolution, new Dictionary <int, List <JObject> >()
                        {
                            { int.Parse(pack.Value <string>("Episode")), new List <JObject>()
                              {
                                  pack
                              } }
                        });
                    }
                    else
                    {
                        resolutions.Add(resolution, new Dictionary <int, List <JObject> >()
                        {
                            { -1, new List <JObject>()
                              {
                                  pack
                              } }
                        });
                    }
                }
                else
                {
                    if (pack.ContainsKey("Episode"))
                    {
                        if (resolutions[resolution].ContainsKey(int.Parse(pack.Value <string>("Episode"))))
                        {
                            resolutions[resolution][int.Parse(pack.Value <string>("Episode"))].Add(pack);
                        }
                        else
                        {
                            resolutions[resolution].Add(int.Parse(pack.Value <string>("Episode")), new List <JObject>()
                            {
                                pack
                            });
                        }
                    }
                    else
                    {
                        if (resolutions[resolution].ContainsKey(-1))
                        {
                            resolutions[resolution][-1].Add(pack);
                        }
                        else
                        {
                            resolutions[resolution].Add(-1, new List <JObject>()
                            {
                                pack
                            });
                        }
                    }
                }
            }


            DebugHandler.TraceMessage("FINISHED SEPERATING RESOLUTION: " + resolutions.Count.ToString(), DebugSource.TASK, DebugType.INFO);

            DebugHandler.TraceMessage("PARSING PER EPISODE ", DebugSource.TASK, DebugType.INFO);
            JArray new_anime_episodes = result.anime_episodes;

            int index = 0;

            foreach (JObject episode in result.anime_episodes)
            {
                int episodeNumber = episode["attributes"].Value <int>("number");

                DebugHandler.TraceMessage("PARSING EPISODE: " + episodeNumber, DebugSource.TASK, DebugType.INFO);
                JObject fileList = new JObject();

                foreach (KeyValuePair <string, Dictionary <int, List <JObject> > > resolution in resolutions)
                {
                    DebugHandler.TraceMessage("ADDING RESOLUTION: " + resolution.Key, DebugSource.TASK, DebugType.INFO);

                    if (resolution.Value.ContainsKey(episodeNumber))
                    {
                        List <JObject> files = resolution.Value[episodeNumber];


                        DebugHandler.TraceMessage("FOUND : " + files.Count + " AMOUNT OF FILES FOR EPISODE: " + episodeNumber, DebugSource.TASK, DebugType.INFO);

                        JArray filesArray = JArray.FromObject(files);

                        fileList[resolution.Key] = filesArray;
                    }
                    else
                    {
                        DebugHandler.TraceMessage(" DID NOT FIND FILES FOR EPISODE: " + episodeNumber, DebugSource.TASK, DebugType.INFO);
                    }
                }

                new_anime_episodes[index]["files"] = fileList;

                index++;
            }

            DebugHandler.TraceMessage("FINISHED PARSING EPISODES", DebugSource.TASK, DebugType.INFO);
            result.anime_episodes = new_anime_episodes;


            DebugHandler.TraceMessage("ANIME INFO: " + id, DebugSource.TASK, DebugType.INFO);
            DebugHandler.TraceMessage(result.ToJson(), DebugSource.TASK, DebugType.INFO);

            return(result);
        }