@@ -58,13 +58,41 @@ func (e *LetterboxdExporter) getTimeInConfigTimezone() time.Time {
5858 return now .In (loc )
5959}
6060
61- // ExportMovies exports the given movies to a CSV file in Letterboxd format
62- func (e * LetterboxdExporter ) ExportMovies (movies []api.Movie ) error {
63- if err := os .MkdirAll (e .config .Letterboxd .ExportDir , 0755 ); err != nil {
61+ // getExportDir creates and returns the path to the directory where exports should be saved
62+ func (e * LetterboxdExporter ) getExportDir () (string , error ) {
63+ // Get current time in configured timezone
64+ now := e .getTimeInConfigTimezone ()
65+
66+ // Create a subdirectory with date and time
67+ dirName := fmt .Sprintf ("export_%s_%s" ,
68+ now .Format ("2006-01-02" ),
69+ now .Format ("15-04" ))
70+
71+ // Full path to the export directory
72+ exportDir := filepath .Join (e .config .Letterboxd .ExportDir , dirName )
73+
74+ // Create the directory
75+ if err := os .MkdirAll (exportDir , 0755 ); err != nil {
6476 e .log .Error ("errors.export_dir_create_failed" , map [string ]interface {}{
6577 "error" : err .Error (),
78+ "path" : exportDir ,
6679 })
67- return fmt .Errorf ("failed to create export directory: %w" , err )
80+ return "" , fmt .Errorf ("failed to create export directory: %w" , err )
81+ }
82+
83+ e .log .Info ("export.using_directory" , map [string ]interface {}{
84+ "path" : exportDir ,
85+ })
86+
87+ return exportDir , nil
88+ }
89+
90+ // ExportMovies exports the given movies to a CSV file in Letterboxd format
91+ func (e * LetterboxdExporter ) ExportMovies (movies []api.Movie ) error {
92+ // Get export directory
93+ exportDir , err := e .getExportDir ()
94+ if err != nil {
95+ return err
6896 }
6997
7098 // Use configured filename, or generate one with timestamp if not specified
@@ -74,9 +102,11 @@ func (e *LetterboxdExporter) ExportMovies(movies []api.Movie) error {
74102 } else {
75103 // Use the configured timezone for filename timestamp
76104 now := e .getTimeInConfigTimezone ()
77- filename = fmt .Sprintf ("letterboxd-export-%s.csv" , now .Format ("2006-01-02" ))
105+ filename = fmt .Sprintf ("letterboxd-export_%s_%s.csv" ,
106+ now .Format ("2006-01-02" ),
107+ now .Format ("15-04" ))
78108 }
79- filePath := filepath .Join (e . config . Letterboxd . ExportDir , filename )
109+ filePath := filepath .Join (exportDir , filename )
80110
81111 file , err := os .Create (filePath )
82112 if err != nil {
@@ -183,11 +213,10 @@ func (e *LetterboxdExporter) ExportMovies(movies []api.Movie) error {
183213
184214// ExportCollectionMovies exports the user's movie collection to a CSV file in Letterboxd format
185215func (e * LetterboxdExporter ) ExportCollectionMovies (movies []api.CollectionMovie ) error {
186- if err := os .MkdirAll (e .config .Letterboxd .ExportDir , 0755 ); err != nil {
187- e .log .Error ("errors.export_dir_create_failed" , map [string ]interface {}{
188- "error" : err .Error (),
189- })
190- return fmt .Errorf ("failed to create export directory: %w" , err )
216+ // Get export directory
217+ exportDir , err := e .getExportDir ()
218+ if err != nil {
219+ return err
191220 }
192221
193222 // Use configured filename, or generate one with timestamp if not specified
@@ -197,9 +226,11 @@ func (e *LetterboxdExporter) ExportCollectionMovies(movies []api.CollectionMovie
197226 } else {
198227 // Use the configured timezone for filename timestamp
199228 now := e .getTimeInConfigTimezone ()
200- filename = fmt .Sprintf ("collection-export-%s.csv" , now .Format ("2006-01-02" ))
229+ filename = fmt .Sprintf ("collection-export_%s_%s.csv" ,
230+ now .Format ("2006-01-02" ),
231+ now .Format ("15-04" ))
201232 }
202- filePath := filepath .Join (e . config . Letterboxd . ExportDir , filename )
233+ filePath := filepath .Join (exportDir , filename )
203234
204235 file , err := os .Create (filePath )
205236 if err != nil {
@@ -250,11 +281,10 @@ func (e *LetterboxdExporter) ExportCollectionMovies(movies []api.CollectionMovie
250281
251282// ExportShows exports the user's watched shows to a CSV file
252283func (e * LetterboxdExporter ) ExportShows (shows []api.WatchedShow ) error {
253- if err := os .MkdirAll (e .config .Letterboxd .ExportDir , 0755 ); err != nil {
254- e .log .Error ("errors.export_dir_create_failed" , map [string ]interface {}{
255- "error" : err .Error (),
256- })
257- return fmt .Errorf ("failed to create export directory: %w" , err )
284+ // Get export directory
285+ exportDir , err := e .getExportDir ()
286+ if err != nil {
287+ return err
258288 }
259289
260290 // Use configured filename, or generate one with timestamp if not specified
@@ -264,9 +294,11 @@ func (e *LetterboxdExporter) ExportShows(shows []api.WatchedShow) error {
264294 } else {
265295 // Use the configured timezone for filename timestamp
266296 now := e .getTimeInConfigTimezone ()
267- filename = fmt .Sprintf ("shows-export-%s.csv" , now .Format ("2006-01-02" ))
297+ filename = fmt .Sprintf ("shows-export_%s_%s.csv" ,
298+ now .Format ("2006-01-02" ),
299+ now .Format ("15-04" ))
268300 }
269- filePath := filepath .Join (e . config . Letterboxd . ExportDir , filename )
301+ filePath := filepath .Join (exportDir , filename )
270302
271303 file , err := os .Create (filePath )
272304 if err != nil {
@@ -398,18 +430,19 @@ func (e *LetterboxdExporter) ExportShows(shows []api.WatchedShow) error {
398430
399431// ExportRatings exports the user's movie ratings to a CSV file in Letterboxd format
400432func (e * LetterboxdExporter ) ExportRatings (ratings []api.Rating ) error {
401- if err := os .MkdirAll (e .config .Letterboxd .ExportDir , 0755 ); err != nil {
402- e .log .Error ("errors.export_dir_create_failed" , map [string ]interface {}{
403- "error" : err .Error (),
404- })
405- return fmt .Errorf ("failed to create export directory: %w" , err )
433+ // Get export directory
434+ exportDir , err := e .getExportDir ()
435+ if err != nil {
436+ return err
406437 }
407438
408439 // Use configured filename, or generate one with timestamp if not specified
409440 // Use the configured timezone for filename timestamp
410441 now := e .getTimeInConfigTimezone ()
411- filename := fmt .Sprintf ("ratings-export-%s.csv" , now .Format ("2006-01-02" ))
412- filePath := filepath .Join (e .config .Letterboxd .ExportDir , filename )
442+ filename := fmt .Sprintf ("ratings-export_%s_%s.csv" ,
443+ now .Format ("2006-01-02" ),
444+ now .Format ("15-04" ))
445+ filePath := filepath .Join (exportDir , filename )
413446
414447 file , err := os .Create (filePath )
415448 if err != nil {
@@ -467,18 +500,19 @@ func (e *LetterboxdExporter) ExportRatings(ratings []api.Rating) error {
467500
468501// ExportWatchlist exports the user's movie watchlist to a CSV file in Letterboxd format
469502func (e * LetterboxdExporter ) ExportWatchlist (watchlist []api.WatchlistMovie ) error {
470- if err := os .MkdirAll (e .config .Letterboxd .ExportDir , 0755 ); err != nil {
471- e .log .Error ("errors.export_dir_create_failed" , map [string ]interface {}{
472- "error" : err .Error (),
473- })
474- return fmt .Errorf ("failed to create export directory: %w" , err )
503+ // Get export directory
504+ exportDir , err := e .getExportDir ()
505+ if err != nil {
506+ return err
475507 }
476508
477509 // Use configured filename, or generate one with timestamp if not specified
478510 // Use the configured timezone for filename timestamp
479511 now := e .getTimeInConfigTimezone ()
480- filename := fmt .Sprintf ("watchlist-export-%s.csv" , now .Format ("2006-01-02" ))
481- filePath := filepath .Join (e .config .Letterboxd .ExportDir , filename )
512+ filename := fmt .Sprintf ("watchlist-export_%s_%s.csv" ,
513+ now .Format ("2006-01-02" ),
514+ now .Format ("15-04" ))
515+ filePath := filepath .Join (exportDir , filename )
482516
483517 file , err := os .Create (filePath )
484518 if err != nil {
@@ -532,16 +566,15 @@ func (e *LetterboxdExporter) ExportWatchlist(watchlist []api.WatchlistMovie) err
532566// The format matches the official Letterboxd import format with columns:
533567// Title, Year, imdbID, tmdbID, WatchedDate, Rating10, Rewatch
534568func (e * LetterboxdExporter ) ExportLetterboxdFormat (movies []api.Movie , ratings []api.Rating ) error {
535- if err := os .MkdirAll (e .config .Letterboxd .ExportDir , 0755 ); err != nil {
536- e .log .Error ("errors.export_dir_create_failed" , map [string ]interface {}{
537- "error" : err .Error (),
538- })
539- return fmt .Errorf ("failed to create export directory: %w" , err )
569+ // Get export directory
570+ exportDir , err := e .getExportDir ()
571+ if err != nil {
572+ return err
540573 }
541574
542575 // Use configured filename, or generate one with timestamp if not specified
543576 filename := "letterboxd_import.csv"
544- filePath := filepath .Join (e . config . Letterboxd . ExportDir , filename )
577+ filePath := filepath .Join (exportDir , filename )
545578
546579 file , err := os .Create (filePath )
547580 if err != nil {
0 commit comments