M cmd/archive.go => cmd/archive.go +5 -2
@@ 58,8 58,9 @@ func implArchive(dname string, driver libgallery.Driver, query string, limit uin
log.Fatal(err)
}
+ defer files.Close()
+
for i, j := range files {
- defer j.Close()
filename := fmt.Sprintf("%s_%v", v.ID, i)
file, err := os.Create(filename)
if err != nil {
@@ 71,7 72,7 @@ func implArchive(dname string, driver libgallery.Driver, query string, limit uin
log.Fatal(err)
}
- file.Close()
+ defer file.Close()
mime, err := mimetype.DetectFile(filename)
if err != nil {
@@ 84,6 85,8 @@ func implArchive(dname string, driver libgallery.Driver, query string, limit uin
}
}
+
+ files.Close()
}
i++
M cmd/search.go => cmd/search.go +0 -1
@@ 45,7 45,6 @@ func implSearch(impl libgallery.Driver, query string, limit uint64) {
if onlyids {
fmt.Println(v.ID)
} else {
-
if onlyids {
fmt.Println(v.ID)
} else {
M drivers/danbooru/implementation.go => drivers/danbooru/implementation.go +1 -4
@@ 73,10 73,9 @@ func (i *implementation) Search(query string, page uint64) ([]libgallery.Post, e
}
return posts, err
-
}
-func (i *implementation) File(id string) ([]io.ReadCloser, error) {
+func (i *implementation) File(id string) (libgallery.Files, error) {
const reqbase = "https://%s/posts/%v.json"
url := fmt.Sprintf(reqbase, i.host, id)
@@ 92,7 91,6 @@ func (i *implementation) File(id string) ([]io.ReadCloser, error) {
}
return []io.ReadCloser{rc}, nil
-
}
func (i *implementation) Comments(id string) ([]libgallery.Comment, error) {
@@ 123,7 121,6 @@ func (i *implementation) Comments(id string) ([]libgallery.Comment, error) {
}
return comments, err
-
}
func (i *implementation) Name() string {
M drivers/e621/implementation.go => drivers/e621/implementation.go +1 -3
@@ 75,10 75,9 @@ func (i *implementation) Search(query string, page uint64) ([]libgallery.Post, e
}
return libposts, err
-
}
-func (i *implementation) File(id string) ([]io.ReadCloser, error) {
+func (i *implementation) File(id string) (libgallery.Files, error) {
const reqbase = "https://e621.net/posts/%s.json"
url := fmt.Sprintf(reqbase, id)
@@ 96,7 95,6 @@ func (i *implementation) File(id string) ([]io.ReadCloser, error) {
}
return []io.ReadCloser{filereader}, nil
-
}
// No API access, will need to implement scraping.
M drivers/rule34/implementation.go => drivers/rule34/implementation.go +1 -3
@@ 75,10 75,9 @@ func (i *implementation) Search(query string, page uint64) ([]libgallery.Post, e
}
return posts, err
-
}
-func (i *implementation) File(id string) ([]io.ReadCloser, error) {
+func (i *implementation) File(id string) (libgallery.Files, error) {
const reqbase = "https://api.rule34.xxx/index.php?page=dapi&s=post&q=index&id="
var response searchResponse
@@ 98,7 97,6 @@ func (i *implementation) File(id string) ([]io.ReadCloser, error) {
}
return []io.ReadCloser{rc}, nil
-
}
func (i *implementation) Name() string {
M interface.go => interface.go +9 -2
@@ 18,7 18,7 @@ type Driver interface {
// If a booru doesn't support it you will need to
// transmogrify the query.
Search(string, uint64) ([]Post, error) // Tags, and page number.
- File(string) ([]io.ReadCloser, error) // Fetches a file with a given ID.
+ File(string) (Files, error) // Fetches a file with a given ID.
Comments(string) ([]Comment, error) // Fetches the comments from a given ID.
}
@@ 39,7 39,14 @@ type Post struct {
Score int64 `json:"score"`
}
-//
+type Files []io.ReadCloser
+
+func (f *Files) Close() {
+ for _, v := range *f {
+ v.Close()
+ }
+}
+
type Comment struct {
Author string `json:"author"`
Body string `json:"body"`