NoppesTheFolf / E621Client

.NET Standard wrapper for the e621 API.
MIT License
9 stars 1 forks source link

Support has_notes and duration in Post/IqdbPost #16

Open Jdbye opened 1 year ago

Jdbye commented 1 year ago

Noticed these two are in the JSON data, but not exposed in the data types. Interestingly enough, they aren't documented on the wiki either.

Simple change in Post.cs:

        /// <summary>
        /// Whether the post has notes associated with it.
        /// </summary>
        [JsonProperty("has_notes")]
        public bool HasNotes { get; set; }

        /// <summary>
        /// The duration of the post, if it is a video, or null otherwise
        /// </summary>
        [JsonProperty("duration")]
        public double? Duration { get; set; }

IqdbPost.cs is a bit more complicated. has_notes is not there, but we have another thing instead which we can use which does not exist in normal posts, namely last_noted_at:

        [JsonProperty("last_noted_at")]
        public DateTimeOffset? LastNotedAt;

        [JsonProperty("duration")]
        public double? Duration { get; set; }

And in AsPost():

                HasNotes = LastNotedAt != null,
                Duration = Duration

I've tested these changes and they seem to work fine and the behavior corresponds with what is expected. There is the possibility of a post having a note added and later deleted, resulting in last_noted_at being set even though the post does not currently have any notes, so IqdbPost wrongly assumes the post has notes. This is probably fairly rare though and not a high priority issue. It might not even be an issue, if last_noted_at is simply fetched from the latest note added rather than being a fixed field in the database.

On a side note, it is a shame that some of the post information is not available through the API. Things like uploader name, deleted by, deleted reason, notes. Notes are used for translations and the usefulness of the others is self explanatory. These are not available through the database exports either (presumably they live in separate databases which are not exported)

Edit: Noticed Duration is there in DbExportPost, but gets converted to TimeSpan. So for consistency, best to do the same here, I suppose.