mirror of https://github.com/pikami/rss-dl.git
Remove HTTP GET params from saving file path
This commit is contained in:
parent
63d39f225e
commit
881f1aec48
|
@ -3,6 +3,7 @@ package helpers
|
|||
import (
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ToCleanString - replaces spaces with underscores
|
||||
|
@ -13,3 +14,8 @@ func ToCleanString(str string) string {
|
|||
}
|
||||
return reg.ReplaceAllString(str, "_")
|
||||
}
|
||||
|
||||
// RemoveGetParams - removes http GET params
|
||||
func RemoveGetParams(str string) string {
|
||||
return strings.Split(str, "?")[0]
|
||||
}
|
||||
|
|
7
main.go
7
main.go
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
. "./fileio"
|
||||
. "./helpers"
|
||||
|
@ -26,7 +25,7 @@ func main() {
|
|||
LogInfo("Writing feed details as JSON to " + feedInfoPath)
|
||||
WriteToFile(feedInfoPath, GrabFeedDetailsJSON(feed))
|
||||
|
||||
feedImagePath := outputDir + "/image" + filepath.Ext(feed.Image.URL)
|
||||
feedImagePath := outputDir + "/image" + RemoveGetParams(filepath.Ext(feed.Image.URL))
|
||||
DownloadFile(feedImagePath, feed.Image.URL)
|
||||
|
||||
for _, item := range feed.Items {
|
||||
|
@ -48,14 +47,14 @@ func main() {
|
|||
itemDetailsPath,
|
||||
GrabFeedItemJSON(item))
|
||||
|
||||
itemImagePath := itemOutputDir + "/image" + filepath.Ext(item.Image.URL)
|
||||
itemImagePath := itemOutputDir + "/image" + RemoveGetParams(filepath.Ext(item.Image.URL))
|
||||
LogInfo("Downloading image to " + itemImagePath)
|
||||
DownloadFile(
|
||||
itemImagePath,
|
||||
item.Image.URL)
|
||||
|
||||
for _, enclosure := range item.Enclosures {
|
||||
filename := strings.Split(filepath.Base(enclosure.URL), "?")[0]
|
||||
filename := RemoveGetParams(filepath.Base(enclosure.URL))
|
||||
LogInfo("Downloading attachment '" + filename + "'")
|
||||
DownloadFile(
|
||||
itemOutputDir+"/"+filename,
|
||||
|
|
Loading…
Reference in New Issue