Re: [PATCH] use title stream when saving stream
Tuomas Jaakola <[email protected]>
| Newsgroups | gmane.comp.multimedia.xmms.devel |
|---|---|
| Message-ID | <[email protected]> |
Tuomas Jaakola wrote: > I'm new here on the list so I'm not sure if this kind of feature > is existing already. But here it comes anyway.. I hope it's > bug-free. :) Well, that hoping was in vain.. it included bugs. :) One bug exists already in the current Xmms version: when saving the stream, if the target file cannot be accessed the new filename will be generated wrong and new target file is not created. The new patch comes here as an attachment. It's also available on http://tumppi.net/xmms-stream-saving.diff This time I don't hope anything. Regards, -- # Tuomas Jaakola
xmms-stream-saving.diff
(text/plain, 3.5 KB)
Index: Input/mpg123/http.c
===================================================================
RCS file: /cvs/xmms/Input/mpg123/http.c,v
retrieving revision 1.30
diff -u -1 -b -p -u -r1.30 http.c
--- Input/mpg123/http.c 1 Sep 2003 20:18:53 -0000 1.30
+++ Input/mpg123/http.c 25 Sep 2003 20:58:39 -0000
@@ -54,3 +54,3 @@ static gint sock, rd_index, wr_index, bu
static guint64 buffer_read = 0;
-static gchar *buffer;
+static gchar *buffer, *title = NULL;
static pthread_t thread;
@@ -254,6 +254,11 @@ int mpg123_http_read(gpointer data, gint
{
- char *temp = tags[i] + 13;
- char *title = g_strdup_printf("%s (%s)", temp, icy_name);
- mpg123_ip.set_info(title, -1, mpg123_bitrate * 1000, mpg123_frequency, mpg123_stereo);
+ char *new_title = g_strdup_printf("%s (%s)", tags[i] + 13, icy_name);
+ mpg123_ip.set_info(new_title, -1, mpg123_bitrate * 1000, mpg123_frequency, mpg123_stereo);
+ if (output_file && strcmp(new_title, title))
+ {
g_free(title);
+ title = g_strdup(new_title);
+ mpg123_http_create_output_file();
+ }
+ g_free(new_title);
}
@@ -618,30 +623,4 @@ static void *http_buffer_loop(void *arg)
{
- char *output_name;
- int i = 1;
-
- file = mpg123_http_get_title(url);
- output_name = file;
- if (!strncasecmp(output_name, "http://", 7))
- output_name += 7;
- temp = strrchr(output_name, '.');
- if (temp && !strcasecmp(temp, ".mp3"))
- *temp = '\0';
-
- while ((temp = strchr(output_name, '/')))
- *temp = '_';
- output_name = g_strdup_printf("%s/%s.mp3",
- mpg123_cfg.save_http_path,
- output_name);
- while (!access(output_name, F_OK) && i < 100000)
- {
- g_free(output_name);
- output_name = g_strdup_printf("%s/%s-%d.mp3",
- mpg123_cfg.save_http_path,
- output_name, i++);
- }
-
- g_free(file);
-
- output_file = fopen(output_name, "wb");
- g_free(output_name);
+ title = mpg123_http_get_title(url);
+ mpg123_http_create_output_file();
}
@@ -717,2 +696,3 @@ static void *http_buffer_loop(void *arg)
g_free(url);
+ if (title) g_free(title);
@@ -741,2 +721,36 @@ int mpg123_http_open(gchar * _url)
return 0;
+}
+
+void mpg123_http_create_output_file(void)
+{
+ gchar *temp, *ptr, *file_name;
+ char *output_name;
+ int i = 1;
+
+ if (output_file)
+ fclose(output_file);
+
+ temp = g_strdup(title);
+ file_name = temp;
+ if (!strncasecmp(file_name, "http://", 7))
+ file_name += 7;
+ ptr = strrchr(file_name, '.');
+ if (ptr && !strcasecmp(ptr, ".mp3"))
+ *ptr = '\0';
+
+ while ((ptr = strchr(file_name, '/')))
+ *ptr = '_';
+ output_name = g_strdup_printf("%s/%s.mp3",
+ mpg123_cfg.save_http_path,
+ file_name);
+ while (!access(output_name, F_OK) && i < 100000)
+ {
+ g_free(output_name);
+ output_name = g_strdup_printf("%s/%s-%d.mp3",
+ mpg123_cfg.save_http_path,
+ file_name, i++);
+ }
+ output_file = fopen(output_name, "wb");
+ g_free(output_name);
+ g_free(temp);
}
Index: Input/mpg123/mpg123.h
===================================================================
RCS file: /cvs/xmms/Input/mpg123/mpg123.h,v
retrieving revision 1.23
diff -u -1 -b -p -u -r1.23 mpg123.h
--- Input/mpg123/mpg123.h 2 Sep 2003 17:36:23 -0000 1.23
+++ Input/mpg123/mpg123.h 25 Sep 2003 20:58:39 -0000
@@ -176,2 +176,3 @@ extern struct bitstream_info bsi;
extern int mpg123_http_open(char *url);
+void mpg123_http_create_output_file(void);
int mpg123_http_read(gpointer data, gint length);