Пример #1
0
        public static async Task <List <Illust> > GetRecommend(string accessToken)
        {
            string        API  = "https://app-api.pixiv.net/v1/illust/recommended";
            List <Illust> list = new List <Illust>();

            Dictionary <string, string> headers = new Dictionary <string, string>
            {
                { "Authorization", "Bearer " + accessToken },
            };

            do
            {
                string     json    = await(await Request.CreateRequest(MethodType.GET, API, null, headers)).GetResponseStringAsync();
                IllustList ranking = JsonConvert.DeserializeObject <IllustList>(json);

                if (ranking.NextUrl != null)
                {
                    API = ranking.NextUrl;
                }
                else
                {
                    break;
                };

                list.AddRange(ranking.Illusts);
            } while (list.Count < Properties.Settings.Default.countNum);

            return(list);
        }
Пример #2
0
        public static async Task <IllustList> GetFallback()
        {
            string     json     = await(await Request.CreateRequest(MethodType.GET, API)).GetResponseStringAsync();
            IllustList fallback = JsonConvert.DeserializeObject <IllustList>(json, Converter.Settings);

            return(fallback);
        }
Пример #3
0
        public static async Task <List <Illust> > GetRanking(Category category, string accessToken)
        {
            string        API  = "https://app-api.pixiv.net/v1/illust/ranking?mode=";
            List <Illust> list = new List <Illust>();

            switch (category)
            {
            case Category.Daily:
                API += "day";
                break;

            case Category.Weekly:
                API += "week";
                break;

            case Category.Monthly:
                API += "month";
                break;

            default:
                API += "day";
                break;
            }

            Dictionary <string, string> headers = new Dictionary <string, string>
            {
                { "Authorization", "Bearer " + accessToken },
            };

            do
            {
                string     json    = await(await Request.CreateRequest(MethodType.GET, API, null, headers)).GetResponseStringAsync();
                IllustList ranking = JsonConvert.DeserializeObject <IllustList>(json);

                if (ranking.NextUrl != null)
                {
                    API = ranking.NextUrl;
                }
                else
                {
                    break;
                }

                list.AddRange(ranking.Illusts);
            } while (list.Count < Properties.Settings.Default.countNum);

            return(list);
        }
Пример #4
0
        public static async Task <List <Illust> > GetBookmark(string accessToken, long userID, bool privateMode)
        {
            string        PublicAPI  = "https://app-api.pixiv.net/v1/user/bookmarks/illust?restrict=public&user_id=";
            string        PrivateAPI = "https://app-api.pixiv.net/v1/user/bookmarks/illust?restrict=private&user_id=";
            List <Illust> list       = new List <Illust>();
            int           i          = 0;
            string        API        = privateMode ? PrivateAPI + $"{userID}" : PublicAPI + $"{userID}";

            Dictionary <string, string> headers = new Dictionary <string, string>
            {
                { "Authorization", "Bearer " + accessToken },
            };

            do
            {
                string     json    = await(await Request.CreateRequest(MethodType.GET, API, null, headers)).GetResponseStringAsync();
                IllustList ranking = JsonConvert.DeserializeObject <IllustList>(json);

                if (ranking.NextUrl != null)
                {
                    API = ranking.NextUrl;
                }
                else
                {
                    if (privateMode || i >= 3)
                    {
                        break;
                    }
                    ;

                    i++;
                }

                list.AddRange(ranking.Illusts);
            } while (list.Count < Properties.Settings.Default.countNum);

            return(list);
        }
        public async Task FetchWallpaper()
        {
            List <Illust> illustList;

            decimal count             = Properties.Settings.Default.countNum;
            bool    fetchNsfw         = Properties.Settings.Default.R18Check;
            bool    filterPanting     = Properties.Settings.Default.paintingCheck;
            decimal filterResolution  = Properties.Settings.Default.resolutionNum;
            bool    originalImage     = (filterResolution > 1200) || Properties.Settings.Default.originPictureCheck;
            decimal minView           = Properties.Settings.Default.viewCountNum;
            decimal minCollection     = Properties.Settings.Default.collectionNum;
            string  fetchMode         = Properties.Settings.Default.modeCombo;
            string  rankFetchCategory = Properties.Settings.Default.rankModeCombo;
            bool    privateMode       = Properties.Settings.Default.privateColletcion;

            if (!Properties.Auth.Default.KEY_PIXIV_USER_LOGIN)
            {
                IllustList list = await Fallback.GetFallback();

                illustList = list.Illusts.ToList();
            }
            else
            {
                _ = await Auth.Refresh(Properties.Auth.Default.KEY_PIXIV_DEVICE_TOKEN, Properties.Auth.Default.KEY_PIXIV_REFRESH_TOKEN);

                string   accessToken = Properties.Auth.Default.KEY_PIXIV_ACCESS_TOKEN;
                long     userID      = Properties.Auth.Default.KEY_PIXIV_USER_ID;
                Category rankMode;

                switch (rankFetchCategory)
                {
                case "每日":
                    rankMode = Category.Daily;
                    break;

                case "每週":
                    rankMode = Category.Weekly;
                    break;

                case "每月":
                    rankMode = Category.Monthly;
                    break;

                default:
                    rankMode = Category.Daily;
                    break;
                }

                switch (fetchMode)
                {
                case "排行榜":
                    illustList = await Ranking.GetRanking(rankMode, accessToken);

                    break;

                case "推薦":
                    illustList = await Recommend.GetRecommend(accessToken);

                    break;

                case "收藏":
                    illustList = await Bookmark.GetBookmark(accessToken, userID, privateMode);

                    break;

                default:
                    illustList = await Ranking.GetRanking(rankMode, accessToken);

                    break;
                }
            }

            foreach (Illust result in illustList)
            {
                if (LocalArtworksHelper.GetUnchangedWallpaperCount() >= count)
                {
                    break;
                }
                if (!fetchNsfw && result.SanityLevel >= 4)
                {
                    continue;
                }
                if (filterPanting && result.Type != TypeEnum.Illust)
                {
                    continue;
                }
                if (minView > result.TotalView || minCollection > result.TotalBookmarks)
                {
                    continue;
                }

                if (result.PageCount > 1)
                {
                    for (int i = 0; i < result.MetaPages.Length; i++)
                    {
                        if (LocalArtworksHelper.GetUnchangedWallpaperCount() >= count)
                        {
                            break;
                        }
                        string url       = originalImage ? result.MetaPages[i].ImageUrls.Original : result.MetaPages[i].ImageUrls.Large;
                        string finalPath = $"{Path}\\{result.Id}_{i}{System.IO.Path.GetExtension(url)}";
                        try
                        {
                            _ = LocalArtworksHelper.AddAndSaveArtwork(
                                Image.SaveImage(url),
                                finalPath,
                                result.Title,
                                result.User.Name,
                                $"{result.Id}_{i}",
                                url
                                );
                        }
                        catch (WebException)
                        {
                            LocalArtworksHelper.Save();
                            throw;
                        }
                    }
                }
                else
                {
                    string url       = originalImage ? result.MetaSinglePage.OriginalImageUrl : result.ImageUrls.Large;
                    string finalPath = $"{Path}\\{result.Id}{System.IO.Path.GetExtension(url)}";
                    try
                    {
                        _ = LocalArtworksHelper.AddAndSaveArtwork(
                            Image.SaveImage(url),
                            finalPath,
                            result.Title,
                            result.User.Name,
                            result.Id.ToString(),
                            url
                            );
                    }
                    catch (WebException)
                    {
                        LocalArtworksHelper.Save();
                        throw;
                    }
                }
            }

            if (Properties.Settings.Default.deleteCheck)
            {
                LocalArtworksHelper.ClearChangedWallpaper();
            }
            LocalArtworksHelper.Save();
        }