[PATCH] use title stream when saving stream
Tuomas Jaakola <[email protected]>
| Newsgroups | gmane.comp.multimedia.xmms.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi folks! I made a patch for saving stream feature of MPG123 input plugin. With this patch the plugin creates a file which name corresponds the title it gets from the stream. Whenever the title changes, the plugin will create a new file matching the title. I didn't make this feature configurable, I suppose that anyone who is using title stream and wants to save stream to disk, wants this feature enabled. If title stream is not used or received, saving will work as before. 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. :) Regards, -- # Tuomas Jaakola
xmms-stream-saving.diff
(text/plain, 3 KB)
Index: Input/mpg123/http.c
===================================================================
RCS file: /cvs/xmms/Input/mpg123/http.c,v
retrieving revision 1.30
diff -u -r1.30 http.c
--- Input/mpg123/http.c 1 Sep 2003 20:18:53 -0000 1.30
+++ Input/mpg123/http.c 23 Sep 2003 21:26:42 -0000
@@ -255,6 +255,8 @@
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);
+ if (output_file)
+ mpg123_http_create_output_file(title);
g_free(title);
}
@@ -616,34 +618,9 @@
if (mpg123_cfg.save_http_stream)
{
- 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);
+ gchar *file = mpg123_http_get_title(url);
+ mpg123_http_create_output_file(file);
+ g_free(file);
}
while (going)
@@ -739,6 +716,39 @@
pthread_create(&thread, NULL, http_buffer_loop, url);
return 0;
+}
+
+void mpg123_http_create_output_file(char *title)
+{
+ gchar *temp;
+ char *output_name;
+ int i = 1;
+
+ if (output_file)
+ fclose(output_file);
+
+ output_name = title;
+ 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++);
+ }
+
+ output_file = fopen(output_name, "wb");
+ g_free(output_name);
}
char *mpg123_http_get_title(char *url)
Index: Input/mpg123/mpg123.h
===================================================================
RCS file: /cvs/xmms/Input/mpg123/mpg123.h,v
retrieving revision 1.23
diff -u -r1.23 mpg123.h
--- Input/mpg123/mpg123.h 2 Sep 2003 17:36:23 -0000 1.23
+++ Input/mpg123/mpg123.h 23 Sep 2003 21:26:42 -0000
@@ -174,6 +174,7 @@
/* ------ Declarations from "http.c" ------ */
extern int mpg123_http_open(char *url);
+void mpg123_http_create_output_file(char *title);
int mpg123_http_read(gpointer data, gint length);
void mpg123_http_close(void);
char *mpg123_http_get_title(char * url);