2010-02-08 10:56:28 +01:00
|
|
|
/*
|
2013-01-02 18:38:32 +01:00
|
|
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
2010-02-08 10:56:28 +01:00
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2013-01-02 18:38:32 +01:00
|
|
|
#include "PlaylistMapper.hxx"
|
2012-09-28 00:40:00 +02:00
|
|
|
#include "PlaylistFile.hxx"
|
2013-01-02 22:43:56 +01:00
|
|
|
#include "Mapper.hxx"
|
2013-01-17 00:56:57 +01:00
|
|
|
#include "Path.hxx"
|
2012-09-27 22:55:57 +02:00
|
|
|
|
|
|
|
extern "C" {
|
2010-02-08 10:56:28 +01:00
|
|
|
#include "playlist_list.h"
|
|
|
|
#include "uri.h"
|
2012-09-27 22:55:57 +02:00
|
|
|
}
|
2010-02-08 10:56:28 +01:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
static struct playlist_provider *
|
2011-09-14 21:46:41 +02:00
|
|
|
playlist_open_path(const char *path_fs, GMutex *mutex, GCond *cond,
|
|
|
|
struct input_stream **is_r)
|
2010-02-08 10:56:28 +01:00
|
|
|
{
|
|
|
|
struct playlist_provider *playlist;
|
|
|
|
|
2011-09-14 21:46:41 +02:00
|
|
|
playlist = playlist_list_open_uri(path_fs, mutex, cond);
|
2010-06-01 09:10:58 +02:00
|
|
|
if (playlist != NULL)
|
|
|
|
*is_r = NULL;
|
|
|
|
else
|
2011-09-14 21:46:41 +02:00
|
|
|
playlist = playlist_list_open_path(path_fs, mutex, cond, is_r);
|
2010-02-08 10:56:28 +01:00
|
|
|
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a playlist from the configured playlist directory.
|
|
|
|
*/
|
|
|
|
static struct playlist_provider *
|
2011-09-14 21:46:41 +02:00
|
|
|
playlist_open_in_playlist_dir(const char *uri, GMutex *mutex, GCond *cond,
|
|
|
|
struct input_stream **is_r)
|
2010-02-08 10:56:28 +01:00
|
|
|
{
|
|
|
|
char *path_fs;
|
|
|
|
|
|
|
|
assert(spl_valid_name(uri));
|
|
|
|
|
|
|
|
const char *playlist_directory_fs = map_spl_path();
|
|
|
|
if (playlist_directory_fs == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
path_fs = g_build_filename(playlist_directory_fs, uri, NULL);
|
|
|
|
|
2011-09-14 21:46:41 +02:00
|
|
|
struct playlist_provider *playlist =
|
|
|
|
playlist_open_path(path_fs, mutex, cond, is_r);
|
2010-02-08 10:56:28 +01:00
|
|
|
g_free(path_fs);
|
|
|
|
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a playlist from the configured music directory.
|
|
|
|
*/
|
|
|
|
static struct playlist_provider *
|
2011-09-14 21:46:41 +02:00
|
|
|
playlist_open_in_music_dir(const char *uri, GMutex *mutex, GCond *cond,
|
|
|
|
struct input_stream **is_r)
|
2010-02-08 10:56:28 +01:00
|
|
|
{
|
|
|
|
assert(uri_safe_local(uri));
|
|
|
|
|
2013-01-17 00:56:57 +01:00
|
|
|
Path path = map_uri_fs(uri);
|
|
|
|
if (path.IsNull())
|
2010-02-08 10:56:28 +01:00
|
|
|
return NULL;
|
|
|
|
|
2013-01-17 00:56:57 +01:00
|
|
|
return playlist_open_path(path.c_str(), mutex, cond, is_r);
|
2010-02-08 10:56:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct playlist_provider *
|
2011-09-14 21:46:41 +02:00
|
|
|
playlist_mapper_open(const char *uri, GMutex *mutex, GCond *cond,
|
|
|
|
struct input_stream **is_r)
|
2010-02-08 10:56:28 +01:00
|
|
|
{
|
|
|
|
struct playlist_provider *playlist;
|
|
|
|
|
|
|
|
if (spl_valid_name(uri)) {
|
2011-09-14 21:46:41 +02:00
|
|
|
playlist = playlist_open_in_playlist_dir(uri, mutex, cond,
|
|
|
|
is_r);
|
2010-02-08 10:56:28 +01:00
|
|
|
if (playlist != NULL)
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uri_safe_local(uri)) {
|
2011-09-14 21:46:41 +02:00
|
|
|
playlist = playlist_open_in_music_dir(uri, mutex, cond, is_r);
|
2010-02-08 10:56:28 +01:00
|
|
|
if (playlist != NULL)
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|