52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"go.senan.xyz/taglib"
|
|
)
|
|
|
|
func getPodcastCover(imageUrl string) ([]byte, error) {
|
|
resp, err := http.Get(imageUrl)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to fetch podcast cover image: %v", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
data, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to read image data from response: %v", err)
|
|
}
|
|
|
|
return data, nil
|
|
}
|
|
|
|
func appendPodcastMetadata(filePath string, feedItem RSSFeedItem, episodeNumber int, podcast Podcast) error {
|
|
if err := taglib.WriteTags(filePath, map[string][]string{
|
|
taglib.Artist: {podcast.Name},
|
|
taglib.AlbumArtist: {podcast.Name},
|
|
taglib.Album: {podcast.Name},
|
|
taglib.TrackNumber: {strconv.Itoa(episodeNumber)},
|
|
taglib.Podcast: {podcast.Name},
|
|
taglib.PodcastURL: {podcast.Link},
|
|
taglib.PodcastDesc: {podcast.Description},
|
|
taglib.Title: {feedItem.Title},
|
|
}, 0); err != nil {
|
|
return fmt.Errorf("failed to append tags: %v", err)
|
|
}
|
|
|
|
imgData, err := getPodcastCover(podcast.Image)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to fetch podcast cover: %v", err)
|
|
}
|
|
|
|
if err := taglib.WriteImage(filePath, imgData); err != nil {
|
|
return fmt.Errorf("failed to append cover image: %v", err)
|
|
}
|
|
|
|
return nil
|
|
}
|