commit c0b3067f1004563c8e14a7b0cbbccac699d4747d Author: Óscar M. Lage Date: Tue Oct 8 21:08:01 2024 +0200 Initial commit diff --git a/env.sample b/env.sample new file mode 100644 index 0000000..3dbe54b --- /dev/null +++ b/env.sample @@ -0,0 +1,14 @@ +# Secrets and API Keys +IMDB_API_KEY=your_imdb_api_key +IGDB_API_KEY=your_igdb_api_key +ISBNDB_API_KEY=your_isbndb_api_key +FANART_API_KEY=your_fanart_api_key +SPOTIFY_API_KEY=your_spotify_api_key + +# Ruta a los archivos de Obsidian +OBSIDIAN_YAML_PATH=/ruta/a/tu/vault/obsidian/ + +# Directorios +MARKDOWN_OUTPUT_DIR=output/markdown +IMAGES_OUTPUT_DIR=output/images +TEMPLATES_DIR=templates diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6a9a152 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module hugo-medialog + +go 1.21.4 + +require ( + github.com/joho/godotenv v1.5.1 + gopkg.in/yaml.v3 v3.0.1 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e536c30 --- /dev/null +++ b/go.sum @@ -0,0 +1,6 @@ +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/libros/controller.go b/internal/libros/controller.go new file mode 100644 index 0000000..e69de29 diff --git a/internal/libros/model.go b/internal/libros/model.go new file mode 100644 index 0000000..2d3ef90 --- /dev/null +++ b/internal/libros/model.go @@ -0,0 +1,17 @@ +package libros + +type Libro struct { + Title string `yaml:"title"` + Author string `yaml:"author"` + Link string `yaml:"link"` + Year int `yaml:"year"` + Rate float64 `yaml:"rate"` + Progress string `yaml:"progress"` + Image string `yaml:"image"` + Poster string `yaml:"poster-image"` + Background string `yaml:"background-image"` + Date string `yaml:"date"` + Tags []string +} + +type Libros []Libro diff --git a/internal/musica/controller.go b/internal/musica/controller.go new file mode 100644 index 0000000..e69de29 diff --git a/internal/musica/model.go b/internal/musica/model.go new file mode 100644 index 0000000..02ad56e --- /dev/null +++ b/internal/musica/model.go @@ -0,0 +1,16 @@ +package musica + +type Musica struct { + Title string `yaml:"title"` + Subtitle string `yaml:"subtitle"` + Link string `yaml:"link"` + Year int `yaml:"year"` + Rate float64 `yaml:"rate"` + Image string `yaml:"image"` + Poster string `yaml:"poster-image"` + Background string `yaml:"background-image"` + Date string `yaml:"date"` + Tags []string +} + +type Musicas []Musica diff --git a/internal/peliculas/controller.go b/internal/peliculas/controller.go new file mode 100644 index 0000000..d2f82e4 --- /dev/null +++ b/internal/peliculas/controller.go @@ -0,0 +1,64 @@ +// internal/peliculas/controller.go +package peliculas + +import ( + "fmt" + "hugo-medialog/utils" + "os" + "path/filepath" + + "gopkg.in/yaml.v3" +) + +func LoadPeliculas(obsidianPath string) ([]Pelicula, error) { + moviesFile := filepath.Join(obsidianPath, "pelis.yml.md") + fileData, err := os.ReadFile(moviesFile) + if err != nil { + return nil, err + } + + var peliculas []Pelicula + err = yaml.Unmarshal(fileData, &peliculas) + if err != nil { + return nil, err + } + + return peliculas, nil +} + +func ProcessPeliculas(peliculas []Pelicula) error { + for _, pelicula := range peliculas { + fmt.Printf("Título: %s, Puntuación: %.1f, Fecha: %s\n", + pelicula.Title, pelicula.Rate, pelicula.Date) + // Aquí se pueden hacer las llamadas a APIs externas (IMDb, Fanart.tv) + // y generar el markdown en base a las plantillas. + err := generatePeliculaMarkdown(pelicula) + if err != nil { + return err + } + } + return nil +} + +func generatePeliculaMarkdown(pelicula Pelicula) error { + templatePath := filepath.Join(os.Getenv("TEMPLATES_DIR"), "pelicula.md.tpl") + outputDir := os.Getenv("MARKDOWN_OUTPUT_DIR") + if err := utils.CreateDirIfNotExists(outputDir); err != nil { + return err + } + outputPath := filepath.Join(outputDir, fmt.Sprintf("%s.md", pelicula.Title)) + + data := map[string]interface{}{ + "Title": pelicula.Title, + "Link": "https://imdb.com/enlace", // Obtener el enlace de IMDb + "Subtitle": pelicula.Year, + "Year": pelicula.Year, + "Rate": pelicula.Rate, + "Image": pelicula.Image, + "Poster": pelicula.Poster, + "Background": pelicula.Background, + "Date": pelicula.Date, + } + + return utils.GenerateMarkdown(templatePath, outputPath, data) +} diff --git a/internal/peliculas/model.go b/internal/peliculas/model.go new file mode 100644 index 0000000..d481b90 --- /dev/null +++ b/internal/peliculas/model.go @@ -0,0 +1,16 @@ +package peliculas + +type Pelicula struct { + Title string `yaml:"title"` + Subtitle string `yaml:"subtitle"` + Link string `yaml:"link"` + Year int `yaml:"year"` + Rate float64 `yaml:"rate"` + Image string `yaml:"image"` + Poster string `yaml:"poster-image"` + Background string `yaml:"background-image"` + Date string `yaml:"date"` + Tags []string +} + +type Peliculas []Pelicula diff --git a/internal/series/controller.go b/internal/series/controller.go new file mode 100644 index 0000000..e69de29 diff --git a/internal/series/model.go b/internal/series/model.go new file mode 100644 index 0000000..b666aac --- /dev/null +++ b/internal/series/model.go @@ -0,0 +1,17 @@ +package series + +type Serie struct { + Title string `yaml:"title"` + Link string `yaml:"link"` + Subtitle string `yaml:"subtitle"` + Year int `yaml:"year"` + Rate float64 `yaml:"rate"` + Progress string `yaml:"progress"` + Image string `yaml:"image"` + Poster string `yaml:"poster-image"` + Background string `yaml:"background-image"` + Date string `yaml:"date"` + Tags []string +} + +type Series []Serie diff --git a/internal/videojuegos/controller.go b/internal/videojuegos/controller.go new file mode 100644 index 0000000..e69de29 diff --git a/internal/videojuegos/model.go b/internal/videojuegos/model.go new file mode 100644 index 0000000..83ccfa0 --- /dev/null +++ b/internal/videojuegos/model.go @@ -0,0 +1,17 @@ +package videojuegos + +type Videojuego struct { + Title string `yaml:"title"` + Link string `yaml:"link"` + Subtitle string `yaml:"subtitle"` + Year int `yaml:"year"` + Rate float64 `yaml:"rate"` + Progress string `yaml:"progress"` + Image string `yaml:"image"` + Poster string `yaml:"poster-image"` + Background string `yaml:"background-image"` + Date string `yaml:"date"` + Tags []string +} + +type Videojuegos []Videojuego diff --git a/main.go b/main.go new file mode 100644 index 0000000..e0c25b2 --- /dev/null +++ b/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "hugo-medialog/internal/peliculas" + "hugo-medialog/utils" + "os" +) + +func main() { + // Cargar el archivo .env + utils.LoadConfig() + + obsidianPath := os.Getenv("OBSIDIAN_YAML_PATH") + + // Peliculas + moviesList, err := peliculas.LoadPeliculas(obsidianPath) + if err != nil { + fmt.Printf("Error reading peliculas file: %v\n", err) + return + } + err = peliculas.ProcessPeliculas(moviesList) + if err != nil { + fmt.Printf("Error processing peliculas: %v\n", err) + } + +} diff --git a/obsidian/libros.yml.md b/obsidian/libros.yml.md new file mode 100644 index 0000000..b2fc066 --- /dev/null +++ b/obsidian/libros.yml.md @@ -0,0 +1,4 @@ +- title: "The Catcher in the Rye" + progress: "50%" + rate: 7.5 + date: 2024-10-08 diff --git a/obsidian/musica.yml.md b/obsidian/musica.yml.md new file mode 100644 index 0000000..0387bee --- /dev/null +++ b/obsidian/musica.yml.md @@ -0,0 +1,4 @@ +- title: "Random Access Memories" + spotify_id: "4m2880jivSbbyEGAKfITCa" + rate: 9.8 + date: 2024-10-08 diff --git a/obsidian/pelis.yml.md b/obsidian/pelis.yml.md new file mode 100644 index 0000000..1b75fd3 --- /dev/null +++ b/obsidian/pelis.yml.md @@ -0,0 +1,9 @@ +- title: "Inception" + imdb: + rate: 8.5 + date: 2024-10-08 + +- title: "Matrix" + imdb: + rate: 9.8 + date: "2024-10-08" diff --git a/obsidian/series.yml.md b/obsidian/series.yml.md new file mode 100644 index 0000000..81ab355 --- /dev/null +++ b/obsidian/series.yml.md @@ -0,0 +1,4 @@ +- title: "Breaking Bad" + progress: "10%" + rate: 9.2 + date: 2024-10-08 diff --git a/obsidian/videojuegos.yml.md b/obsidian/videojuegos.yml.md new file mode 100644 index 0000000..99ba718 --- /dev/null +++ b/obsidian/videojuegos.yml.md @@ -0,0 +1,4 @@ +- title: "The Legend of Zelda: Breath of the Wild" + progress: "40%" + rate: 9.8 + date: 2024-10-08 diff --git a/services/fanart.go b/services/fanart.go new file mode 100644 index 0000000..e69de29 diff --git a/services/igdb.go b/services/igdb.go new file mode 100644 index 0000000..e69de29 diff --git a/services/imdb.go b/services/imdb.go new file mode 100644 index 0000000..e69de29 diff --git a/services/isbndb.go b/services/isbndb.go new file mode 100644 index 0000000..e69de29 diff --git a/services/spotify.go b/services/spotify.go new file mode 100644 index 0000000..e69de29 diff --git a/templates/libro.md.tpl b/templates/libro.md.tpl new file mode 100644 index 0000000..50a5c55 --- /dev/null +++ b/templates/libro.md.tpl @@ -0,0 +1,23 @@ +--- +title: "{{ .Title }}" +link: "{{ .Link }}" +subtitle: "{{ .Subtitle }}" +author: "{{ .Author }}" +year: {{ .Year }} +rate: {{ .Rate }} +progress: {{ .Progress }} +image: {{ .Image }} +poster-image: {{ .PosterImage }} +background-image: {{ .BackgroundImage }} +date: {{ .Date }} +draft: false +tags: {{ .Tags }} +--- + +# {{ .Title }} + +## Overview + +{{ .Overview }} + +## My thoughts diff --git a/templates/musica.md.tpl b/templates/musica.md.tpl new file mode 100644 index 0000000..7c8938b --- /dev/null +++ b/templates/musica.md.tpl @@ -0,0 +1,21 @@ +--- +title: "{{ .Title }}" +link: "{{ .Link }}" +subtitle: "{{ .Subtitle }}" +year: {{ .Year }} +rate: {{ .Rate }} +image: {{ .Image }} +poster-image: {{ .PosterImage }} +background-image: {{ .BackgroundImage }} +date: {{ .Date }} +draft: false +tags: {{ .Tags }} +--- + +# {{ .Title }} + +## Overview + +{{ .Overview }} + +## My thoughts diff --git a/templates/pelicula.md.tpl b/templates/pelicula.md.tpl new file mode 100644 index 0000000..7c8938b --- /dev/null +++ b/templates/pelicula.md.tpl @@ -0,0 +1,21 @@ +--- +title: "{{ .Title }}" +link: "{{ .Link }}" +subtitle: "{{ .Subtitle }}" +year: {{ .Year }} +rate: {{ .Rate }} +image: {{ .Image }} +poster-image: {{ .PosterImage }} +background-image: {{ .BackgroundImage }} +date: {{ .Date }} +draft: false +tags: {{ .Tags }} +--- + +# {{ .Title }} + +## Overview + +{{ .Overview }} + +## My thoughts diff --git a/templates/serie.md.tpl b/templates/serie.md.tpl new file mode 100644 index 0000000..18514cd --- /dev/null +++ b/templates/serie.md.tpl @@ -0,0 +1,22 @@ +--- +title: "{{ .Title }}" +link: "{{ .Link }}" +subtitle: "{{ .Subtitle }}" +year: {{ .Year }} +rate: {{ .Rate }} +progress: {{ .Progress }} +image: {{ .Image }} +poster-image: {{ .PosterImage }} +background-image: {{ .BackgroundImage }} +date: {{ .Date }} +draft: false +tags: {{ .Tags }} +--- + +# {{ .Title }} + +## Overview + +{{ .Overview }} + +## My thoughts diff --git a/templates/videojuego.md.tpl b/templates/videojuego.md.tpl new file mode 100644 index 0000000..18514cd --- /dev/null +++ b/templates/videojuego.md.tpl @@ -0,0 +1,22 @@ +--- +title: "{{ .Title }}" +link: "{{ .Link }}" +subtitle: "{{ .Subtitle }}" +year: {{ .Year }} +rate: {{ .Rate }} +progress: {{ .Progress }} +image: {{ .Image }} +poster-image: {{ .PosterImage }} +background-image: {{ .BackgroundImage }} +date: {{ .Date }} +draft: false +tags: {{ .Tags }} +--- + +# {{ .Title }} + +## Overview + +{{ .Overview }} + +## My thoughts diff --git a/utils/config.go b/utils/config.go new file mode 100644 index 0000000..0760cf8 --- /dev/null +++ b/utils/config.go @@ -0,0 +1,31 @@ +package utils + +import ( + "io/ioutil" + "log" + "path/filepath" + + "github.com/joho/godotenv" +) + +func LoadConfig() { + err := godotenv.Load() + if err != nil { + log.Fatal("Error loading .env file") + } +} + +func ReadFiles(dir string) ([]string, error) { + files, err := ioutil.ReadDir(dir) + if err != nil { + return nil, err + } + + var filePaths []string + for _, file := range files { + if !file.IsDir() && filepath.Ext(file.Name()) == ".md" { + filePaths = append(filePaths, filepath.Join(dir, file.Name())) + } + } + return filePaths, nil +} diff --git a/utils/file_reader.go b/utils/file_reader.go new file mode 100644 index 0000000..d20055f --- /dev/null +++ b/utils/file_reader.go @@ -0,0 +1,25 @@ +// utils/file_reader.go +package utils + +import ( + "fmt" + "io/ioutil" + + "gopkg.in/yaml.v3" +) + +// Función para leer el archivo YAML +func ReadYMLFile(filePath string, out interface{}) error { + data, err := ioutil.ReadFile(filePath) + if err != nil { + return fmt.Errorf("error al leer el archivo %s: %v", filePath, err) + } + + // Deserializar el contenido YAML en la estructura Go pasada en "out" + err = yaml.Unmarshal(data, out) + if err != nil { + return fmt.Errorf("error al deserializar el archivo %s: %v", filePath, err) + } + + return nil +} diff --git a/utils/utils.go b/utils/utils.go new file mode 100644 index 0000000..af2cc6e --- /dev/null +++ b/utils/utils.go @@ -0,0 +1,30 @@ +// utils/utils.go +package utils + +import ( + "bytes" + "os" + "text/template" +) + +func CreateDirIfNotExists(dir string) error { + if _, err := os.Stat(dir); os.IsNotExist(err) { + return os.MkdirAll(dir, 0755) + } + return nil +} + +func GenerateMarkdown(templatePath string, outputPath string, data map[string]interface{}) error { + tmpl, err := template.ParseFiles(templatePath) + if err != nil { + return err + } + + var output bytes.Buffer + err = tmpl.Execute(&output, data) + if err != nil { + return err + } + + return os.WriteFile(outputPath, output.Bytes(), 0644) +}