package main import ( "flag" "fmt" "hugo-medialog/internal/books" "hugo-medialog/internal/games" "hugo-medialog/internal/movies" "hugo-medialog/internal/music" "hugo-medialog/internal/series" "hugo-medialog/utils" "os" ) func main() { // Load .env file utils.LoadConfig() // --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") // 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() // 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) case "games": processGames(*update) case "music": processMusic(*update) default: fmt.Printf("Invalid media type: %s. Please use movies, series, books, games, or music.\n", *media) printHelp() os.Exit(1) } } } func processAll(update bool) { processMovies(update) processSeries(update) processBooks(update) processGames(update) processMusic(update) } func processMovies(update bool) { moviesList, err := movies.LoadMovies() if err != nil { fmt.Printf("Error reading movies file: %v\n", err) return } err = movies.ProcessMovies(moviesList, update) if err != nil { fmt.Printf("Error processing movies: %v\n", err) } } func processSeries(update bool) { seriesList, err := series.LoadSeries() if err != nil { fmt.Printf("Error reading series file: %v\n", err) return } err = series.ProcessSeries(seriesList, update) if err != nil { fmt.Printf("Error processing series: %v\n", err) } } func processBooks(update bool) { booksList, err := books.LoadBooks() if err != nil { fmt.Printf("Error reading books file: %v\n", err) return } err = books.ProcessBooks(booksList, update) if err != nil { fmt.Printf("Error processing books: %v\n", err) } } func processGames(update bool) { gamesList, err := games.LoadGames() if err != nil { fmt.Printf("Error reading games file: %v\n", err) return } err = games.ProcessGames(gamesList, update) if err != nil { fmt.Printf("Error processing games: %v\n", err) } } func processMusic(update bool) { albumList, err := music.LoadAlbums() if err != nil { fmt.Printf("Error reading music file: %v\n", err) return } err = music.ProcessAlbum(albumList, update) if err != nil { fmt.Printf("Error processing music: %v\n", err) } } 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 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.`) }