Ejemplo n.º 1
0
        public static async Task UpdateItem(ItemModel e, AnimeOrManga AnimeManga)
        {
            using (var stream = new MemoryStream()) {
                using (var writer = XmlWriter.Create(stream)) {
                    new XmlSerializer(e.GetType()).Serialize(writer, e);
                    var xmlEncodedList = Encoding.UTF8.GetString(stream.ToArray());

                    var User = Logincredentials.getuser(1); //Grab username and password
                    var url  = new Uri("https://myanimelist.net/api/" + AnimeManga.ToString() + "list/update/" + e.Item_Id + ".xml?data=" + xmlEncodedList);

                    //GET
                    byte[] bytes         = Encoding.UTF8.GetBytes(User.UserName + ":" + User.Password);
                    string LoginToBase64 = Convert.ToBase64String(bytes);

                    using (var client = new HttpClient()) {
                        client.DefaultRequestHeaders.Add("Authorization", "Basic " + LoginToBase64);

                        HttpResponseMessage response = await client.GetAsync(url);

                        response.EnsureSuccessStatusCode();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        ///<summary>
        ///Grab user's data from the server and save it to the local file inside the app.
        ///
        ///category : 1 -> anime , 2-> manga
        ///</summary>
        public static async Task GrabUserDatatoOffline(int service)
        {
            string           username = Logincredentials.getuser(1).UserName;
            List <ItemModel> Item     = new List <ItemModel>();

            ///currently only to serve MyAnimelist
            ///Considering to use NetJSON to get faster serializer and deserializer.
            var    url = new Uri("https://myanimelist.net/malappinfo.php?u=" + Uri.EscapeDataString(username) + "&type=anime&status=all");
            var    url2 = new Uri("https://myanimelist.net/malappinfo.php?u=" + Uri.EscapeDataString(username) + "&type=manga&status=all");
            string FetchData, FetchData2;

            using (var client = new HttpClient()) {
                HttpResponseMessage response = await client.GetAsync(url);

                HttpResponseMessage response2 = await client.GetAsync(url2);

                response.EnsureSuccessStatusCode();
                response2.EnsureSuccessStatusCode();

                FetchData  = response.Content.ToString();
                FetchData2 = response2.Content.ToString();
            }

            //convert XML to JSON for good
            XDocument ParsedItemsAnime = XDocument.Parse(FetchData);
            var       anime            = ParsedItemsAnime.Descendants("anime");

            foreach (var item in anime)
            {
                Item.Add(new ItemModel {
                    Category           = AnimeOrManga.anime,
                    Item_Id            = (int)item.Element("series_animedb_id"),
                    Item_Title         = item.Element("series_title").Value,
                    Item_Totalepisodes = (int)item.Element("series_episodes"),
                    Series_start       = new string(item.Element("series_start").Value.Take(4).ToArray()),
                    Imgurl             = item.Element("series_image").Value,

                    My_watch  = (int)item.Element("my_watched_episodes"),
                    My_score  = (int)item.Element("my_score"),
                    My_status = (int)item.Element("my_status")
                });
            }
            XDocument ParsedItemsManga = XDocument.Parse(FetchData2);
            var       manga            = ParsedItemsManga.Descendants("manga");

            foreach (var item in manga)
            {
                Item.Add(new ItemModel {
                    Category           = AnimeOrManga.manga,
                    Item_Id            = (int)item.Element("series_mangadb_id"),
                    Item_Title         = item.Element("series_title").Value,
                    Item_Totalepisodes = (int)item.Element("series_chapters"),
                    Series_start       = new string(item.Element("series_start").Value.Take(4).ToArray()),
                    Imgurl             = item.Element("series_image").Value,

                    My_watch  = (int)item.Element("my_read_chapters"),
                    My_score  = (int)item.Element("my_score"),
                    My_status = (int)item.Element("my_status")
                });
            }

            string JsonItems = JsonConvert.SerializeObject(Item, Formatting.Indented);
            //save data
            var OfflineFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Offline_data", CreationCollisionOption.OpenIfExists);

            var SaveFile = await OfflineFolder.CreateFileAsync("RAW_" + service + ".json", CreationCollisionOption.ReplaceExisting);

            await FileIO.WriteTextAsync(SaveFile, JsonItems);
        }
Ejemplo n.º 3
0
        private static async Task <List <GroupedSearchResult> > OnlineResult(string Query)
        {
            var User = Logincredentials.getuser(1);                                        //Grab username and password
            var url  = new Uri("https://myanimelist.net/api/anime/search.xml?q=" + Query);
            var url2 = new Uri("https://myanimelist.net/api/manga/search.xml?q=" + Query); //my god, I hate this hack

            //GET
            HttpResponseMessage AnimeResponse, MangaResponse;

            byte[] bytes         = Encoding.UTF8.GetBytes(User.UserName + ":" + User.Password);
            string LoginToBase64 = Convert.ToBase64String(bytes);

            using (var client = new HttpClient()) {
                client.DefaultRequestHeaders.Add("Authorization", "Basic " + LoginToBase64);

                AnimeResponse = await client.GetAsync(url);

                AnimeResponse.EnsureSuccessStatusCode();

                MangaResponse = await client.GetAsync(url2);

                MangaResponse.EnsureSuccessStatusCode();
            }

            List <GroupedSearchResult> ItemList = new List <GroupedSearchResult>();
            XDocument AnimeItems = ParseResponse(AnimeResponse.Content.ToString());
            XDocument MangaItems = ParseResponse(MangaResponse.Content.ToString());

            if (AnimeItems == null && MangaItems == null)
            {
                return(ItemList);                                                                         // just return null list.
            }
            AnimeResponse.Dispose();
            MangaResponse.Dispose();
            if (AnimeItems != null)
            {
                var AnimeIndex = AnimeItems.Descendants("entry").Take(3);
                foreach (var item in AnimeIndex)
                {
                    ItemList.Add(new GroupedSearchResult {
                        GroupName = "Anime",
                        Library   = new ItemModel {
                            Item_Id    = (int)item.Element("id"),
                            Item_Title = item.Element("title").Value,
                            Imgurl     = item.Element("image").Value
                        }
                    });
                }
            }

            if (MangaItems != null)
            {
                var MangaIndex = MangaItems.Descendants("entry").Take(3);
                foreach (var item in MangaIndex)
                {
                    ItemList.Add(new GroupedSearchResult {
                        GroupName = "Manga",
                        Library   = new ItemModel {
                            Item_Id    = (int)item.Element("id"),
                            Item_Title = item.Element("title").Value,
                            Imgurl     = item.Element("image").Value
                        }
                    });
                }
            }
            return(ItemList);
        }