package music import ( "fmt" "hugo-medialog/utils" "os" "path/filepath" "gopkg.in/yaml.v2" ) func LoadAlbums() ([]Album, error) { albumsFile := os.Getenv("OBSIDIAN_MUSIC_FILE") fileData, err := os.ReadFile(albumsFile) if err != nil { return nil, err } var albums []Album err = yaml.Unmarshal(fileData, &albums) if err != nil { return nil, err } return albums, nil } func ProcessAlbum(albumList []Album) error { for _, album := range albumList { fmt.Printf("Title: %s\n", album.Title) // If we dont have ID, search album by Title and get the ID if album.ID == "" { err := SearchAlbumByTitle(album.Title, &album) if err != nil { fmt.Printf("Error searching album by title %s: %s\n", album.Title, err) continue } } album.Slug = utils.Sluggify(album.Title) // Now we need to get the image if album.Image != "" { err := DownloadImage(album.Image, album.Slug) if err != nil { fmt.Printf("Error downloading %s: %s\n", album.Image, err) } } album.Image = fmt.Sprintf("%s.jpg", album.Slug) err := generateAlbumMarkdown(album) if err != nil { return err } utils.Sep() } return nil } func generateAlbumMarkdown(album Album) error { templatePath := filepath.Join(os.Getenv("TEMPLATES_DIR"), "music.md.tpl") outputDir := os.Getenv("MARKDOWN_OUTPUT_MUSIC_DIR") if err := utils.CreateDirIfNotExists(outputDir); err != nil { return err } outputPath := filepath.Join(outputDir, fmt.Sprintf("%s.md", album.Slug)) data := map[string]interface{}{ "Title": album.Title, "Artist": album.Artist, "Link": album.Link, "Subtitle": album.Year, "Year": album.Year, "Rate": album.Rate, "Tracks": album.Tracks, "Image": album.Image, "Date": album.Date, "Tags": "listening", } return utils.GenerateMarkdown(templatePath, outputPath, data) }