/// <summary> /// Upedate the given entry on the authenticated user's list. /// </summary> /// <param name="manga">The manga to update with updated list values</param> /// <returns>true on success.</returns> /// <exception cref="ApiFormatException">if the request times out.</exception> /// <exception cref="WebException">if a connection cannot be established.</exception> public async Task <bool> UpdateManga(Manga manga) { Console.WriteLine(manga.Title + " " + manga.ListStatus); if (manga.ListStatus == ApiEntry.ListStatuses.NotInList) { return(RemoveManga(manga.Id).Result); } if (manga.ListStatus == ApiEntry.ListStatuses.Completed) { manga.CurrentChapter = manga.Chapters; } string start = (manga.UserStart == DateTime.MinValue) ? DefaultDate : manga.UserStart.ToString(DateRequestFormat); string end = (manga.UserEnd == DateTime.MinValue) ? DefaultDate : manga.UserEnd.ToString(DateRequestFormat); var data = new FormUrlEncodedContent(new [] { new KeyValuePair <string, string>("data", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<entry>" + "<chapter>" + manga.CurrentChapter + "</chapter>" + "<volume>" + manga.CurrentVolume + "</volume>" + "<status>" + (int)manga.ListStatus + "</status>" + "<score>" + manga.UserScore + "</score>" + "<date_start>" + start + "</date_start>" + "<date_finish>" + end + "</date_finish>" + "</entry>"), }); var response = await _client.PostAsync(Path.Combine(UrlBase, "mangalist", "update", manga.Id + ".xml"), data); Console.WriteLine(response.StatusCode + " " + response.Content.ReadAsStringAsync().Result); return(response.Content.ReadAsStringAsync().Result.Contains("Updated")); }
private static Manga ToMangaFromOld(XmlNode node) { if (node.Name != "manga") { throw new ApiFormatException("The node received was not a manga entry node"); } if (!node.HasChildNodes) { throw new ApiFormatException("The node received contained no information"); } try { var id = int.Parse(node.SelectSingleNode(".//series_mangadb_id/text()").Value); var title = node.SelectSingleNode(".//series_title/text()").Value; var synonymnode = node.SelectSingleNode(".//series_synonyms/text()"); var synonyms = synonymnode == null ? new string[0] : Regex.Split(synonymnode.Value, "; "); var type = ResolveMangaType(node.SelectSingleNode(".//series_type/text()").Value); var chapters = int.Parse(node.SelectSingleNode(".//series_chapters/text()").Value); var volumes = int.Parse(node.SelectSingleNode(".//series_volumes/text()").Value); var status = ResolveMangaStatus(node.SelectSingleNode(".//series_status/text()").Value); var startstring = node.SelectSingleNode(".//series_start/text()").Value; var endstring = node.SelectSingleNode(".//series_end/text()").Value; var start = ParseDateTime(startstring); var end = ParseDateTime(endstring); var url = node.SelectSingleNode(".//series_image/text()")?.Value; var result = new Manga(id, title, string.Empty, string.Empty, synonyms, chapters, volumes, 0.0, type, status, start, end, string.Empty, url); result.CurrentChapter = int.Parse(node.SelectSingleNode(".//my_read_chapters/text()").Value); result.CurrentVolume = int.Parse(node.SelectSingleNode(".//my_read_volumes/text()").Value); startstring = node.SelectSingleNode(".//my_start_date/text()").Value; endstring = node.SelectSingleNode(".//my_finish_date/text()").Value; result.UserStart = ParseDateTime(startstring); result.UserEnd = ParseDateTime(endstring); result.UserScore = int.Parse(node.SelectSingleNode(".//my_score/text()").Value); result.ListStatus = ResolveListStatus(node.SelectSingleNode(".//my_status/text()").Value); return(result); } catch (NullReferenceException) { throw new ApiFormatException("One or more required nodes were missing from the response."); } }
/// <summary> /// Update a manga on the list /// </summary> /// <param name="manga">The manga to update with updated values</param> /// <returns>True on success</returns> public async Task <bool> UpdateManga(Manga manga) { var id = await GetEntryId(manga.Id); if (id == -1) { Debug.WriteLine("Manga not in database", "Manga update WARNING"); return(false); } const string q = @" { mutation($id: Int, $status: MediaListStatus, $score: Float, $ch: Int, $vol: Int, $notes: String, $start: FuzzyDateInput, $end: FuzzyDateInput) { SaveMediaListEntry(id: $id, status: $status, score(POINT_10): $score, progress: $ch, progressVolumes: $vol, notes: $notes, startedAt: $start, completedAt: $end) { id mediaId } } } " ; var v = new JsonObject() { ["id"] = id, ["status"] = FromListStatus(manga.ListStatus), ["score"] = manga.UserScore, ["ch"] = manga.CurrentChapter, ["vol"] = manga.CurrentVolume, ["notes"] = manga.Notes, ["start"] = FromDateTime(manga.UserStart), ["end"] = FromDateTime(manga.UserEnd) }; var json = await SendRequest(q, v); Debug.WriteLineIf( id != json?["data"]["SaveMediaListEntry"]["id"] || manga.Id != json["data"]["SaveMediaListEntry"]["mediaId"], "The parameters returned don't match!", "AniList UpdateManga WARNING"); return(true); }
/// <summary> /// Update the manga on the authenticated user's list. /// </summary> /// <param name="m">The manga to update</param> /// <returns>True on success</returns> public async Task <bool> UpdateManga(Manga m) { await AuthenticationCheck(); if (m.ListStatus == ApiEntry.ListStatuses.NotInList) { return(await RemoveManga(m.Id)); } if (m.ListStatus == ApiEntry.ListStatuses.Completed) { m.CurrentChapter = m.Chapters; } var id = await GetEntryId(m.Id, "manga"); if (id == -2) { return(false); } if (id == -1) { await AddManga(m.Id, m.ListStatus); id = await GetEntryId(m.Id, "manga"); if (id < 0) { return(false); } } var json = new JsonObject() { ["data"] = new JsonObject() { ["id"] = id, ["type"] = "libraryEntries", ["attributes"] = new JsonObject() { ["status"] = FromListStatus(m.ListStatus), ["progress"] = m.CurrentChapter, ["volumesOwned"] = m.CurrentVolume, ["notes"] = m.Notes, ["startedAt"] = FromDateTime(m.UserStart), ["finishedAt"] = FromDateTime(m.UserEnd), }, ["relationships"] = new JsonObject() { ["user"] = new JsonObject() { ["data"] = new JsonObject() { ["id"] = _userId, ["type"] = "users" } }, ["media"] = new JsonObject() { ["data"] = new JsonObject() { ["type"] = "anime", ["id"] = m.Id } } } } }; // if we define it, it must be bigger thna 2. json["data"]["attributes"]["ratingTwenty"] = m.UserScore >= 1 ? (JsonValue)(m.UserScore * 2) : null; var response = await _client.SendAsync( new HttpRequestMessage(new HttpMethod("PATCH"), LibraryEntries + $"/{id}") { Content = new StringContent(json.ToString(), Encoding.UTF8, ContentType) }); Debug.WriteLineIf(!response.IsSuccessStatusCode, await response.Content.ReadAsStringAsync(), "Kitsu WARNING"); return(response.IsSuccessStatusCode); }
public Season(Manga m) { Quarter = GetCour(m.StartDate); Year = m.StartDate.Year; }