diff --git a/src/main.rs b/src/main.rs index e443a20..5ad2d7d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,10 @@ fn extract_spotify_id(uri: &str) -> Option { } /// Convert an Exportify record to a `TuneMyMusic` record -fn convert_record(record: &ExportifyRecord) -> TuneMusicRecord { +fn convert_record( + record: &ExportifyRecord, + playlist_name: &str, +) -> TuneMusicRecord { // Extract Spotify ID from Track URI if available let spotify_id = record .track_uri @@ -77,7 +80,7 @@ fn convert_record(record: &ExportifyRecord) -> TuneMusicRecord { track_name: record.track_name.clone().unwrap_or_default(), artist_name: record.artist_names.clone().unwrap_or_default(), album: record.album_name.clone().unwrap_or_default(), - playlist_name: "misc.".to_string(), + playlist_name: playlist_name.to_string(), record_type: "Playlist".to_string(), isrc: record.isrc.clone().unwrap_or_default(), spotify_id, @@ -147,9 +150,19 @@ fn process_file( }, }; + // Derive playlist name from input filename + let playlist_name = input_path + .file_stem() // Get filename without extension + .map_or_else( + || "misc.".to_string(), // Default if stem extraction fails + |stem| stem.to_string_lossy().replace('_', " "), // Replace underscores with spaces + ); + // Convert to TuneMyMusic format - let tune_records: Vec = - export_records.iter().map(convert_record).collect(); + let tune_records: Vec = export_records + .iter() + .map(|record| convert_record(record, &playlist_name)) // Pass playlist name + .collect(); // Write to file let file = File::create(output_path)?;