hugo-medialog/main.go

111 lines
2.4 KiB
Go
Raw Normal View History

2024-10-08 19:08:01 +00:00
package main
import (
"flag"
2024-10-08 19:08:01 +00:00
"fmt"
2024-10-10 12:13:40 +00:00
"hugo-medialog/internal/books"
2024-10-10 18:03:49 +00:00
"hugo-medialog/internal/games"
2024-10-09 09:12:44 +00:00
"hugo-medialog/internal/movies"
2024-10-11 11:05:46 +00:00
"hugo-medialog/internal/music"
2024-10-09 19:56:40 +00:00
"hugo-medialog/internal/series"
2024-10-08 19:08:01 +00:00
"hugo-medialog/utils"
)
func main() {
2024-10-09 09:12:44 +00:00
// Load .env file
2024-10-08 19:08:01 +00:00
utils.LoadConfig()
2024-10-11 18:20:01 +00:00
utils.Sep()
2024-10-08 19:08:01 +00:00
2024-10-10 18:03:49 +00: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 18:03:49 +00:00
case "games":
processGames(*update)
2024-10-11 11:05:46 +00: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 09:12:44 +00:00
moviesList, err := movies.LoadMovies()
2024-10-08 19:08:01 +00:00
if err != nil {
2024-10-09 09:12:44 +00:00
fmt.Printf("Error reading movies file: %v\n", err)
2024-10-08 19:08:01 +00:00
return
}
2024-10-09 09:12:44 +00:00
err = movies.ProcessMovies(moviesList)
2024-10-08 19:08:01 +00:00
if err != nil {
2024-10-09 09:12:44 +00:00
fmt.Printf("Error processing movies: %v\n", err)
2024-10-08 19:08:01 +00:00
}
}
2024-10-08 19:08:01 +00:00
func processSeries(update bool) {
2024-10-09 19:56:40 +00:00
seriesList, err := series.LoadSeries()
if err != nil {
fmt.Printf("Error reading series file: %v\n", err)
return
}
err = series.ProcessSeries(seriesList)
if err != nil {
fmt.Printf("Error processing series: %v\n", err)
}
}
2024-10-09 19:56:40 +00:00
func processBooks(update bool) {
2024-10-10 12:13:40 +00: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 12:13:40 +00:00
if err != nil {
fmt.Printf("Error processing books: %v\n", err)
}
2024-10-08 19:08:01 +00:00
}
2024-10-10 18:03:49 +00:00
func processGames(update bool) {
2024-10-10 18:03:49 +00:00
gamesList, err := games.LoadGames()
if err != nil {
fmt.Printf("Error reading games file: %v\n", err)
return
}
2024-10-11 20:54:29 +00:00
err = games.ProcessGames(gamesList, update)
2024-10-10 18:03:49 +00:00
if err != nil {
fmt.Printf("Error processing games: %v\n", err)
}
}
2024-10-11 11:05:46 +00:00
func processMusic(update bool) {
2024-10-11 11:05:46 +00:00
albumList, err := music.LoadAlbums()
if err != nil {
fmt.Printf("Error reading music file: %v\n", err)
return
}
err = music.ProcessAlbum(albumList)
if err != nil {
fmt.Printf("Error processing music: %v\n", err)
}
}