00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "debug.h"
00023 #include "playlist.h"
00024 #include "plugin.h"
00025 #include "plugins.h"
00026
00027 static const gchar * get_extension (const gchar * filename, gboolean quiet)
00028 {
00029 const gchar * s = strrchr (filename, '/');
00030 if (! s)
00031 goto FAIL;
00032
00033 const gchar * p = strrchr (s + 1, '.');
00034 if (! p)
00035 goto FAIL;
00036
00037 return p + 1;
00038
00039 FAIL:
00040 if (! quiet)
00041 fprintf (stderr, "Failed to parse playlist filename %s.\n", filename);
00042 return NULL;
00043 }
00044
00045 gboolean filename_is_playlist (const gchar * filename)
00046 {
00047 const gchar * ext = get_extension (filename, TRUE);
00048 if (! ext)
00049 return FALSE;
00050
00051 return playlist_plugin_for_extension (ext) ? TRUE : FALSE;
00052 }
00053
00054 static PlaylistPlugin * get_plugin (const gchar * filename)
00055 {
00056 const gchar * ext = get_extension (filename, FALSE);
00057 if (! ext)
00058 return NULL;
00059
00060 PluginHandle * plugin = playlist_plugin_for_extension (ext);
00061 if (! plugin)
00062 {
00063 fprintf (stderr, "Unrecognized playlist file type \"%s\".\n", ext);
00064 return NULL;
00065 }
00066
00067 return plugin_get_header (plugin);
00068 }
00069
00070 gboolean playlist_insert_playlist (gint list, gint at, const gchar * filename)
00071 {
00072 AUDDBG ("Loading playlist %s.\n", filename);
00073 PlaylistPlugin * pp = get_plugin (filename);
00074 g_return_val_if_fail (pp && pp->load, FALSE);
00075 return pp->load (filename, list, at);
00076 }
00077
00078 gboolean playlist_save (gint list, const gchar * filename)
00079 {
00080 AUDDBG ("Saving playlist %s.\n", filename);
00081 PlaylistPlugin * pp = get_plugin (filename);
00082 g_return_val_if_fail (pp && pp->save, FALSE);
00083 return pp->save (filename, list);
00084 }