예제 #1
0
 /// <summary>
 /// 自动判断<see cref="IllustDetail"/>的类型并选择合适的下载方法
 /// </summary>
 public static Task AutoDownload(this IllustDetail illust, bool forcsSaveAll = false) =>
 illust.Type == "ugoira"                                   // 判断类型
         ? illust.DownloadUgoiraImage()                    // 保存动图
                                                           // TODO: 把保存全部图片做成设置
         : (illust.OriginalUrls.Count > 1) || forcsSaveAll // 不是动图 读取设置
         ? illust.DownloadAllImage()                       // 保存全部图片
         : illust.DownloadFirstImage();                    // 保存第一张图片
예제 #2
0
        public static IllustDetail FromJsonValue(JsonObject Source)
        {
            IllustDetail toret = new IllustDetail();

            toret.IllustID        = (int)Source["illust"].GetObject()["id"].GetNumber();
            toret.Title           = Source["illust"].GetObject()["title"].TryGetString();
            toret.Type            = Source["illust"].GetObject()["type"].TryGetString();
            toret.Caption         = Source["illust"].GetObject()["caption"].TryGetString();
            toret.AuthorID        = (int)Source["illust"].GetObject()["user"].GetObject()["id"].GetNumber();
            toret.Author          = Source["illust"].GetObject()["user"].GetObject()["name"].TryGetString();
            toret.AuthorAccount   = Source["illust"].GetObject()["user"].GetObject()["account"].TryGetString();
            toret.AuthorAvatarUrl = Source["illust"].GetObject()["user"].GetObject()["profile_image_urls"].GetObject()["medium"].TryGetString();
            toret.IsUserFollowed  = Source["illust"].GetObject()["user"].GetObject()["is_followed"].GetBoolean();
            var tags = Source["illust"].GetObject()["tags"].GetArray();

            toret.Tags = new List <string>();
            foreach (var tag in tags)
            {
                toret.Tags.Add(tag.GetObject()["name"].TryGetString());
            }
            var tools = Source["illust"].GetObject()["tools"].GetArray();

            toret.Tools = new List <string>();
            foreach (var tool in tools)
            {
                toret.Tools.Add(tool.TryGetString());
            }
            toret.CreateDate = Source["illust"].GetObject()["create_date"].TryGetString();
            toret.MediumUrl  = Source["illust"].GetObject()["image_urls"].GetObject()["square_medium"].TryGetString();
            var pgCount = (int)Source["illust"].GetObject()["page_count"].GetNumber();

            toret.OriginalUrls = new List <string>();
            if (pgCount == 1)
            {
                toret.OriginalUrls.Add(Source["illust"].GetObject()["meta_single_page"].GetObject()["original_image_url"].TryGetString());
            }
            else
            {
                var pages = Source["illust"].GetObject()["meta_pages"].GetArray();
                foreach (var page in pages)
                {
                    toret.OriginalUrls.Add(page.GetObject()["image_urls"].GetObject()["original"].TryGetString());
                }
            }
            toret.Width          = (int)Source["illust"].GetObject()["width"].GetNumber();
            toret.Height         = (int)Source["illust"].GetObject()["height"].GetNumber();
            toret.SanityLevel    = (int)Source["illust"].GetObject()["sanity_level"].GetNumber();
            toret.TotalView      = (int)Source["illust"].GetObject()["total_view"].GetNumber();
            toret.TotalBookmarks = (int)Source["illust"].GetObject()["total_bookmarks"].GetNumber();
            toret.IsBookmarked   = Source["illust"].GetObject()["is_bookmarked"].GetBoolean();
            toret.TotalComments  = (int)Source["illust"].GetObject()["total_comments"].GetNumber();
            return(toret);
        }
예제 #3
0
                : illust.DownloadFirstImage();                    // 保存第一张图片

        /// <summary>
        /// 下载全部 分P
        /// </summary>
        public static async Task DownloadAllImage(this IllustDetail illust)
        {
            DownloadJobsAdd?.Invoke(illust.Title);
            for (ushort i = 0; i < illust.OriginalUrls.Count; i++)
            {
                var file = await illust.GetDownloadTargetFile(i);

                if (file != null)
                {
                    NewJob(illust.Title, illust.OriginalUrls[i], file);
                }
            }
        }