Пример #1
0
        public int GetMALIDFromAniListID(int anilistid, EntryType type)
        {
            int titleid = this.RetreiveSavedMALIDFromServiceID(Service.AniList, anilistid, type);

            if (titleid > -1)
            {
                return(titleid);
            }
            String typestr = "";

            switch (type)
            {
            case EntryType.Anime:
                typestr = "ANIME";
                break;

            case EntryType.Manga:
                typestr = "MANGA";
                break;

            default:
                break;
            }

            RestRequest request = new RestRequest("/", Method.POST);

            request.RequestFormat = DataFormat.Json;
            GraphQLQuery gquery = new GraphQLQuery();

            gquery.query     = "query ($id: Int!, $type: MediaType) {\n  Media(id: $id, type: $type) {\n    id\n    idMal\n  }\n}";
            gquery.variables = new Dictionary <string, object> {
                { "id", anilistid.ToString() }, { "type", typestr }
            };
            request.AddJsonBody(gquery);
            IRestResponse response = raclient.Execute(request);

            Thread.Sleep(2000);
            if (response.StatusCode.GetHashCode() == 200)
            {
                Dictionary <string, object> jsonData = JsonConvert.DeserializeObject <Dictionary <string, object> >(response.Content);
                Dictionary <string, object> data     = JObjectToDictionary((JObject)jsonData["data"]);
                Dictionary <string, object> media    = JObjectToDictionary((JObject)data["Media"]);
                int malid = !object.ReferenceEquals(null, media["idMal"]) ? Convert.ToInt32((long)media["idMal"]) : -1;
                if (malid > 0)
                {
                    this.SaveIDtoDatabase(Service.AniList, malid, anilistid, type);
                    Thread.Sleep(2000);
                    return(malid);
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                return(-1);
            }
        }
Пример #2
0
        private List <ListEntry> PerformRetrieveAniListList(int page)
        {
            RestRequest request = new RestRequest("/", Method.POST);

            request.RequestFormat = DataFormat.Json;
            GraphQLQuery gquery = new GraphQLQuery();

            switch (currenttype)
            {
            case EntryType.Anime:
                gquery.query = "query ($id : Int!, $page: Int) {\n  AnimeList: Page (page: $page) {\n    mediaList(userId: $id, type: ANIME) {\n      id :media{id\n idMal}\n      entryid: id\n      title: media {title {\n        title: userPreferred\n      }}\n      episodes: media{episodes}\n      duration: media{duration}\n      image_url: media{coverImage {\n        large\n        medium\n      }}\n        type: media{format}\n      status: media{status}\n      score: score(format: POINT_100)\n      watched_episodes: progress\n      watched_status: status\n      rewatch_count: repeat\n      private\n      notes\n      watching_start: startedAt {\n        year\n        month\n        day\n      }\n      watching_end: completedAt {\n        year\n        month\n        day\n      }\n    }\n    pageInfo {\n      total\n      currentPage\n      lastPage\n      hasNextPage\n      perPage\n    }\n  }\n}";
                break;

            case EntryType.Manga:
                gquery.query = "query ($id : Int!, $page: Int) {\n  MangaList: Page (page: $page) {\n    mediaList(userId: $id, type: MANGA) {\n      id :media{id\n idMal}\n      entryid: id\n      title: media {title {\n        title: userPreferred\n      }}\n      chapters: media{chapters}\n      volumes: media{volumes}\n      image_url: media{coverImage {\n        large\n        medium\n      }}\n      type: media{format}\n      status: media{status}\n      score: score(format: POINT_100)\n      read_chapters: progress\n      read_volumes: progressVolumes\n      read_status: status\n      reread_count: repeat\n      private\n      notes\n      read_start: startedAt {\n        year\n        month\n        day\n      }\n      read_end: completedAt {\n        year\n        month\n        day\n      }\n    }\n        pageInfo {\n      total\n      currentPage\n      lastPage\n      hasNextPage\n      perPage\n    }\n  }\n}";
                break;

            default:
                return(new List <ListEntry>());
            }
            gquery.variables = new Dictionary <string, object> {
                { "id", currentuserid.ToString() }, { "page", page.ToString() }
            };
            request.AddJsonBody(gquery);
            IRestResponse response = arestclient.Execute(request);

            Thread.Sleep(1000);
            if (response.StatusCode.GetHashCode() == 200)
            {
                Dictionary <string, object> jsonData = JsonConvert.DeserializeObject <Dictionary <string, object> >(response.Content);
                Dictionary <string, object> list;
                switch (currenttype)
                {
                case EntryType.Anime:
                    list = JObjectToDictionary((JObject)JObjectToDictionary((JObject)jsonData["data"])["AnimeList"]);
                    break;

                case EntryType.Manga:
                    list = JObjectToDictionary((JObject)JObjectToDictionary((JObject)jsonData["data"])["MangaList"]);
                    break;

                default:
                    return(new List <ListEntry>());
                }
                Dictionary <string, object> pageData = JObjectToDictionary((JObject)list["pageInfo"]);
                tmplist.AddRange(((JArray)list["mediaList"]).ToObject <List <Dictionary <string, object> > >());
                bool nextpage = (bool)pageData[@"hasNextPage"];
                if (nextpage)
                {
                    int newpage = page + 1;
                    return(this.PerformRetrieveAniListList(newpage));
                }
                else
                {
                    // Convert List
                    switch (currenttype)
                    {
                    case EntryType.Anime:
                        return(this.NormalizeAniListAnimeList());

                    case EntryType.Manga:
                        return(this.NormalizeAniListMangaList());

                    default:
                        return(new List <ListEntry>());
                    }
                }
            }
            else
            {
                this.erroredout = true;
                return(new List <ListEntry>());
            }
        }