Mercurial > audlegacy
changeset 1559:9a1e4bca7d8b trunk
[svn] - m3u works again
author | nenolod |
---|---|
date | Thu, 10 Aug 2006 19:35:03 -0700 |
parents | a6793cf239e9 |
children | 5840d797ea02 |
files | ChangeLog audacious/Makefile audacious/main.c audacious/playlist.c audacious/playlist_container.h audacious/playlist_m3u.c audacious/playlist_pls.c |
diffstat | 7 files changed, 211 insertions(+), 159 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Aug 10 19:24:55 2006 -0700 +++ b/ChangeLog Thu Aug 10 19:35:03 2006 -0700 @@ -1,3 +1,13 @@ +2006-08-11 02:24:55 +0000 William Pitcock <nenolod@nenolod.net> + revision [2030] + - .pls playlists work again, now to do M3Us. + + + Changes: Modified: + +10 -0 trunk/audacious/main.c + +6 -0 trunk/audacious/playlist_pls.c + + 2006-08-11 02:21:37 +0000 William Pitcock <nenolod@nenolod.net> revision [2028] - make it compile
--- a/audacious/Makefile Thu Aug 10 19:24:55 2006 -0700 +++ b/audacious/Makefile Thu Aug 10 19:35:03 2006 -0700 @@ -45,6 +45,7 @@ playlist.c \ playlist_container.c \ playlist_pls.c \ + playlist_m3u.c \ controlsocket.c \ dock.c \ playback.c \
--- a/audacious/main.c Thu Aug 10 19:24:55 2006 -0700 +++ b/audacious/main.c Thu Aug 10 19:35:03 2006 -0700 @@ -1079,10 +1079,7 @@ } temporary_pls_register(); - -#ifdef NOTYET temporary_m3u_register(); -#endif plugin_system_init();
--- a/audacious/playlist.c Thu Aug 10 19:24:55 2006 -0700 +++ b/audacious/playlist.c Thu Aug 10 19:35:03 2006 -0700 @@ -118,9 +118,6 @@ playlist_compare_playlist }; -static void playlist_save_m3u(FILE * file); -static void playlist_save_pls(FILE * file); - static guint playlist_load_ins(const gchar * filename, gint pos); static void playlist_generate_shuffle_list(void); @@ -1247,46 +1244,6 @@ return len; } -static void -playlist_save_m3u(FILE * file) -{ - GList *node; - gchar *outstr = NULL; - - g_return_if_fail(file != NULL); - - if (cfg.use_pl_metadata) - g_fprintf(file, "#EXTM3U\n"); - - PLAYLIST_LOCK(); - - for (node = playlist; node; node = g_list_next(node)) { - PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); - - if (entry->title && cfg.use_pl_metadata) { - gint seconds; - - if (entry->length > 0) - seconds = (entry->length) / 1000; - else - seconds = -1; - - outstr = g_locale_from_utf8(entry->title, -1, NULL, NULL, NULL); - if(outstr) { - g_fprintf(file, "#EXTINF:%d,%s\n", seconds, outstr); - g_free(outstr); - outstr = NULL; - } else { - g_fprintf(file, "#EXTINF:%d,%s\n", seconds, entry->title); - } - } - - g_fprintf(file, "%s\n", entry->filename); - } - - PLAYLIST_UNLOCK(); -} - gboolean playlist_save(const gchar * filename) { @@ -1376,115 +1333,6 @@ g_free(filename); } -static void -parse_extm3u_info(const gchar * info, gchar ** title, gint * length) -{ - gchar *str; - - g_return_if_fail(info != NULL); - g_return_if_fail(title != NULL); - g_return_if_fail(length != NULL); - - *title = NULL; - *length = -1; - - if (!str_has_prefix_nocase(info, "#EXTINF:")) { - g_message("Invalid m3u metadata (%s)", info); - return; - } - - info += 8; - - *length = atoi(info); - if (*length <= 0) - *length = -1; - else - *length *= 1000; - - if ((str = strchr(info, ','))) { - *title = g_strstrip(g_strdup(str + 1)); - if (strlen(*title) < 1) { - g_free(*title); - *title = NULL; - } - } -} - -static guint -playlist_load_m3u(const gchar * filename, gint pos) -{ - FILE *file; - gchar *line; - gchar *ext_info = NULL, *ext_title = NULL; - gsize line_len = 1024; - gint ext_len = -1; - gboolean is_extm3u = FALSE; - guint added_count = 0; - - if (!(file = fopen(filename, "r"))) - return 0; - - line = g_malloc(line_len); - while (fgets(line, line_len, file)) { - while (strlen(line) == line_len - 1 && line[strlen(line) - 1] != '\n') { - line_len += 1024; - line = g_realloc(line, line_len); - fgets(&line[strlen(line)], 1024, file); - } - - while (line[strlen(line) - 1] == '\r' || - line[strlen(line) - 1] == '\n') - line[strlen(line) - 1] = '\0'; - - if (str_has_prefix_nocase(line, "#EXTM3U")) { - is_extm3u = TRUE; - continue; - } - - if (is_extm3u && str_has_prefix_nocase(line, "#EXTINF:")) { - str_replace_in(&ext_info, g_strdup(line)); - continue; - } - - if (line[0] == '#' || strlen(line) == 0) { - if (ext_info) { - g_free(ext_info); - ext_info = NULL; - } - continue; - } - - if (is_extm3u) { - if (cfg.use_pl_metadata && ext_info) - parse_extm3u_info(ext_info, &ext_title, &ext_len); - g_free(ext_info); - ext_info = NULL; - } - - playlist_load_ins_file(line, filename, pos, ext_title, ext_len); - - str_replace_in(&ext_title, NULL); - ext_len = -1; - - added_count++; - if (pos >= 0) - pos++; - } - - fclose(file); - g_free(line); - - playlist_generate_shuffle_list(); - playlistwin_update_list(); - - if (g_ascii_strcasecmp(filename, BMP_PLAYLIST_BASENAME)) - playlist_set_current_name(NULL); - else - playlist_set_current_name(filename); - - return added_count; -} - static guint playlist_load_ins(const gchar * filename, gint pos) {
--- a/audacious/playlist_container.h Thu Aug 10 19:24:55 2006 -0700 +++ b/audacious/playlist_container.h Thu Aug 10 19:35:03 2006 -0700 @@ -24,8 +24,8 @@ struct _PlaylistContainer { char *name; /* human-readable name */ char *ext; /* extension */ - GList *(*plc_read)(char *filename, gint pos); /* plc_load */ - void (*plc_write)(char *filename, gint pos); /* plc_write */ + void (*plc_read)(const gchar *filename, gint pos); /* plc_load */ + void (*plc_write)(const gchar *filename, gint pos); /* plc_write */ }; typedef struct _PlaylistContainer PlaylistContainer;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/audacious/playlist_m3u.c Thu Aug 10 19:35:03 2006 -0700 @@ -0,0 +1,195 @@ +/* + * Audacious: A cross-platform multimedia player + * Copyright (c) 2006 William Pitcock, Tony Vroon, George Averill, + * Giacomo Lozito, Derek Pomery and Yoshiki Yazawa. + * + * 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 <glib.h> +#include <string.h> +#include <glib.h> +#include <glib/gprintf.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/errno.h> + +#include "main.h" +#include "util.h" +#include "playlist.h" +#include "playlist_container.h" + +static void +parse_extm3u_info(const gchar * info, gchar ** title, gint * length) +{ + gchar *str; + + g_return_if_fail(info != NULL); + g_return_if_fail(title != NULL); + g_return_if_fail(length != NULL); + + *title = NULL; + *length = -1; + + if (!str_has_prefix_nocase(info, "#EXTINF:")) { + g_message("Invalid m3u metadata (%s)", info); + return; + } + + info += 8; + + *length = atoi(info); + if (*length <= 0) + *length = -1; + else + *length *= 1000; + + if ((str = strchr(info, ','))) { + *title = g_strstrip(g_strdup(str + 1)); + if (strlen(*title) < 1) { + g_free(*title); + *title = NULL; + } + } +} + +static void +playlist_load_m3u(const gchar * filename, gint pos) +{ + FILE *file; + gchar *line; + gchar *ext_info = NULL, *ext_title = NULL; + gsize line_len = 1024; + gint ext_len = -1; + gboolean is_extm3u = FALSE; + + if (!(file = fopen(filename, "r"))) + return; + + line = g_malloc(line_len); + while (fgets(line, line_len, file)) { + while (strlen(line) == line_len - 1 && line[strlen(line) - 1] != '\n') { + line_len += 1024; + line = g_realloc(line, line_len); + fgets(&line[strlen(line)], 1024, file); + } + + while (line[strlen(line) - 1] == '\r' || + line[strlen(line) - 1] == '\n') + line[strlen(line) - 1] = '\0'; + + if (str_has_prefix_nocase(line, "#EXTM3U")) { + is_extm3u = TRUE; + continue; + } + + if (is_extm3u && str_has_prefix_nocase(line, "#EXTINF:")) { + str_replace_in(&ext_info, g_strdup(line)); + continue; + } + + if (line[0] == '#' || strlen(line) == 0) { + if (ext_info) { + g_free(ext_info); + ext_info = NULL; + } + continue; + } + + if (is_extm3u) { + if (cfg.use_pl_metadata && ext_info) + parse_extm3u_info(ext_info, &ext_title, &ext_len); + g_free(ext_info); + ext_info = NULL; + } + + playlist_load_ins_file(line, filename, pos, ext_title, ext_len); + + str_replace_in(&ext_title, NULL); + ext_len = -1; + + if (pos >= 0) + pos++; + } + + fclose(file); + g_free(line); +} + +static void +playlist_save_m3u(const gchar *filename, gint pos) +{ + GList *node; + gchar *outstr = NULL; + FILE *file; + + g_return_if_fail(filename != NULL); + + file = fopen(filename, "wb"); + + g_return_if_fail(file != NULL); + + if (cfg.use_pl_metadata) + g_fprintf(file, "#EXTM3U\n"); + + PLAYLIST_LOCK(); + + for (node = playlist_get(); node; node = g_list_next(node)) { + PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); + + if (entry->title && cfg.use_pl_metadata) { + gint seconds; + + if (entry->length > 0) + seconds = (entry->length) / 1000; + else + seconds = -1; + + outstr = g_locale_from_utf8(entry->title, -1, NULL, NULL, NULL); + if(outstr) { + g_fprintf(file, "#EXTINF:%d,%s\n", seconds, outstr); + g_free(outstr); + outstr = NULL; + } else { + g_fprintf(file, "#EXTINF:%d,%s\n", seconds, entry->title); + } + } + + g_fprintf(file, "%s\n", entry->filename); + } + + PLAYLIST_UNLOCK(); + + fclose(file); +} + +PlaylistContainer plc_m3u = { + .name = "M3U Playlist Format", + .ext = "m3u", + .plc_read = playlist_load_m3u, + .plc_write = playlist_save_m3u, +}; + +void +temporary_m3u_register(void) +{ + playlist_container_register(&plc_m3u); +} +
--- a/audacious/playlist_pls.c Thu Aug 10 19:24:55 2006 -0700 +++ b/audacious/playlist_pls.c Thu Aug 10 19:35:03 2006 -0700 @@ -31,6 +31,7 @@ #include <sys/stat.h> #include <sys/errno.h> +#include "util.h" #include "playlist.h" #include "playlist_container.h" @@ -41,7 +42,7 @@ gchar key[10]; gchar *line; - g_return_val_if_fail(filename != NULL, 0); + g_return_if_fail(filename != NULL); if (!str_has_suffix_nocase(filename, ".pls")) return; @@ -67,7 +68,7 @@ } static void -playlist_save_pls(gchar *filename, gint pos) +playlist_save_pls(const gchar *filename, gint pos) { GList *node; FILE *file = fopen(filename, "wb");