main
Óscar M. Lage 2024-10-09 11:12:44 +02:00
parent d5cc40c0db
commit 16b7e40a6a
26 changed files with 103 additions and 89 deletions

View File

@ -5,10 +5,14 @@ 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/
# PATH to Obisdian files where the information is
OBSIDIAN_BOOKS_FILE=/path/to/your/obsidian/books.yml.md
OBSIDIAN_GAMES_FILE=/path/to/your/obsidian/games.yml.md
OBSIDIAN_MOVIES_FILE=/path/to/your/obsidian/movies.yml.md
OBSIDIAN_MUSIC_FILE=/path/to/your/obsidian/music.yml.md
OBSIDIAN_SERIES_FILE=/path/to/your/obsidian/series.yml.md
# Directorios
# Other directories
MARKDOWN_OUTPUT_DIR=output/markdown
IMAGES_OUTPUT_DIR=output/images
TEMPLATES_DIR=templates

View File

@ -0,0 +1,2 @@
// internal/books/controller.go

View File

@ -1,6 +1,7 @@
package libros
// internal/books/model.go
package books
type Libro struct {
type Book struct {
Title string `yaml:"title"`
Author string `yaml:"author"`
Link string `yaml:"link"`
@ -14,4 +15,4 @@ type Libro struct {
Tags []string
}
type Libros []Libro
type Books []Book

View File

@ -0,0 +1,2 @@
// internal/games/controller.go

View File

@ -1,6 +1,7 @@
package videojuegos
// internal/games/model.go
package games
type Videojuego struct {
type Game struct {
Title string `yaml:"title"`
Link string `yaml:"link"`
Subtitle string `yaml:"subtitle"`
@ -14,4 +15,4 @@ type Videojuego struct {
Tags []string
}
type Videojuegos []Videojuego
type Games []Game

View File

@ -0,0 +1,63 @@
// internal/movies/controller.go
package movies
import (
"fmt"
"hugo-medialog/utils"
"os"
"path/filepath"
"gopkg.in/yaml.v3"
)
func LoadMovies() ([]Movie, error) {
moviesFile := os.Getenv("OBSIDIAN_MOVIES_FILE")
fileData, err := os.ReadFile(moviesFile)
if err != nil {
return nil, err
}
var movies []Movie
err = yaml.Unmarshal(fileData, &movies)
if err != nil {
return nil, err
}
return movies, nil
}
func ProcessMovies(movies []Movie) error {
for _, movie := range movies {
fmt.Printf("Título: %s, Puntuación: %.1f, Fecha: %s\n",
movie.Title, movie.Rate, movie.Date)
// API Calls
err := generateMovieMarkdown(movie)
if err != nil {
return err
}
}
return nil
}
func generateMovieMarkdown(movie Movie) error {
templatePath := filepath.Join(os.Getenv("TEMPLATES_DIR"), "movie.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", movie.Title))
data := map[string]interface{}{
"Title": movie.Title,
"Link": "https://imdb.com/enlace",
"Subtitle": movie.Year,
"Year": movie.Year,
"Rate": movie.Rate,
"Image": movie.Image,
"Poster": movie.Poster,
"Background": movie.Background,
"Date": movie.Date,
}
return utils.GenerateMarkdown(templatePath, outputPath, data)
}

View File

@ -1,6 +1,7 @@
package musica
// internal/movies/model.go
package movies
type Musica struct {
type Movie struct {
Title string `yaml:"title"`
Subtitle string `yaml:"subtitle"`
Link string `yaml:"link"`
@ -13,4 +14,4 @@ type Musica struct {
Tags []string
}
type Musicas []Musica
type Movies []Movie

View File

@ -0,0 +1,2 @@
// internal/music/controller.go

View File

@ -1,6 +1,7 @@
package peliculas
// internal/music/model.go
package music
type Pelicula struct {
type Album struct {
Title string `yaml:"title"`
Subtitle string `yaml:"subtitle"`
Link string `yaml:"link"`
@ -13,4 +14,4 @@ type Pelicula struct {
Tags []string
}
type Peliculas []Pelicula
type Albums []Album

View File

@ -1,64 +0,0 @@
// 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)
}

View File

@ -0,0 +1,2 @@
// internal/series/controller.go

View File

@ -1,3 +1,4 @@
// internal/series/model.go
package series
type Serie struct {

17
main.go
View File

@ -2,26 +2,23 @@ package main
import (
"fmt"
"hugo-medialog/internal/peliculas"
"hugo-medialog/internal/movies"
"hugo-medialog/utils"
"os"
)
func main() {
// Cargar el archivo .env
// Load .env file
utils.LoadConfig()
obsidianPath := os.Getenv("OBSIDIAN_YAML_PATH")
// Peliculas
moviesList, err := peliculas.LoadPeliculas(obsidianPath)
// Movies
moviesList, err := movies.LoadMovies()
if err != nil {
fmt.Printf("Error reading peliculas file: %v\n", err)
fmt.Printf("Error reading movies file: %v\n", err)
return
}
err = peliculas.ProcessPeliculas(moviesList)
err = movies.ProcessMovies(moviesList)
if err != nil {
fmt.Printf("Error processing peliculas: %v\n", err)
fmt.Printf("Error processing movies: %v\n", err)
}
}

View File

@ -1,3 +1,4 @@
// utils/config.go
package utils
import (