public MyAnimeListEntry(decimal?score, AnimeCompletionStatus status, int numEpisodesWatched, UncertainDate myStartDate, UncertainDate myFinishDate, DateTime myLastUpdate, MalAnimeInfoFromUserLookup animeInfo, ICollection <string> tags) { Score = score; Status = status; NumEpisodesWatched = numEpisodesWatched; MyStartDate = myStartDate; MyFinishDate = myFinishDate; MyLastUpdate = myLastUpdate; AnimeInfo = animeInfo; Tags = tags; }
public MyMangaListEntry(decimal?score, MangaCompletionStatus status, int numChaptersRead, int numVolumesRead, UncertainDate myStartDate, UncertainDate myFinishDate, DateTime myLastUpdate, MalMangaInfoFromUserLookup mangaInfo, ICollection <string> tags) { Score = score; Status = status; NumChaptersRead = numChaptersRead; NumVolumesRead = numVolumesRead; MyStartDate = myStartDate; MyFinishDate = myFinishDate; MyLastUpdate = myLastUpdate; MangaInfo = mangaInfo; Tags = tags; }
public MalAnimeInfoFromUserLookup(int animeId, string title, MalAnimeType type, ICollection <string> synonyms, MalAnimeSeriesStatus status, int numEpisodes, UncertainDate startDate, UncertainDate endDate, string imageUrl) { AnimeId = animeId; Title = title; Type = type; Synonyms = synonyms; Status = status; NumEpisodes = numEpisodes; StartDate = startDate; EndDate = endDate; ImageUrl = imageUrl; }
public MalMangaInfoFromUserLookup(int mangaId, string title, MalMangaType type, ICollection <string> synonyms, MalMangaSeriesStatus status, int numChapters, int numVolumes, UncertainDate startDate, UncertainDate endDate, string imageUrl) { MangaId = mangaId; Title = title; Type = type; Synonyms = synonyms; Status = status; NumChapters = numChapters; NumVolumes = numVolumes; StartDate = startDate; EndDate = endDate; ImageUrl = imageUrl; }
/// <summary> /// Parses XML obtained from malappinfo.php. /// </summary> /// <param name="doc"></param> /// <returns></returns> public static MalUserLookupResults Parse(XDocument doc) { Logging.Log.Trace("Parsing XML."); XElement error = doc.Root.Element("error"); if (error != null && (string)error == "Invalid username") { throw new MalUserNotFoundException("No MAL list exists for this user."); } else if (error != null) { throw new MalApiException((string)error); } if (!doc.Root.HasElements) { throw new MalUserNotFoundException("No MAL list exists for this user."); } XElement myinfo = GetExpectedElement(doc.Root, "myinfo"); int userId = GetElementValueInt(myinfo, "user_id"); string canonicalUserName = GetElementValueString(myinfo, "user_name"); List <MyAnimeListEntry> entries = new List <MyAnimeListEntry>(); IEnumerable <XElement> animes = doc.Root.Elements("anime"); foreach (XElement anime in animes) { int animeId = GetElementValueInt(anime, "series_animedb_id"); string title = GetElementValueString(anime, "series_title"); string synonymList = GetElementValueString(anime, "series_synonyms"); string[] rawSynonyms = synonymList.Split(SynonymSeparator, StringSplitOptions.RemoveEmptyEntries); // filter out synonyms that are the same as the main title HashSet <string> synonyms = new HashSet <string>(rawSynonyms.Where(synonym => !synonym.Equals(title, StringComparison.Ordinal))); int seriesTypeInt = GetElementValueInt(anime, "series_type"); MalAnimeType seriesType = (MalAnimeType)seriesTypeInt; int numEpisodes = GetElementValueInt(anime, "series_episodes"); int seriesStatusInt = GetElementValueInt(anime, "series_status"); MalSeriesStatus seriesStatus = (MalSeriesStatus)seriesStatusInt; string seriesStartString = GetElementValueString(anime, "series_start"); UncertainDate seriesStart = UncertainDate.FromMalDateString(seriesStartString); string seriesEndString = GetElementValueString(anime, "series_end"); UncertainDate seriesEnd = UncertainDate.FromMalDateString(seriesEndString); string seriesImage = GetElementValueString(anime, "series_image"); MalAnimeInfoFromUserLookup animeInfo = new MalAnimeInfoFromUserLookup(animeId: animeId, title: title, type: seriesType, synonyms: synonyms, status: seriesStatus, numEpisodes: numEpisodes, startDate: seriesStart, endDate: seriesEnd, imageUrl: seriesImage); int numEpisodesWatched = GetElementValueInt(anime, "my_watched_episodes"); string myStartDateString = GetElementValueString(anime, "my_start_date"); UncertainDate myStartDate = UncertainDate.FromMalDateString(myStartDateString); string myFinishDateString = GetElementValueString(anime, "my_finish_date"); UncertainDate myFinishDate = UncertainDate.FromMalDateString(myFinishDateString); decimal rawScore = GetElementValueDecimal(anime, "my_score"); decimal?myScore = rawScore == 0 ? (decimal?)null : rawScore; int completionStatusInt = GetElementValueInt(anime, "my_status"); CompletionStatus completionStatus = (CompletionStatus)completionStatusInt; long lastUpdatedUnixTimestamp = GetElementValueLong(anime, "my_last_updated"); DateTime lastUpdated = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc) + TimeSpan.FromSeconds(lastUpdatedUnixTimestamp); string rawTagsString = GetElementValueString(anime, "my_tags"); string[] untrimmedTags = rawTagsString.Split(TagSeparator, StringSplitOptions.RemoveEmptyEntries); List <string> tags = new List <string>(untrimmedTags.Select(tag => tag.Trim())); MyAnimeListEntry entry = new MyAnimeListEntry(score: myScore, status: completionStatus, numEpisodesWatched: numEpisodesWatched, myStartDate: myStartDate, myFinishDate: myFinishDate, myLastUpdate: lastUpdated, animeInfo: animeInfo, tags: tags); entries.Add(entry); } MalUserLookupResults results = new MalUserLookupResults(userId: userId, canonicalUserName: canonicalUserName, animeList: entries); Logging.Log.Trace("Parsed XML."); return(results); }