Skip to content

Commit a1edc2e

Browse files
committed
feat: Add extended API endpoints support
1 parent aaaaa8e commit a1edc2e

File tree

8 files changed

+587
-15
lines changed

8 files changed

+587
-15
lines changed

cmd/export_trakt/main.go

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
func main() {
1616
// Parse command line flags
1717
configPath := flag.String("config", "config/config.toml", "Path to configuration file")
18-
exportType := flag.String("export", "watched", "Type of export (watched, collection, shows, all)")
18+
exportType := flag.String("export", "watched", "Type of export (watched, collection, shows, ratings, watchlist, all)")
1919
flag.Parse()
2020

2121
// Initialize logger
@@ -65,13 +65,19 @@ func main() {
6565
exportCollection(traktClient, letterboxdExporter, log)
6666
case "shows":
6767
exportShows(traktClient, letterboxdExporter, log)
68+
case "ratings":
69+
exportRatings(traktClient, letterboxdExporter, log)
70+
case "watchlist":
71+
exportWatchlist(traktClient, letterboxdExporter, log)
6872
case "all":
6973
exportWatchedMovies(traktClient, letterboxdExporter, log)
7074
exportCollection(traktClient, letterboxdExporter, log)
7175
exportShows(traktClient, letterboxdExporter, log)
76+
exportRatings(traktClient, letterboxdExporter, log)
77+
exportWatchlist(traktClient, letterboxdExporter, log)
7278
default:
7379
log.Error("errors.invalid_export_type", map[string]interface{}{"type": *exportType})
74-
fmt.Printf("Invalid export type: %s. Valid types are 'watched', 'collection', 'shows', or 'all'\n", *exportType)
80+
fmt.Printf("Invalid export type: %s. Valid types are 'watched', 'collection', 'shows', 'ratings', 'watchlist', or 'all'\n", *exportType)
7581
os.Exit(1)
7682
}
7783

@@ -144,4 +150,42 @@ func exportShows(client *api.Client, exporter *export.LetterboxdExporter, log lo
144150
log.Error("export.export_failed", map[string]interface{}{"error": err.Error()})
145151
os.Exit(1)
146152
}
153+
}
154+
155+
func exportRatings(client *api.Client, exporter *export.LetterboxdExporter, log logger.Logger) {
156+
// Get ratings
157+
log.Info("export.retrieving_ratings", nil)
158+
ratings, err := client.GetRatings()
159+
if err != nil {
160+
log.Error("errors.api_request_failed", map[string]interface{}{"error": err.Error()})
161+
os.Exit(1)
162+
}
163+
164+
log.Info("export.ratings_retrieved", map[string]interface{}{"count": len(ratings)})
165+
166+
// Export ratings
167+
log.Info("export.exporting_ratings", nil)
168+
if err := exporter.ExportRatings(ratings); err != nil {
169+
log.Error("export.export_failed", map[string]interface{}{"error": err.Error()})
170+
os.Exit(1)
171+
}
172+
}
173+
174+
func exportWatchlist(client *api.Client, exporter *export.LetterboxdExporter, log logger.Logger) {
175+
// Get watchlist
176+
log.Info("export.retrieving_watchlist", nil)
177+
watchlist, err := client.GetWatchlist()
178+
if err != nil {
179+
log.Error("errors.api_request_failed", map[string]interface{}{"error": err.Error()})
180+
os.Exit(1)
181+
}
182+
183+
log.Info("export.watchlist_retrieved", map[string]interface{}{"count": len(watchlist)})
184+
185+
// Export watchlist
186+
log.Info("export.exporting_watchlist", nil)
187+
if err := exporter.ExportWatchlist(watchlist); err != nil {
188+
log.Error("export.export_failed", map[string]interface{}{"error": err.Error()})
189+
os.Exit(1)
190+
}
147191
}

config/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ client_id = ""
44
client_secret = ""
55
access_token = ""
66
api_base_url = "https://api.trakt.tv"
7+
extended_info = "full"
78

89
# Letterboxd Export Configuration
910
[letterboxd]

locales/en.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@
2323
"retrieving_watched_shows": "Retrieving watched shows from Trakt.tv",
2424
"shows_retrieved": "Retrieved {{.shows}} shows with {{.episodes}} episodes from Trakt.tv",
2525
"exporting_shows": "Exporting TV shows to CSV format",
26-
"shows_export_complete": "Successfully exported {{.shows}} shows with {{.episodes}} episodes to {{.path}}"
26+
"shows_export_complete": "Successfully exported {{.shows}} shows with {{.episodes}} episodes to {{.path}}",
27+
"retrieving_ratings": "Retrieving movie ratings from Trakt.tv",
28+
"ratings_retrieved": "Retrieved {{.count}} movie ratings from Trakt.tv",
29+
"exporting_ratings": "Exporting movie ratings to Letterboxd format",
30+
"ratings_export_complete": "Successfully exported {{.count}} movie ratings to {{.path}}",
31+
"retrieving_watchlist": "Retrieving movie watchlist from Trakt.tv",
32+
"watchlist_retrieved": "Retrieved {{.count}} movies from your Trakt.tv watchlist",
33+
"exporting_watchlist": "Exporting movie watchlist to Letterboxd format",
34+
"watchlist_export_complete": "Successfully exported {{.count}} watchlist movies to {{.path}}"
2735
},
2836
"errors": {
2937
"config_load_failed": "Failed to load configuration: {{.error}}",
@@ -32,6 +40,8 @@
3240
"file_create_failed": "Failed to create file: {{.error}}",
3341
"log_file_failed": "Failed to set log file: {{.error}}",
3442
"translator_failed": "Failed to initialize translator: {{.error}}",
35-
"invalid_export_type": "Invalid export type: {{.type}}"
43+
"invalid_export_type": "Invalid export type: {{.type}}",
44+
"api_url_parse_error": "Failed to parse API URL: {{.error}}",
45+
"api_response_parse_failed": "Failed to parse API response: {{.error}}"
3646
}
3747
}

locales/fr.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@
2323
"retrieving_watched_shows": "Récupération des séries TV vues depuis Trakt.tv",
2424
"shows_retrieved": "{{.shows}} séries avec {{.episodes}} épisodes récupérés depuis Trakt.tv",
2525
"exporting_shows": "Exportation des séries TV au format CSV",
26-
"shows_export_complete": "{{.shows}} séries avec {{.episodes}} épisodes exportés avec succès vers {{.path}}"
26+
"shows_export_complete": "{{.shows}} séries avec {{.episodes}} épisodes exportés avec succès vers {{.path}}",
27+
"retrieving_ratings": "Récupération des évaluations de films depuis Trakt.tv",
28+
"ratings_retrieved": "{{.count}} évaluations de films récupérées depuis Trakt.tv",
29+
"exporting_ratings": "Exportation des évaluations de films au format Letterboxd",
30+
"ratings_export_complete": "{{.count}} évaluations de films exportées avec succès vers {{.path}}",
31+
"retrieving_watchlist": "Récupération de la liste de surveillance depuis Trakt.tv",
32+
"watchlist_retrieved": "{{.count}} films récupérés depuis votre liste de surveillance Trakt.tv",
33+
"exporting_watchlist": "Exportation de la liste de surveillance au format Letterboxd",
34+
"watchlist_export_complete": "{{.count}} films de la liste de surveillance exportés avec succès vers {{.path}}"
2735
},
2836
"errors": {
2937
"config_load_failed": "Échec du chargement de la configuration : {{.error}}",
@@ -32,6 +40,8 @@
3240
"file_create_failed": "Échec de la création du fichier : {{.error}}",
3341
"log_file_failed": "Échec de la définition du fichier journal : {{.error}}",
3442
"translator_failed": "Échec de l'initialisation du traducteur : {{.error}}",
35-
"invalid_export_type": "Type d'exportation invalide : {{.type}}"
43+
"invalid_export_type": "Type d'exportation invalide : {{.type}}",
44+
"api_url_parse_error": "Échec de l'analyse de l'URL de l'API : {{.error}}",
45+
"api_response_parse_failed": "Échec de l'analyse de la réponse de l'API : {{.error}}"
3646
}
3747
}

0 commit comments

Comments
 (0)