[htmlgrab] Added support for base64 images

This commit is contained in:
Pijus Kamandulis
2021-06-09 19:07:07 +03:00
parent 01f7879f7e
commit 38f9cdeb09
5 changed files with 95 additions and 14 deletions

View File

@@ -30,14 +30,23 @@ func HtmlGrab(htmlStr string, itemOutputDir string) {
// For each item found, get the title
val, exists := s.Attr("src")
if exists {
imageName := helpers.RemoveGetParams(filepath.Base(val))
itemImagePath := outputDir + "/" + imageName
helpers.LogInfo("Downloading image to " + itemImagePath)
fileio.DownloadFile(
itemImagePath,
val)
imageName := "#"
if strings.Contains(val, "base64") {
imageName = fileio.SaveFromBase64(val, outputDir)
} else {
imageName = helpers.RemoveGetParams(filepath.Base(val))
itemImagePath := outputDir + "/" + imageName
helpers.LogInfo("Downloading image to " + itemImagePath)
err = fileio.DownloadFile(
itemImagePath,
val)
fmt.Printf("[htmlgrab] %d: %s\n", i, val)
if err != nil {
fmt.Printf("[htmlgrab] %d: failed to get %s\n", i, val)
} else {
fmt.Printf("[htmlgrab] %d: %s\n", i, val)
}
}
s.SetAttr("src", imageName)
}