Skip to content

Commit

Permalink
basic mp3 enclosures working
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoKats committed Aug 31, 2024
1 parent a4753a1 commit 5e2d43b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.xml
config.json
*.mp3
51 changes: 51 additions & 0 deletions lib/filesize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package lib

import (
"strconv"
"unicode"
"strings"
"os/exec"
"os"
)

func extractInt(text string) int {
filteredString := ""
for _, character := range text {
if unicode.IsDigit(character) {
filteredString += string(character)
}
}
integer, convErr := strconv.Atoi(filteredString)
if convErr != nil {
Error.Println(convErr)
return 1
} else {
return integer
}
}

func FileSizeLocal(filename string) int {
fileInfo, fileErr := os.Stat(filename)
if fileErr != nil {
Error.Println(fileErr)
return 1
}
return int(fileInfo.Size())
}

func FileSizeUrl(url string) int {
cmd := exec.Command("curl", "-sIL", url)
cmdOutput, cmdErr := cmd.Output()
if cmdErr != nil {
Error.Println(cmdErr)
return 1
} else {
for _, line := range strings.Split(string(cmdOutput), "\n") {
if strings.Contains(line, "content-length") {
return extractInt(line)
}
}
}
Error.Printf("No content-length found for %s", url)
return 1
}
9 changes: 8 additions & 1 deletion lib/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func convertMarkdownLink(text string, markdownLinks *regexp.Regexp) string {
return "<p>" + markdownLinks.ReplaceAllString(text, "<a href='$2'>$1</a>") + "</p>"
}

func convertMarkdownEnclosure(text string, markdownLinks *regexp.Regexp) string {
return "<enclosure " + markdownLinks.ReplaceAllString(text, "url='$2' type='$1'") + " />"
}

func convertMarkdownList(text string) string {
if !markdownListActive {
markdownListActive = true
Expand All @@ -42,6 +46,9 @@ func convertMarkdownList(text string) string {
func ConvertMarkdownToRSS(text string) string {
markdownLinks := regexp.MustCompile(`\[(.*)\]\((.*)\)`)
markdownLists := regexp.MustCompile(`^(\s*)(-|\*|\+)(.*)`)
if markdownLinks.Match([]byte(text)) && strings.Contains(text, "audio/mpeg") {
return convertMarkdownEnclosure(text, markdownLinks)
}
if markdownLinks.Match([]byte(text)) {
return convertMarkdownLink(text, markdownLinks)
}
Expand All @@ -59,7 +66,7 @@ func GetArticles(config Config) ([]Article, error) {
articles := []Article{}
if fileErr == nil {
for _, file := range RawArticles {
if !file.IsDir() && !strings.HasPrefix(file.Name(), "draft-") {
if !file.IsDir() && !strings.HasPrefix(file.Name(), "draft-") && strings.HasSuffix(file.Name(), ".md") {
var article Article
fileInfo, _ := file.Info()
article.Filename = file.Name()
Expand Down
2 changes: 2 additions & 0 deletions test/another-article.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

Hi all. I've added my public PGP key to the files section of this website. It's linked to my main e-mail address (hello[at]timokats[dot]xyz).

[audio/mpeg](https://www.native-instruments.com/fileadmin/ni_media/producer/koresoundpack/fm8transientattacks/audio/1_FM8ROXXS.mp3)

Note, for me it's not a hard requirement to use it when sending me an email. In fact, it's mainly there for those that prefer/require encrypted correspondence when contacting me.

Timo
Expand Down

0 comments on commit 5e2d43b

Please sign in to comment.