hugo-medialog/main.go

150 lines
3.8 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"
2024-10-25 09:36:05 +02:00
"os"
2024-10-08 21:08:01 +02:00
)
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-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")
2024-10-25 09:36:05 +02:00
// Define custom help option
help := flag.Bool("help", false, "Display this help message")
flag.BoolVar(help, "h", false, "Display this help message") // support -h as well
flag.Parse()
2024-10-25 09:36:05 +02:00
// Show help message if -h or --help is specified
if *help {
printHelp()
os.Exit(0)
}
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)
2024-10-25 09:36:05 +02:00
printHelp()
os.Exit(1)
}
}
}
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)
}
}
2024-10-25 09:36:05 +02:00
func printHelp() {
fmt.Println(`Usage: go run main.go [--media mediatype] [--update]
Description:
This command allows you to manage multimedia files and update their data in the system.
Options:
--media <mediatype> Specifies the type of media to process.
Possible values are:
- movies: Processes movie files.
- series: Processes series files.
- books: Processes book files.
- games: Processes game files.
- music: Processes music files.
If not specified, all media types will be processed.
--update Runs in update mode to refresh existing media entries.
This option is optional and requires no value.
-h, --help Displays this help message and exits.
Usage examples:
go run main.go --media movies Processes only movie files.
go run main.go --update Updates all multimedia files.
go run main.go --media series --update Processes and updates series files.`)
}