Esempio n. 1
0
        public static HitomiMetadata ArticleToMetadata(HitomiArticle article)
        {
            HitomiMetadata metadata = new HitomiMetadata();

            if (article.Artists != null)
            {
                metadata.Artists = article.Artists;
            }
            if (article.Characters != null)
            {
                metadata.Characters = article.Characters;
            }
            if (article.Groups != null)
            {
                metadata.Groups = article.Groups;
            }
            metadata.ID       = Convert.ToInt32(article.Magic);
            metadata.Language = LegalizeLanguage(article.Language);
            metadata.Name     = article.Title;
            if (article.Series != null)
            {
                metadata.Parodies = article.Series;
            }
            if (article.Tags != null)
            {
                metadata.Tags = article.Tags.Select(x => LegalizeTag(x)).ToArray();
            }
            metadata.Type = article.Type;
            return(metadata);
        }
Esempio n. 2
0
        public static HitomiMetadata?GetMetadataFromMagic(string magic)
        {
            HitomiMetadata tmp = new HitomiMetadata()
            {
                ID = Convert.ToInt32(magic)
            };
            var pos = HitomiData.Instance.metadata_collection.BinarySearch(tmp, new CompareMetadata());

            if (pos < 0)
            {
                return(null);
            }
            return(HitomiData.Instance.metadata_collection[pos]);
        }
Esempio n. 3
0
        public static HitomiArticle MetadataToArticle(HitomiMetadata metadata)
        {
            HitomiArticle article = new HitomiArticle();

            article.Artists    = metadata.Artists;
            article.Characters = metadata.Characters;
            article.Groups     = metadata.Groups;
            article.Language   = metadata.Language;
            article.Magic      = metadata.ID.ToString();
            article.Series     = metadata.Parodies;
            article.Tags       = metadata.Tags;
            article.Title      = metadata.Name;
            article.Type       = metadata.Type;
            return(article);
        }
Esempio n. 4
0
        public static HitomiMetadata ArticleToMetadata(HitomiArticle article)
        {
            HitomiMetadata metadata = new HitomiMetadata();

            if (article.Artists != null)
            {
                metadata.Artists = article.Artists;
            }
            if (article.Characters != null)
            {
                metadata.Characters = article.Characters;
            }
            if (article.Groups != null)
            {
                metadata.Groups = article.Groups;
            }
            try
            {
                if (article.Magic.Contains("-"))
                {
                    metadata.ID = Convert.ToInt32(article.Magic.Split('-').Last().Split('.')[0]);
                }
                else if (article.Magic.Contains("galleries"))
                {
                    metadata.ID = Convert.ToInt32(article.Magic.Split('/').Last().Split('.')[0]);
                }
                else
                {
                    metadata.ID = Convert.ToInt32(article.Magic);
                }
            }
            catch
            {
                ;
            }
            metadata.Language = LegalizeLanguage(article.Language);
            metadata.Name     = article.Title;
            if (article.Series != null)
            {
                metadata.Parodies = article.Series;
            }
            if (article.Tags != null)
            {
                metadata.Tags = article.Tags.Select(x => LegalizeTag(x)).ToArray();
            }
            metadata.Type = article.Type;
            return(metadata);
        }
        public static bool match(object[] queries, HitomiMetadata md)
        {
            bool[] checker = new bool[queries.Length];

            for (int i = 1; i < queries.Length; i++)
            {
                if (queries[i] is HitomiDataAdvancedQuery query)
                {
                    if (query.is_operator == false)
                    {
                        string token = query.token.Replace('_', ' ');
                        switch (query.token_type)
                        {
                        case HitomiDataAdvancedQueryTokenType.None:
                            Console.Console.Instance.WriteErrorLine("Query type not found!");
                            Console.Console.Instance.Write(Monitor.SerializeObject(query));
                            throw new Exception($"Query system error!");

                        case HitomiDataAdvancedQueryTokenType.Common:
                            if (md.Artists != null)
                            {
                                checker[i] = md.Artists.Any(x => x.Contains(token));
                            }
                            if (md.Name != null)
                            {
                                checker[i] = md.Name.ToLower().Contains(token);
                            }
                            if (md.Groups != null)
                            {
                                checker[i] = md.Groups.Any(x => x.Contains(token));
                            }
                            if (md.Parodies != null)
                            {
                                checker[i] = md.Parodies.Any(x => x.Contains(token));
                            }
                            if (md.Characters != null)
                            {
                                checker[i] = md.Characters.Any(x => x.Contains(token));
                            }
                            if (md.Language == token)
                            {
                                checker[i] = true;
                            }
                            if (md.Type == token)
                            {
                                checker[i] = true;
                            }
                            if (md.ID.ToString() == token)
                            {
                                checker[i] = true;
                            }
                            if (md.Tags != null)
                            {
                                checker[i] = md.Tags.Contains(token);
                            }
                            break;

                        case HitomiDataAdvancedQueryTokenType.Artists:
                            if (md.Artists != null)
                            {
                                checker[i] = md.Artists.Contains(token);
                            }
                            break;

                        case HitomiDataAdvancedQueryTokenType.Title:
                            if (md.Name != null)
                            {
                                checker[i] = token.ToLower().Contains(token);
                            }
                            break;

                        case HitomiDataAdvancedQueryTokenType.Groups:
                            if (md.Groups != null)
                            {
                                checker[i] = md.Groups.Contains(token);
                            }
                            break;

                        case HitomiDataAdvancedQueryTokenType.Series:
                            if (md.Parodies != null)
                            {
                                checker[i] = md.Parodies.Contains(token);
                            }
                            break;

                        case HitomiDataAdvancedQueryTokenType.Characters:
                            if (md.Characters != null)
                            {
                                checker[i] = md.Characters.Contains(token);
                            }
                            break;

                        case HitomiDataAdvancedQueryTokenType.Type:
                            if (md.Type == token)
                            {
                                checker[i] = true;
                            }
                            break;

                        case HitomiDataAdvancedQueryTokenType.Language:
                            var lang = md.Language;
                            if (string.IsNullOrEmpty(lang))
                            {
                                lang = "n/a";
                            }
                            if (lang == token)
                            {
                                checker[i] = true;
                            }
                            break;

                        case HitomiDataAdvancedQueryTokenType.Id:
                            if (md.ID.ToString() == token)
                            {
                                checker[i] = true;
                            }
                            break;

                        case HitomiDataAdvancedQueryTokenType.Tag:
                            if (md.Tags != null)
                            {
                                checker[i] = md.Tags.Contains(token);
                            }
                            break;

                        case HitomiDataAdvancedQueryTokenType.FemaleTag:
                            if (md.Tags != null)
                            {
                                checker[i] = md.Tags.Contains("female:" + token);
                            }
                            break;

                        case HitomiDataAdvancedQueryTokenType.MaleTag:
                            if (md.Tags != null)
                            {
                                checker[i] = md.Tags.Contains("male:" + token);
                            }
                            break;
                        }
                        if (query.option == HitomiDataAdvancedQueryTokenOption.Complement)
                        {
                            checker[i] = !checker[i];
                        }
                    }
                }
            }

            for (int i = queries.Length - 1; i >= 0; i--)
            {
                if (queries[i] is HitomiDataAdvancedQuery query)
                {
                    if (query.is_operator == true)
                    {
                        int s1 = i * 2;
                        int s2 = i * 2 + 1;

                        var qop = queries[i] as HitomiDataAdvancedQuery;

                        if (qop.combination == HitomiDataAdvancedQueryCombinationOption.Default)
                        {
                            checker[i] = checker[s1] && checker[s2];
                        }
                        else if (qop.combination == HitomiDataAdvancedQueryCombinationOption.Combination)
                        {
                            checker[i] = checker[s1] || checker[s2];
                        }
                        else if (qop.combination == HitomiDataAdvancedQueryCombinationOption.Difference)
                        {
                            checker[i] = checker[s1] && !checker[s2];
                        }

                        if (qop.option == HitomiDataAdvancedQueryTokenOption.Complement)
                        {
                            checker[i] = !checker[i];
                        }
                    }
                }
            }

            return(checker[1]);
        }