-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* basic mp3 enclosures working * add tests and update README
- Loading branch information
Showing
6 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.xml | ||
config.json | ||
*.mp3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package lib | ||
|
||
import ( | ||
"unicode" | ||
"strings" | ||
"os/exec" | ||
"errors" | ||
) | ||
|
||
func extractInt(text string) string { | ||
filteredString := "" | ||
for _, character := range text { | ||
if unicode.IsDigit(character) { | ||
filteredString += string(character) | ||
} | ||
} | ||
if len(filteredString) == 0 { | ||
return "1" | ||
} else { | ||
return filteredString | ||
} | ||
} | ||
|
||
func FileSizeUrl(url string) (string, error) { | ||
cmd := exec.Command("curl", "-sIL", url) | ||
cmdOutput, cmdErr := cmd.Output() | ||
if cmdErr != nil { | ||
return "1", errors.New("Issues when running curl to get filesize.") | ||
} else { | ||
for _, line := range strings.Split(string(cmdOutput), "\n") { | ||
if strings.Contains(line, "content-length") { | ||
return extractInt(line), nil | ||
} | ||
} | ||
} | ||
return "1", errors.New("No content-length found for url") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters