|
|
@ -33,7 +33,7 @@ func Download(link string, episodeTitle string, podcastName string, prefix strin
|
|
|
|
if prefix != "" {
|
|
|
|
if prefix != "" {
|
|
|
|
fileName = fmt.Sprintf("%s-%s", prefix, fileName)
|
|
|
|
fileName = fmt.Sprintf("%s-%s", prefix, fileName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
folder := createIfFoldeDoesntExist(podcastName)
|
|
|
|
folder := createDataFolderIfNotExists(podcastName)
|
|
|
|
finalPath := path.Join(folder, fileName)
|
|
|
|
finalPath := path.Join(folder, fileName)
|
|
|
|
|
|
|
|
|
|
|
|
if _, err := os.Stat(finalPath); !os.IsNotExist(err) {
|
|
|
|
if _, err := os.Stat(finalPath); !os.IsNotExist(err) {
|
|
|
@ -85,7 +85,7 @@ func FileExists(filePath string) bool {
|
|
|
|
|
|
|
|
|
|
|
|
func GetAllBackupFiles() ([]string, error) {
|
|
|
|
func GetAllBackupFiles() ([]string, error) {
|
|
|
|
var files []string
|
|
|
|
var files []string
|
|
|
|
folder := createIfFoldeDoesntExist("backups")
|
|
|
|
folder := createConfigFolderIfNotExists("backups")
|
|
|
|
err := filepath.Walk(folder, func(path string, info os.FileInfo, err error) error {
|
|
|
|
err := filepath.Walk(folder, func(path string, info os.FileInfo, err error) error {
|
|
|
|
if !info.IsDir() {
|
|
|
|
if !info.IsDir() {
|
|
|
|
files = append(files, path)
|
|
|
|
files = append(files, path)
|
|
|
@ -115,7 +115,7 @@ func deleteOldBackup() {
|
|
|
|
func CreateBackup() (string, error) {
|
|
|
|
func CreateBackup() (string, error) {
|
|
|
|
|
|
|
|
|
|
|
|
backupFileName := "podgrab_backup_" + time.Now().Format("2006.01.02_150405") + ".tar.gz"
|
|
|
|
backupFileName := "podgrab_backup_" + time.Now().Format("2006.01.02_150405") + ".tar.gz"
|
|
|
|
folder := createIfFoldeDoesntExist("backups")
|
|
|
|
folder := createConfigFolderIfNotExists("backups")
|
|
|
|
configPath := os.Getenv("CONFIG")
|
|
|
|
configPath := os.Getenv("CONFIG")
|
|
|
|
tarballFilePath := path.Join(folder, backupFileName)
|
|
|
|
tarballFilePath := path.Join(folder, backupFileName)
|
|
|
|
file, err := os.Create(tarballFilePath)
|
|
|
|
file, err := os.Create(tarballFilePath)
|
|
|
@ -184,11 +184,10 @@ func httpClient() *http.Client {
|
|
|
|
return &client
|
|
|
|
return &client
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func createIfFoldeDoesntExist(folder string) string {
|
|
|
|
func createFolder(folder string, parent string) string {
|
|
|
|
str := stringy.New(folder)
|
|
|
|
str := stringy.New(folder)
|
|
|
|
folder = str.RemoveSpecialCharacter()
|
|
|
|
folder = str.RemoveSpecialCharacter()
|
|
|
|
dataPath := os.Getenv("DATA")
|
|
|
|
folderPath := path.Join(parent, folder)
|
|
|
|
folderPath := path.Join(dataPath, folder)
|
|
|
|
|
|
|
|
if _, err := os.Stat(folderPath); os.IsNotExist(err) {
|
|
|
|
if _, err := os.Stat(folderPath); os.IsNotExist(err) {
|
|
|
|
os.MkdirAll(folderPath, 0777)
|
|
|
|
os.MkdirAll(folderPath, 0777)
|
|
|
|
changeOwnership(folderPath)
|
|
|
|
changeOwnership(folderPath)
|
|
|
@ -196,6 +195,15 @@ func createIfFoldeDoesntExist(folder string) string {
|
|
|
|
return folderPath
|
|
|
|
return folderPath
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func createDataFolderIfNotExists(folder string) string {
|
|
|
|
|
|
|
|
dataPath := os.Getenv("DATA")
|
|
|
|
|
|
|
|
return createFolder(dataPath, folder)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func createConfigFolderIfNotExists(folder string) string {
|
|
|
|
|
|
|
|
dataPath := os.Getenv("CONFIG")
|
|
|
|
|
|
|
|
return createFolder(dataPath, folder)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func getFileName(link string, title string, defaultExtension string) string {
|
|
|
|
func getFileName(link string, title string, defaultExtension string) string {
|
|
|
|
fileUrl, err := url.Parse(link)
|
|
|
|
fileUrl, err := url.Parse(link)
|
|
|
|
checkError(err)
|
|
|
|
checkError(err)
|
|
|
|