Added --update param

It's being used to only update some frontmatter fields:

- title
- progress
- rate
- date
This commit is contained in:
Óscar M. Lage 2024-10-11 22:43:44 +02:00
parent c7b120a1e5
commit 410f50f716

37
main.go
View File

@ -18,37 +18,38 @@ func main() {
// --media parameter // --media parameter
media := flag.String("media", "", "Specify the media type to process: movies, series, books, games, or music") 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() flag.Parse()
if *media == "" { if *media == "" {
processAll() processAll(*update)
} else { } else {
switch *media { switch *media {
case "movies": case "movies":
processMovies() processMovies(*update)
case "series": case "series":
processSeries() processSeries(*update)
case "books": case "books":
processBooks() processBooks(*update)
case "games": case "games":
processGames() processGames(*update)
case "music": case "music":
processMusic() processMusic(*update)
default: default:
fmt.Printf("Invalid media type: %s. Please use movies, series, books, games, or music.\n", *media) fmt.Printf("Invalid media type: %s. Please use movies, series, books, games, or music.\n", *media)
} }
} }
} }
func processAll() { func processAll(update bool) {
processMovies() processMovies(update)
processSeries() processSeries(update)
processBooks() processBooks(update)
processGames() processGames(update)
processMusic() processMusic(update)
} }
func processMovies() { func processMovies(update bool) {
moviesList, err := movies.LoadMovies() moviesList, err := movies.LoadMovies()
if err != nil { if err != nil {
fmt.Printf("Error reading movies file: %v\n", err) fmt.Printf("Error reading movies file: %v\n", err)
@ -60,7 +61,7 @@ func processMovies() {
} }
} }
func processSeries() { func processSeries(update bool) {
seriesList, err := series.LoadSeries() seriesList, err := series.LoadSeries()
if err != nil { if err != nil {
fmt.Printf("Error reading series file: %v\n", err) fmt.Printf("Error reading series file: %v\n", err)
@ -72,19 +73,19 @@ func processSeries() {
} }
} }
func processBooks() { func processBooks(update bool) {
booksList, err := books.LoadBooks() booksList, err := books.LoadBooks()
if err != nil { if err != nil {
fmt.Printf("Error reading books file: %v\n", err) fmt.Printf("Error reading books file: %v\n", err)
return return
} }
err = books.ProcessBooks(booksList) err = books.ProcessBooks(booksList, update)
if err != nil { if err != nil {
fmt.Printf("Error processing books: %v\n", err) fmt.Printf("Error processing books: %v\n", err)
} }
} }
func processGames() { func processGames(update bool) {
gamesList, err := games.LoadGames() gamesList, err := games.LoadGames()
if err != nil { if err != nil {
fmt.Printf("Error reading games file: %v\n", err) fmt.Printf("Error reading games file: %v\n", err)
@ -96,7 +97,7 @@ func processGames() {
} }
} }
func processMusic() { func processMusic(update bool) {
albumList, err := music.LoadAlbums() albumList, err := music.LoadAlbums()
if err != nil { if err != nil {
fmt.Printf("Error reading music file: %v\n", err) fmt.Printf("Error reading music file: %v\n", err)