hugo-medialog/main.go

111 lines
2.4 KiB
Go
Raw Normal View History

2024-10-08 21:08:01 +02:00
package main
import (
"flag"
2024-10-08 21:08:01 +02:00
"fmt"
2024-10-10 14:13:40 +02:00
"hugo-medialog/internal/books"
2024-10-10 20:03:49 +02:00
"hugo-medialog/internal/games"
2024-10-09 11:12:44 +02:00
"hugo-medialog/internal/movies"
2024-10-11 13:05:46 +02:00
"hugo-medialog/internal/music"
2024-10-09 21:56:40 +02:00
"hugo-medialog/internal/series"
2024-10-08 21:08:01 +02:00
"hugo-medialog/utils"
)
func main() {
2024-10-09 11:12:44 +02:00
// Load .env file
2024-10-08 21:08:01 +02:00
utils.LoadConfig()
2024-10-11 20:20:01 +02:00
utils.Sep()
2024-10-08 21:08:01 +02:00
2024-10-10 20:03:49 +02:00
// --media parameter
media := flag.String("media", "", "Specify the media type to process: movies, series, books, games, or music")
update := flag.Bool("update", false, "Run in update mode to update existing entries")
flag.Parse()
if *media == "" {
processAll(*update)
} else {
switch *media {
case "movies":
processMovies(*update)
case "series":
processSeries(*update)
case "books":
processBooks(*update)
2024-10-10 20:03:49 +02:00
case "games":
processGames(*update)
2024-10-11 13:05:46 +02:00
case "music":
processMusic(*update)
default:
fmt.Printf("Invalid media type: %s. Please use movies, series, books, games, or music.\n", *media)
}
}
}
func processAll(update bool) {
processMovies(update)
processSeries(update)
processBooks(update)
processGames(update)
processMusic(update)
}
func processMovies(update bool) {
2024-10-09 11:12:44 +02:00
moviesList, err := movies.LoadMovies()
2024-10-08 21:08:01 +02:00
if err != nil {
2024-10-09 11:12:44 +02:00
fmt.Printf("Error reading movies file: %v\n", err)
2024-10-08 21:08:01 +02:00
return
}
2024-10-14 16:49:56 +02:00
err = movies.ProcessMovies(moviesList, update)
2024-10-08 21:08:01 +02:00
if err != nil {
2024-10-09 11:12:44 +02:00
fmt.Printf("Error processing movies: %v\n", err)
2024-10-08 21:08:01 +02:00
}
}
2024-10-08 21:08:01 +02:00
func processSeries(update bool) {
2024-10-09 21:56:40 +02:00
seriesList, err := series.LoadSeries()
if err != nil {
fmt.Printf("Error reading series file: %v\n", err)
return
}
2024-10-14 13:44:24 +02:00
err = series.ProcessSeries(seriesList, update)
2024-10-09 21:56:40 +02:00
if err != nil {
fmt.Printf("Error processing series: %v\n", err)
}
}
2024-10-09 21:56:40 +02:00
func processBooks(update bool) {
2024-10-10 14:13:40 +02:00
booksList, err := books.LoadBooks()
if err != nil {
fmt.Printf("Error reading books file: %v\n", err)
return
}
err = books.ProcessBooks(booksList, update)
2024-10-10 14:13:40 +02:00
if err != nil {
fmt.Printf("Error processing books: %v\n", err)
}
2024-10-08 21:08:01 +02:00
}
2024-10-10 20:03:49 +02:00
func processGames(update bool) {
2024-10-10 20:03:49 +02:00
gamesList, err := games.LoadGames()
if err != nil {
fmt.Printf("Error reading games file: %v\n", err)
return
}
2024-10-11 22:54:29 +02:00
err = games.ProcessGames(gamesList, update)
2024-10-10 20:03:49 +02:00
if err != nil {
fmt.Printf("Error processing games: %v\n", err)
}
}
2024-10-11 13:05:46 +02:00
func processMusic(update bool) {
2024-10-11 13:05:46 +02:00
albumList, err := music.LoadAlbums()
if err != nil {
fmt.Printf("Error reading music file: %v\n", err)
return
}
2024-10-14 13:48:49 +02:00
err = music.ProcessAlbum(albumList, update)
2024-10-11 13:05:46 +02:00
if err != nil {
fmt.Printf("Error processing music: %v\n", err)
}
}