playlist: moved code to playlist_save.c
playlist_print_song() and playlist_print_uri() handle charset conversion and (optional) music directory prefixing.
This commit is contained in:
parent
308bc230b2
commit
a52a9fc1fc
|
@ -85,6 +85,7 @@ mpd_headers = \
|
||||||
player_control.h \
|
player_control.h \
|
||||||
playerData.h \
|
playerData.h \
|
||||||
playlist.h \
|
playlist.h \
|
||||||
|
playlist_save.h \
|
||||||
replayGain.h \
|
replayGain.h \
|
||||||
ringbuf.h \
|
ringbuf.h \
|
||||||
signal_check.h \
|
signal_check.h \
|
||||||
|
@ -163,6 +164,7 @@ mpd_SOURCES = \
|
||||||
player_control.c \
|
player_control.c \
|
||||||
playerData.c \
|
playerData.c \
|
||||||
playlist.c \
|
playlist.c \
|
||||||
|
playlist_save.c \
|
||||||
replayGain.c \
|
replayGain.c \
|
||||||
ringbuf.c \
|
ringbuf.c \
|
||||||
sig_handlers.c \
|
sig_handlers.c \
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "playlist.h"
|
#include "playlist.h"
|
||||||
|
#include "playlist_save.h"
|
||||||
#include "player_control.h"
|
#include "player_control.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "ls.h"
|
#include "ls.h"
|
||||||
|
@ -1212,18 +1213,8 @@ enum playlist_result savePlaylist(const char *utf8file)
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return PLAYLIST_RESULT_ERRNO;
|
return PLAYLIST_RESULT_ERRNO;
|
||||||
|
|
||||||
for (i = 0; i < playlist.length; i++) {
|
for (i = 0; i < playlist.length; i++)
|
||||||
char tmp[MPD_PATH_MAX];
|
playlist_print_song(fp, playlist.songs[i]);
|
||||||
|
|
||||||
song_get_url(playlist.songs[i], path_max_tmp);
|
|
||||||
utf8_to_fs_charset(tmp, path_max_tmp);
|
|
||||||
|
|
||||||
if (playlist_saveAbsolutePaths &&
|
|
||||||
song_is_file(playlist.songs[i]))
|
|
||||||
fprintf(fp, "%s\n", rmp2amp_r(tmp, tmp));
|
|
||||||
else
|
|
||||||
fprintf(fp, "%s\n", tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (fclose(fp) && errno == EINTR) ;
|
while (fclose(fp) && errno == EINTR) ;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
/* the Music Player Daemon (MPD)
|
||||||
|
* Copyright (C) 2008 Max Kellermann <max@duempel.org>
|
||||||
|
* This project's homepage is: http://www.musicpd.org
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "playlist_save.h"
|
||||||
|
#include "playlist.h"
|
||||||
|
#include "song.h"
|
||||||
|
#include "path.h"
|
||||||
|
#include "ls.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
playlist_print_song(FILE *file, const struct song *song)
|
||||||
|
{
|
||||||
|
char tmp1[MPD_PATH_MAX], tmp2[MPD_PATH_MAX];
|
||||||
|
|
||||||
|
song_get_url(song, tmp1);
|
||||||
|
utf8_to_fs_charset(tmp2, tmp1);
|
||||||
|
|
||||||
|
if (playlist_saveAbsolutePaths && song_is_file(song))
|
||||||
|
fprintf(file, "%s\n", rmp2amp_r(tmp2, tmp2));
|
||||||
|
else
|
||||||
|
fprintf(file, "%s\n", tmp2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
playlist_print_uri(FILE *file, const char *uri)
|
||||||
|
{
|
||||||
|
char tmp[MPD_PATH_MAX];
|
||||||
|
const char *s;
|
||||||
|
|
||||||
|
s = utf8_to_fs_charset(tmp, uri);
|
||||||
|
if (playlist_saveAbsolutePaths && !isValidRemoteUtf8Url(s))
|
||||||
|
s = rmp2amp_r(tmp, s);
|
||||||
|
fprintf(file, "%s\n", s);
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/* the Music Player Daemon (MPD)
|
||||||
|
* Copyright (C) 2008 Max Kellermann <max@duempel.org>
|
||||||
|
* This project's homepage is: http://www.musicpd.org
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PLAYLIST_SAVE_H
|
||||||
|
#define PLAYLIST_SAVE_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
struct song;
|
||||||
|
|
||||||
|
void
|
||||||
|
playlist_print_song(FILE *fp, const struct song *song);
|
||||||
|
|
||||||
|
void
|
||||||
|
playlist_print_uri(FILE *fp, const char *uri);
|
||||||
|
|
||||||
|
#endif
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "storedPlaylist.h"
|
#include "storedPlaylist.h"
|
||||||
|
#include "playlist_save.h"
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
@ -64,7 +65,6 @@ writeStoredPlaylistToPath(List *list, const char *utf8path)
|
||||||
{
|
{
|
||||||
ListNode *node;
|
ListNode *node;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char *s;
|
|
||||||
char path_max_tmp[MPD_PATH_MAX];
|
char path_max_tmp[MPD_PATH_MAX];
|
||||||
|
|
||||||
assert(utf8path != NULL);
|
assert(utf8path != NULL);
|
||||||
|
@ -77,10 +77,7 @@ writeStoredPlaylistToPath(List *list, const char *utf8path)
|
||||||
|
|
||||||
node = list->firstNode;
|
node = list->firstNode;
|
||||||
while (node != NULL) {
|
while (node != NULL) {
|
||||||
s = utf8_to_fs_charset(path_max_tmp, (char *)node->data);
|
playlist_print_uri(file, (const char *)node->data);
|
||||||
if (playlist_saveAbsolutePaths && !isValidRemoteUtf8Url(s))
|
|
||||||
s = rmp2amp_r(path_max_tmp, s);
|
|
||||||
fprintf(file, "%s\n", s);
|
|
||||||
node = node->nextNode;
|
node = node->nextNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,10 +261,8 @@ enum playlist_result
|
||||||
appendSongToStoredPlaylistByPath(const char *utf8path, struct song *song)
|
appendSongToStoredPlaylistByPath(const char *utf8path, struct song *song)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char *s;
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char path_max_tmp[MPD_PATH_MAX];
|
char path_max_tmp[MPD_PATH_MAX];
|
||||||
char path_max_tmp2[MPD_PATH_MAX];
|
|
||||||
|
|
||||||
if (!is_valid_playlist_name(utf8path))
|
if (!is_valid_playlist_name(utf8path))
|
||||||
return PLAYLIST_RESULT_BAD_NAME;
|
return PLAYLIST_RESULT_BAD_NAME;
|
||||||
|
@ -293,13 +288,7 @@ appendSongToStoredPlaylistByPath(const char *utf8path, struct song *song)
|
||||||
return PLAYLIST_RESULT_TOO_LARGE;
|
return PLAYLIST_RESULT_TOO_LARGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = utf8_to_fs_charset(path_max_tmp2,
|
playlist_print_song(file, song);
|
||||||
song_get_url(song, path_max_tmp));
|
|
||||||
|
|
||||||
if (playlist_saveAbsolutePaths && song_is_file(song))
|
|
||||||
s = rmp2amp_r(path_max_tmp, s);
|
|
||||||
|
|
||||||
fprintf(file, "%s\n", s);
|
|
||||||
|
|
||||||
while (fclose(file) != 0 && errno == EINTR);
|
while (fclose(file) != 0 && errno == EINTR);
|
||||||
return PLAYLIST_RESULT_SUCCESS;
|
return PLAYLIST_RESULT_SUCCESS;
|
||||||
|
|
Loading…
Reference in New Issue