Add releaseDate attr to music struct

This commit is contained in:
Óscar M. Lage 2024-12-17 14:30:33 +01:00
parent 80b872d6e9
commit 0929e681ce
4 changed files with 29 additions and 26 deletions

View File

@ -102,8 +102,8 @@ func SearchAlbumByTitle(title string, album *Album) error {
album.Artist = track["artists"].([]interface{})[0].(map[string]interface{})["name"].(string) album.Artist = track["artists"].([]interface{})[0].(map[string]interface{})["name"].(string)
album.ID = albumData["id"].(string) album.ID = albumData["id"].(string)
album.Album = albumData["name"].(string) album.Album = albumData["name"].(string)
album.Date = albumData["release_date"].(string) album.ReleaseDate = albumData["release_date"].(string)
album.Year, _ = strconv.Atoi(strings.Split(album.Date, "-")[0]) album.Year, _ = strconv.Atoi(strings.Split(album.ReleaseDate, "-")[0])
album.Subtitle = strconv.Itoa(album.Year) album.Subtitle = strconv.Itoa(album.Year)
album.Tracks = int(albumData["total_tracks"].(float64)) // Spotify envía números como float64 album.Tracks = int(albumData["total_tracks"].(float64)) // Spotify envía números como float64
album.Link = albumData["href"].(string) album.Link = albumData["href"].(string)

View File

@ -90,16 +90,17 @@ func generateAlbumMarkdown(album Album) error {
outputPath := filepath.Join(outputDir, fmt.Sprintf("%s.md", album.Slug)) outputPath := filepath.Join(outputDir, fmt.Sprintf("%s.md", album.Slug))
data := map[string]interface{}{ data := map[string]interface{}{
"Title": album.Title, "Title": album.Title,
"Artist": album.Artist, "Artist": album.Artist,
"Link": album.Link, "Link": album.Link,
"Subtitle": album.Year, "Subtitle": album.Year,
"Year": album.Year, "Year": album.Year,
"Rate": album.Rate, "Rate": album.Rate,
"Tracks": album.Tracks, "Tracks": album.Tracks,
"Image": album.Image, "Image": album.Image,
"Date": album.Date, "Date": album.Date,
"Tags": "listening", "ReleaseDate": album.ReleaseDate,
"Tags": "listening",
} }
return utils.GenerateMarkdown(templatePath, outputPath, data) return utils.GenerateMarkdown(templatePath, outputPath, data)

View File

@ -1,20 +1,21 @@
package music package music
type Album struct { type Album struct {
Title string `yaml:"title"` Title string `yaml:"title"`
Artist string `yaml:"artist"` Artist string `yaml:"artist"`
Album string `yaml:"album"` Album string `yaml:"album"`
Slug string `yaml:"slug"` Slug string `yaml:"slug"`
ID string `yaml:"spotify_id"` ID string `yaml:"spotify_id"`
Subtitle string `yaml:"subtitle"` Subtitle string `yaml:"subtitle"`
Link string `yaml:"link"` Link string `yaml:"link"`
Year int `yaml:"year"` Year int `yaml:"year"`
Rate float64 `yaml:"rate"` Rate float64 `yaml:"rate"`
Tracks int `yaml:"tracks"` Tracks int `yaml:"tracks"`
Image string `yaml:"image"` Image string `yaml:"image"`
Date string `yaml:"date"` ReleaseDate string `yaml:"release_date"`
New bool `yaml:"new"` Date string `yaml:"date"`
Tags []string New bool `yaml:"new"`
Tags []string
} }
type Albums []Album type Albums []Album

View File

@ -11,6 +11,7 @@ image640: {{ imageSize .Image "640" }}
image1024: {{ imageSize .Image "1024" }} image1024: {{ imageSize .Image "1024" }}
tracks: {{ .Tracks }} tracks: {{ .Tracks }}
date: {{ .Date }} date: {{ .Date }}
release_date: {{ .ReleaseDate }}
draft: false draft: false
tags: {{ .Tags }} tags: {{ .Tags }}
--- ---