Index: src/totem-playlist.c
===================================================================
--- src/totem-playlist.c	(revision 4047)
+++ src/totem-playlist.c	(working copy)
@@ -881,26 +881,89 @@
 	playlist_remove_files (playlist);
 }
 
+static char *
+totem_playlist_prevent_overwriting_files (TotemPlaylist *playlist, char *filename, gint active_format)
+{
+	/* This function checks if a filename already exists. If it does: concatenate a number starting with 2 */
+	guint i;
+	char *old_filename, *tmp;
+
+	old_filename = filename;
+	tmp = g_strconcat (filename, save_types[active_format].suffix, NULL);
+	filename = tmp;
+
+	i = 2;
+	while (gnome_vfs_uri_exists (gnome_vfs_uri_new (filename)) == TRUE) {
+		tmp = g_strconcat (old_filename, " (", g_strdup_printf ("%d", i), ")", NULL);
+		filename = tmp;
+
+		tmp = g_strconcat (filename, save_types[active_format].suffix, NULL);
+		filename = tmp;
+		i++;
+	}
+
+	return filename;
+}
+
 static void
 totem_playlist_save_playlist (TotemPlaylist *playlist, char *filename, gint active_format)
 {
 	PlaylistSaveType *cur = NULL;
 	guint i;
+	char *dest = NULL;
+	char *tmp;
 
-	if (active_format > 0)
-		totem_playlist_save_current_playlist_ext (playlist, filename,
-							save_types[active_format - 1].type);
+	if (active_format > 0) {
+		/* File format has been selected, thus the file extension is based on that selection */
+		if (g_str_has_suffix (filename, save_types[active_format - 1].suffix)) {
+			/* Selected file format and suffix are the same */
+			totem_playlist_save_current_playlist_ext (playlist, filename, save_types[active_format - 1].type);
+		}
+		else {
+			/* Selected file format and suffix are not the same */
+			for (i = 0; i < G_N_ELEMENTS(save_types); i++) {
+				if (g_str_has_suffix (filename, save_types[i].suffix)) {
+					cur = &save_types[i];
+					break;
+				}
+			}
+
+			if (cur != NULL) {
+				/* Remove the extension from filename */
+				dest = g_malloc (strlen (filename));
+				g_utf8_strncpy (dest, filename, g_utf8_strlen (filename, -1) - g_utf8_strlen (cur->suffix, -1));
+				filename = dest;
+			}
+
+			tmp = totem_playlist_prevent_overwriting_files (playlist, filename, active_format - 1);
+			filename = tmp;
+			totem_playlist_save_current_playlist_ext (playlist, filename, save_types[active_format - 1].type);
+
+			g_free (dest);
+			g_free (tmp);
+		}
+	}
 	else {
+		/* No specific file format has been selected, extension is based on the file name */
 		for (i = 0; i < G_N_ELEMENTS(save_types); i++) {
 			if (g_str_has_suffix (filename, save_types[i].suffix)) {
 				cur = &save_types[i];
 				break;
 			}
 		}
-		if (cur == NULL)
-			totem_playlist_error (_("Could not save the playlist"), _("Unknown file extension."), playlist);
-		else
+
+		if (cur == NULL) {
+			/* The playlist is saved with the default suffix, because the supplied suffix wasn't in save_types */
+			tmp = totem_playlist_prevent_overwriting_files (playlist, filename, 0);
+			filename = tmp;
+			totem_playlist_save_current_playlist_ext (playlist, filename, save_types[0].type);
+
+			g_free (tmp);
+		}
+		else {
+			/* The playlist is saved with the entered suffix */
 			totem_playlist_save_current_playlist_ext (playlist, filename, cur->type);
+		}
 	}
 }
 
@@ -962,8 +1025,7 @@
 	g_free (filename);
 	combo_box = totem_playlist_save_add_format_combo_box (GTK_FILE_CHOOSER (fs));
 
-	if (playlist->_priv->save_path != NULL)
-	{
+	if (playlist->_priv->save_path != NULL) {
 		gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (fs),
 				playlist->_priv->save_path);
 	}
@@ -973,8 +1035,7 @@
 	while (gtk_events_pending())
 		gtk_main_iteration();
 
-	if (response == GTK_RESPONSE_ACCEPT)
-	{
+	if (response == GTK_RESPONSE_ACCEPT) {
 		char *filename;
 		gint active_format;
 
@@ -991,9 +1052,9 @@
 
 		totem_playlist_save_playlist (playlist, filename, active_format);
 		g_free (filename);
-	} else {
+	}
+	else
 		gtk_widget_destroy (fs);
-	}
 }
 
 static void
