From 513aefd555393f641be9c2d6bce39c8beb669e34 Mon Sep 17 00:00:00 2001 From: the TV Date: Sat, 21 Dec 2019 14:22:35 +0200 Subject: [PATCH 1/2] fix(announcelist is an array not a string) --- reply.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/reply.go b/reply.go index b6f228a..3f7b10f 100644 --- a/reply.go +++ b/reply.go @@ -43,10 +43,10 @@ type StatusInfo struct { Dir string `json:"dir"` // Directory to save files. Files []FileInfo `json:"files"` // Returns the list of files. The elements of this list are the same structs used in aria2.getFiles() method. BitTorrent struct { - AnnounceList string `json:"announceList"` // List of lists of announce URIs. If the torrent contains announce and no announce-list, announce is converted to the announce-list format. - Comment string `json:"comment"` // The comment of the torrent. comment.utf-8 is used if available. - CreationDate string `json:"creationDate"` // The creation time of the torrent. The value is an integer since the epoch, measured in seconds. - Mode string `json:"mode"` // File mode of the torrent. The value is either single or multi. + AnnounceList []string `json:"announceList"` // List of lists of announce URIs. If the torrent contains announce and no announce-list, announce is converted to the announce-list format. + Comment string `json:"comment"` // The comment of the torrent. comment.utf-8 is used if available. + CreationDate string `json:"creationDate"` // The creation time of the torrent. The value is an integer since the epoch, measured in seconds. + Mode string `json:"mode"` // File mode of the torrent. The value is either single or multi. Info struct { Name string `json:"name"` // name in info dictionary. name.utf-8 is used if available. } `json:"info"` // Struct which contains data from Info dictionary. It contains following keys. From 402a30c5502df5016613558140644cb98ee0f77c Mon Sep 17 00:00:00 2001 From: the TV Date: Sun, 22 Dec 2019 21:19:35 +0200 Subject: [PATCH 2/2] fix(StatusInfo): AnnounceList may be a string or a slice of slices of string --- reply.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/reply.go b/reply.go index 3f7b10f..9d02d75 100644 --- a/reply.go +++ b/reply.go @@ -1,5 +1,9 @@ package argo +import ( + "encoding/json" +) + // GIDwithID contains the GID and the ID of the affected download. type GIDwithID struct { GID GID @@ -43,16 +47,32 @@ type StatusInfo struct { Dir string `json:"dir"` // Directory to save files. Files []FileInfo `json:"files"` // Returns the list of files. The elements of this list are the same structs used in aria2.getFiles() method. BitTorrent struct { - AnnounceList []string `json:"announceList"` // List of lists of announce URIs. If the torrent contains announce and no announce-list, announce is converted to the announce-list format. - Comment string `json:"comment"` // The comment of the torrent. comment.utf-8 is used if available. - CreationDate string `json:"creationDate"` // The creation time of the torrent. The value is an integer since the epoch, measured in seconds. - Mode string `json:"mode"` // File mode of the torrent. The value is either single or multi. + AnnounceList []AnnounceList `json:"announceList"` // List of lists of announce URIs. If the torrent contains announce and no announce-list, announce is converted to the announce-list format. + Comment string `json:"comment"` // The comment of the torrent. comment.utf-8 is used if available. + CreationDate string `json:"creationDate"` // The creation time of the torrent. The value is an integer since the epoch, measured in seconds. + Mode string `json:"mode"` // File mode of the torrent. The value is either single or multi. Info struct { Name string `json:"name"` // name in info dictionary. name.utf-8 is used if available. } `json:"info"` // Struct which contains data from Info dictionary. It contains following keys. } `json:"bittorrent"` // Struct which contains information retrieved from the .torrent (file). BitTorrent only. It contains following keys. } +type AnnounceList []string + +func (a *AnnounceList) UnmarshalJSON(b []byte) error { + var sa []string + if err := json.Unmarshal(b, &sa); err == nil { + *a = append(*a, sa...) + return nil + } + var s string + if err := json.Unmarshal(b, &s); err != nil { + return err + } + *a = AnnounceList{s} + return nil +} + // URIInfo represents an element of response of aria2.getUris type URIInfo struct { URI string `json:"uri"` // URI