Exemplo n.º 1
0
        static void Main(string[] args)
        {
            WeebFileNameParser filenameParser = new WeebFileNameParser();

            while (true)
            {
                Console.WriteLine("Episode Parser Test! Type Episode Name:");
                string filename = Console.ReadLine();
                Console.Clear();
                Console.WriteLine("Parsing Epidose File Name: " + filename);



                Dictionary <string, string> resultofprocessing = filenameParser.ParseFullString(filename);

                Console.WriteLine("--------------RESULT---------------");

                foreach (KeyValuePair <string, string> resultparser in resultofprocessing)
                {
                    Console.WriteLine(resultparser.Key + ":" + resultparser.Value);
                }


                Console.ReadLine();
            }
        }
Exemplo n.º 2
0
        //TODO: remove repeating anime titles, create title parse for episodes
        public async Task <JObject> GetLatestFiles(string botid)
        {
            DebugHandler.TraceMessage("GetLatestFiles called", DebugSource.TASK, DebugType.ENTRY_EXIT);
            DebugHandler.TraceMessage("Bot ID: " + botid, DebugSource.TASK, DebugType.PARAMETERS);

            JObject bots = await GetBotList();

            string filesresult = await Get("packs/" + botid + "/page?episodeNumber=0&page=0&size=500&sort=lastModified&direction=DESC");

            if (filesresult.Contains("failed:"))
            {
                return(new JObject());
            }
            else
            {
                var result = (JObject)JsonConvert.DeserializeObject(filesresult);

                List <Dictionary <string, string> > listWithPacks = new List <Dictionary <string, string> >();

                JArray array = result.Value <JArray>("content");

                try
                {
                    foreach (JObject pack in array.Children())
                    {
                        Dictionary <string, string> info = WeebFileNameParser.ParseFullString(pack.Value <string>("name"));
                        info.Add("BotName", bots.Value <string>(pack.Value <string>("botId")));
                        info.Add("PackNumber", pack.Value <string>("number"));
                        info.Add("FullFileName", pack.Value <string>("name"));
                        listWithPacks.Add(info);
                    }
                }
                catch (Exception e)
                {
                    DebugHandler.TraceMessage(e.ToString(), DebugSource.TASK, DebugType.WARNING);
                }


                return(JObject.Parse("{\"bot\":\"" + bots.Value <string>(botid) + "\",\"packs\":" + JsonConvert.SerializeObject(listWithPacks) + " }"));
            }
        }
Exemplo n.º 3
0
        public async Task GetFilesForAnime(JObject query)
        {
            DebugHandler.TraceMessage("GetFilesForAnime Called.", DebugSource.TASK, DebugType.ENTRY_EXIT);
            DebugHandler.TraceMessage("Query: " + query.ToString(), DebugSource.TASK, DebugType.PARAMETERS);

            try
            {
                JArray animeNames = query.Value <JArray>("titles");

                JObject returnresult = new JObject();

                foreach (string title in animeNames)
                {
                    Dictionary <string, string> parsed = WeebFileNameParser.ParseFullString(title);

                    string searchQuery = parsed["MainAnimeTitle"];

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

                    JObject result = await NiblHandler.SearchNibl(searchQuery);

                    returnresult.Add(title, result);
                }


                await WebSocketHandler.SendMessage(returnresult.ToString());
            }
            catch (Exception e)
            {
                DebugHandler.TraceMessage("Failed to get files for requested anime(s): " + e.ToString(), DebugSource.TASK, DebugType.WARNING);

                JsonError jsonError = new JsonError
                {
                    errortype    = "Exception",
                    errormessage = "failed to get files for requested anime(s)",
                    exception    = e.ToString()
                };

                await WebSocketHandler.SendMessage(jsonError.ToString());
            }
        }
Exemplo n.º 4
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);
        }