Beispiel #1
0
 private static HArticleModel ConvertTo(HitomiArticle article, string url, string magic)
 {
     return(ConvertTo(HitomiLegalize.ArticleToMetadata(article), url, magic));
 }
Beispiel #2
0
        private IEnumerable <HitomiColumnModel> getNewedHitomiColumnModels()
        {
            if (_newedCache != null)
            {
                return(_newedCache);
            }
            var articles = new HashSet <int>();

            foreach (var n in newedDataEH)
            {
                articles.Add(n);
            }
            foreach (var n in newedDataHitomi)
            {
                articles.Add(n);
            }

            var x = articles.ToList();

            x.RemoveAll(x => existsBoth.Contains(x));
            x.RemoveAll(x => newedDataEH.Contains(x) && existsEH.Contains(x) && !existsHitomi.Contains(x) && !newedDataHitomi.Contains(x));
            x.RemoveAll(x => newedDataHitomi.Contains(x) && existsHitomi.Contains(x) && !existsEH.Contains(x) && !newedDataEH.Contains(x));
            x.Sort((x, y) => x.CompareTo(y));

            var onHitomi = new Dictionary <int, int>();

            for (int i = 0; i < hitomiArticles.Count; i++)
            {
                var id = 0;

                try
                {
                    if (hitomiArticles[i].Magic.Contains("-"))
                    {
                        id = Convert.ToInt32(hitomiArticles[i].Magic.Split('-').Last().Split('.')[0]);
                    }
                    else if (hitomiArticles[i].Magic.Contains("galleries"))
                    {
                        id = Convert.ToInt32(hitomiArticles[i].Magic.Split('/').Last().Split('.')[0]);
                    }
                    else
                    {
                        id = Convert.ToInt32(hitomiArticles[i].Magic);
                    }
                }
                catch
                {
                    ;
                }

                if (onHitomi.ContainsKey(id))
                {
                    continue;
                }
                onHitomi.Add(id, i);
            }

            var onEH = new Dictionary <int, int>();

            if (eHentaiResultArticles != null)
            {
                for (int i = 0; i < eHentaiResultArticles.Count; i++)
                {
                    var id = int.Parse(eHentaiResultArticles[i].URL.Split('/')[4]);
                    if (onEH.ContainsKey(id))
                    {
                        continue;
                    }
                    onEH.Add(id, i);
                }
            }

            var exists   = db.Query <HitomiColumnModel>($"SELECT * FROM HitomiColumnModel WHERE Id IN ({string.Join(",", x)})");
            var onExists = new Dictionary <int, int>();

            for (int i = 0; i < exists.Count; i++)
            {
                if (onExists.ContainsKey(exists[i].Id))
                {
                    continue;
                }
                onExists.Add(exists[i].Id, i);
            }

            // TODO: This code must be called only one!
            db.Execute($"DELETE FROM HitomiColumnModel WHERE Id IN ({string.Join(",", x)})");

            var datas = x.Select(id =>
            {
                HitomiColumnModel result = null;

                var oh = newedDataHitomi.Contains(id);
                var oe = newedDataEH.Contains(id);
                var ox = onExists.ContainsKey(id);

                var ehh = existsHitomi.Contains(id);
                var eeh = existsEH.Contains(id);

                if (oh)
                {
                    var md = HitomiLegalize.ArticleToMetadata(hitomiArticles[onHitomi[id]]);
                    result = new HitomiColumnModel
                    {
                        Id            = id,
                        Artists       = (md.Artists != null && md.Artists.Length > 0 && md.Artists[0] != "" ? "|" + string.Join("|", md.Artists) + "|" : "|N/A|"),
                        Characters    = (md.Characters != null && md.Characters.Length > 0 && md.Characters[0] != "" ? "|" + string.Join("|", md.Characters) + "|" : null),
                        Groups        = (md.Groups != null && md.Groups.Length > 0 && md.Groups[0] != "" ? "|" + string.Join("|", md.Groups) + "|" : null),
                        Series        = (md.Parodies != null && md.Parodies.Length > 0 && md.Parodies[0] != "" ? "|" + string.Join("|", md.Parodies) + "|" : null),
                        Title         = md.Name,
                        Tags          = (md.Tags != null && md.Tags.Length > 0 && md.Tags[0] != "" ? "|" + string.Join("|", md.Tags) + "|" : null),
                        Type          = md.Type,
                        Language      = (md.Language != null && md.Language.Length != 0) ? md.Language : "n/a",
                        Published     = md.DateTime,
                        ExistOnHitomi = 1,
                    };

                    if (oe)
                    {
                        var ii           = eHentaiResultArticles[onEH[md.ID]];
                        result.Uploader  = ii.Uploader;
                        result.Published = DateTime.Parse(ii.Published);
                        result.EHash     = ii.URL.Split('/')[5];
                        result.Files     = ii.Files.Split(' ')[0].ToInt();
                        if (ii.Title.StartsWith("("))
                        {
                            result.Class = ii.Title.Split("(")[1].Split(")")[0];
                        }
                    }
                    else if (eeh)
                    {
                        var ii           = exists[onExists[id]];
                        result.EHash     = ii.EHash;
                        result.Uploader  = ii.Uploader;
                        result.Published = ii.Published;
                        result.Class     = ii.Class;
                    }
                    //else if (result.Published == null)
                    //    result.Published = mindd.AddMinutes(datetimeEstimator.Predict(md.ID));
                }
                else
                {
                    /*
                     * [
                     *  {
                     *    "URL": string,
                     *    "Thumbnail": string,
                     *    "Title": string,
                     *    "Uploader": string,
                     *    "Published": string,
                     *    "Files": string,
                     *    "Type": string,
                     *    "Descripts": {
                     *      "female": [ string ],
                     *      "artist": [ string ],
                     *      "parody": [ string ],
                     *      "character": [ string ],
                     *      "male": [ string ],
                     *      "misc": [ string ],
                     *      "language": [ string ],
                     *      "group": [ string ]
                     *    }
                     *  }
                     * ]
                     */

                    var ed = eHentaiResultArticles[onEH[id]];

                    var aritst    = ed.Descripts != null ? ed.Descripts.ContainsKey("artist") ? ed.Descripts["artist"] : null : null;
                    var female    = ed.Descripts != null ? ed.Descripts.ContainsKey("female") ? ed.Descripts["female"] : null : null;
                    var parody    = ed.Descripts != null ? ed.Descripts.ContainsKey("parody") ? ed.Descripts["parody"] : null : null;
                    var character = ed.Descripts != null ? ed.Descripts.ContainsKey("character") ? ed.Descripts["character"] : null : null;
                    var male      = ed.Descripts != null ? ed.Descripts.ContainsKey("male") ? ed.Descripts["male"] : null : null;
                    var misc      = ed.Descripts != null ? ed.Descripts.ContainsKey("misc") ? ed.Descripts["misc"] : null : null;
                    var language  = ed.Descripts != null ? ed.Descripts.ContainsKey("language") ? ed.Descripts["language"] : null : null;
                    var group     = ed.Descripts != null ? ed.Descripts.ContainsKey("group") ? ed.Descripts["group"] : null : null;

                    var lang = "n/a";
                    if (language != null && language.Count != 0)
                    {
                        if (language.Where(x => x != "translated").ToList().Count == 0)
                        {
                            Console.WriteLine(ed.URL);
                        }
                        else
                        {
                            lang = language.Where(x => x != "translated").ToList()[0];
                        }
                    }

                    var tags = new List <string>();
                    if (female != null)
                    {
                        foreach (var tag in female)
                        {
                            var tt = tag;
                            if (tt == "lolicon")
                            {
                                tt = "loli";
                            }
                            else if (tt == "shotacon")
                            {
                                tt = "shota";
                            }
                            tags.Add("female:" + tt);
                        }
                    }
                    if (male != null)
                    {
                        foreach (var tag in male)
                        {
                            var tt = tag;
                            if (tt == "lolicon")
                            {
                                tt = "loli";
                            }
                            else if (tt == "shotacon")
                            {
                                tt = "shota";
                            }
                            tags.Add("male:" + tt);
                        }
                    }
                    if (misc != null)
                    {
                        foreach (var tag in misc)
                        {
                            var tt = tag;
                            if (tt == "lolicon")
                            {
                                tt = "loli";
                            }
                            else if (tt == "shotacon")
                            {
                                tt = "shota";
                            }
                            tags.Add(tt);
                        }
                    }

                    result = new HitomiColumnModel
                    {
                        Id            = id,
                        Artists       = (aritst != null && aritst.Count > 0 && aritst[0] != "" ? "|" + string.Join("|", aritst) + "|" : "|N/A|"),
                        Characters    = (character != null && character.Count > 0 && character[0] != "" ? "|" + string.Join("|", character) + "|" : null),
                        Groups        = (group != null && group.Count > 0 && group[0] != "" ? "|" + string.Join("|", group) + "|" : null),
                        Series        = (parody != null && parody.Count > 0 && parody[0] != "" ? "|" + string.Join("|", parody) + "|" : null),
                        Title         = ed.Title,
                        Tags          = (tags.Count > 0 ? "|" + string.Join("|", tags) + "|" : null),
                        Type          = ed.Type,
                        Language      = lang,
                        ExistOnHitomi = ehh ? 1 : 0,
                        Uploader      = ed.Uploader,
                        Published     = DateTime.Parse(ed.Published),
                        EHash         = ed.URL.Split('/')[5],
                        Files         = ed.Files.Split(' ')[0].ToInt(),
                        Class         = ed.Title.StartsWith("(") ? ed.Title.Split("(")[1].Split(")")[0] : null,
                        Thumbnail     = ed.Thumbnail,
                    };
                }
                return(result);
            });

            return(_newedCache = datas);
        }