2024-10-08 21:08:01 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-10-10 14:22:15 +02:00
|
|
|
"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
|
2024-10-10 14:22:15 +02:00
|
|
|
media := flag.String("media", "", "Specify the media type to process: movies, series, books, games, or music")
|
2024-10-11 22:43:44 +02:00
|
|
|
update := flag.Bool("update", false, "Run in update mode to update existing entries")
|
2024-10-10 14:22:15 +02:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *media == "" {
|
2024-10-11 22:43:44 +02:00
|
|
|
processAll(*update)
|
2024-10-10 14:22:15 +02:00
|
|
|
} else {
|
|
|
|
switch *media {
|
|
|
|
case "movies":
|
2024-10-11 22:43:44 +02:00
|
|
|
processMovies(*update)
|
2024-10-10 14:22:15 +02:00
|
|
|
case "series":
|
2024-10-11 22:43:44 +02:00
|
|
|
processSeries(*update)
|
2024-10-10 14:22:15 +02:00
|
|
|
case "books":
|
2024-10-11 22:43:44 +02:00
|
|
|
processBooks(*update)
|
2024-10-10 20:03:49 +02:00
|
|
|
case "games":
|
2024-10-11 22:43:44 +02:00
|
|
|
processGames(*update)
|
2024-10-11 13:05:46 +02:00
|
|
|
case "music":
|
2024-10-11 22:43:44 +02:00
|
|
|
processMusic(*update)
|
2024-10-10 14:22:15 +02:00
|
|
|
default:
|
|
|
|
fmt.Printf("Invalid media type: %s. Please use movies, series, books, games, or music.\n", *media)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-11 22:43:44 +02:00
|
|
|
func processAll(update bool) {
|
|
|
|
processMovies(update)
|
|
|
|
processSeries(update)
|
|
|
|
processBooks(update)
|
|
|
|
processGames(update)
|
|
|
|
processMusic(update)
|
2024-10-10 14:22:15 +02:00
|
|
|
}
|
|
|
|
|
2024-10-11 22:43:44 +02:00
|
|
|
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-10 14:22:15 +02:00
|
|
|
}
|
2024-10-08 21:08:01 +02:00
|
|
|
|
2024-10-11 22:43:44 +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-10 14:22:15 +02:00
|
|
|
}
|
2024-10-09 21:56:40 +02:00
|
|
|
|
2024-10-11 22:43:44 +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
|
|
|
|
}
|
2024-10-11 22:43:44 +02:00
|
|
|
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
|
|
|
|
2024-10-11 22:43:44 +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
|
|
|
|
2024-10-11 22:43:44 +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)
|
|
|
|
}
|
|
|
|
}
|