Initial commit

This commit is contained in:
Óscar M. Lage 2024-10-08 21:08:01 +02:00
commit c0b3067f10
32 changed files with 422 additions and 0 deletions

14
env.sample Normal file
View File

@ -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

8
go.mod Normal file
View File

@ -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
)

6
go.sum Normal file
View File

@ -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=

View File

17
internal/libros/model.go Normal file
View File

@ -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

View File

16
internal/musica/model.go Normal file
View File

@ -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

View File

@ -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)
}

View File

@ -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

View File

17
internal/series/model.go Normal file
View File

@ -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

View File

View File

@ -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

27
main.go Normal file
View File

@ -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)
}
}

4
obsidian/libros.yml.md Normal file
View File

@ -0,0 +1,4 @@
- title: "The Catcher in the Rye"
progress: "50%"
rate: 7.5
date: 2024-10-08

4
obsidian/musica.yml.md Normal file
View File

@ -0,0 +1,4 @@
- title: "Random Access Memories"
spotify_id: "4m2880jivSbbyEGAKfITCa"
rate: 9.8
date: 2024-10-08

9
obsidian/pelis.yml.md Normal file
View File

@ -0,0 +1,9 @@
- title: "Inception"
imdb:
rate: 8.5
date: 2024-10-08
- title: "Matrix"
imdb:
rate: 9.8
date: "2024-10-08"

4
obsidian/series.yml.md Normal file
View File

@ -0,0 +1,4 @@
- title: "Breaking Bad"
progress: "10%"
rate: 9.2
date: 2024-10-08

View File

@ -0,0 +1,4 @@
- title: "The Legend of Zelda: Breath of the Wild"
progress: "40%"
rate: 9.8
date: 2024-10-08

0
services/fanart.go Normal file
View File

0
services/igdb.go Normal file
View File

0
services/imdb.go Normal file
View File

0
services/isbndb.go Normal file
View File

0
services/spotify.go Normal file
View File

23
templates/libro.md.tpl Normal file
View File

@ -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

21
templates/musica.md.tpl Normal file
View File

@ -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

21
templates/pelicula.md.tpl Normal file
View File

@ -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

22
templates/serie.md.tpl Normal file
View File

@ -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

View File

@ -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

31
utils/config.go Normal file
View File

@ -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
}

25
utils/file_reader.go Normal file
View File

@ -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
}

30
utils/utils.go Normal file
View File

@ -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)
}