# HG changeset patch # User nenolod # Date 1134457890 28800 # Node ID e85198a7f34dc0f67e0c331ff977845346ad636a # Parent 374a11c096d299b23ae72183a13c90144d417c9b [svn] Vorbis UTF-8 tag conversion patch, via Takuo Kitame . diff -r 374a11c096d2 -r e85198a7f34d Plugins/Input/vorbis/configure.c --- a/Plugins/Input/vorbis/configure.c Sat Dec 10 19:12:53 2005 -0800 +++ b/Plugins/Input/vorbis/configure.c Mon Dec 12 23:11:30 2005 -0800 @@ -36,6 +36,9 @@ *title_desc; static GtkWidget *rg_switch, *rg_clip_switch, *rg_booster_switch, *rg_track_gain; +/* Encoding patch */ +static GtkWidget *title_encoding_hbox, *title_encoding_enabled, *title_encoding, *title_encoding_label; +/* Encoding patch */ vorbis_config_t vorbis_cfg; @@ -102,7 +105,10 @@ vorbis_cfg.replaygain_mode = REPLAYGAIN_MODE_TRACK; else vorbis_cfg.replaygain_mode = REPLAYGAIN_MODE_ALBUM; - + /* Encoding patch */ + vorbis_cfg.title_encoding_enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(title_encoding_enabled)); + vorbis_cfg.title_encoding = g_strdup(gtk_entry_get_text(GTK_ENTRY(title_encoding))); + /* Encoding patch */ db = bmp_cfg_db_open(); @@ -140,6 +146,10 @@ bmp_cfg_db_set_int(db, "vorbis", "replaygain_mode", vorbis_cfg.replaygain_mode); bmp_cfg_db_set_bool(db, "vorbis", "use_booster", vorbis_cfg.use_booster); + /* Encoding patch */ + bmp_cfg_db_set_bool(db, "vorbis", "title_encoding_enabled", vorbis_cfg.title_encoding_enabled); + bmp_cfg_db_set_string(db, "vorbis", "title_encoding", vorbis_cfg.title_encoding); + /* Encoding patch */ bmp_cfg_db_close(db); gtk_widget_destroy(vorbis_configurewin); } @@ -230,6 +240,17 @@ gtk_widget_set_sensitive(title_desc, override); } +/* Encoding patch */ +static void +title_encoding_enabled_cb(GtkWidget * w, gpointer data) +{ + gboolean encoding_enabled; + encoding_enabled = + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(title_encoding_enabled)); + gtk_widget_set_sensitive(title_encoding_hbox, encoding_enabled); +} +/* Encoding patch */ + static void rg_switch_cb(GtkWidget * w, gpointer data) { @@ -468,6 +489,31 @@ gtk_container_border_width(GTK_CONTAINER(title_tag_vbox), 5); gtk_container_add(GTK_CONTAINER(title_frame), title_tag_vbox); + /* Encoding patch */ + title_encoding_enabled = + gtk_check_button_new_with_label(_("Convert non-UTF8 Vorbis tags to UTF8")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(title_encoding_enabled), + vorbis_cfg.title_encoding_enabled); + g_signal_connect(G_OBJECT(title_encoding_enabled), "clicked", + G_CALLBACK(title_encoding_enabled_cb), NULL); + gtk_box_pack_start(GTK_BOX(title_tag_vbox), title_encoding_enabled, FALSE, + FALSE, 0); + + title_encoding_hbox = gtk_hbox_new(FALSE, 5); + gtk_widget_set_sensitive(title_encoding_hbox, vorbis_cfg.title_encoding_enabled); + gtk_box_pack_start(GTK_BOX(title_tag_vbox), title_encoding_hbox, FALSE, + FALSE, 0); + + title_encoding_label = gtk_label_new(_("Vorbis encoding:")); + gtk_box_pack_start(GTK_BOX(title_encoding_hbox), title_encoding_label, FALSE, + FALSE, 0); + + title_encoding = gtk_entry_new(); + gtk_entry_set_text(GTK_ENTRY(title_encoding), vorbis_cfg.title_encoding); + gtk_box_pack_start(GTK_BOX(title_encoding_hbox), title_encoding, TRUE, TRUE, + 0); + /* Encoding patch */ + title_tag_override = gtk_check_button_new_with_label(_("Override generic titles")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(title_tag_override), diff -r 374a11c096d2 -r e85198a7f34d Plugins/Input/vorbis/vorbis.c --- a/Plugins/Input/vorbis/vorbis.c Sat Dec 10 19:12:53 2005 -0800 +++ b/Plugins/Input/vorbis/vorbis.c Mon Dec 12 23:11:30 2005 -0800 @@ -127,6 +127,7 @@ GMutex *vf_mutex; static gboolean output_error; +gchar **vorbis_tag_encoding_list = NULL; InputPlugin * get_iplugin_info(void) @@ -547,6 +548,30 @@ return vorbis_ip.output->output_time(); } +static gchar * +convert_tag_title(gchar * title) +{ + gchar **encoding = vorbis_tag_encoding_list; + gchar *new_title = NULL; + + if (g_utf8_validate(title, -1, NULL)) + return title; + + while (*encoding && !new_title) { + new_title = g_convert(title, strlen(title), "UTF-8", *encoding++, + NULL, NULL, NULL); + } + + if (new_title) { + g_free(title); + return new_title; + } + + /* FIXME: We're relying on BMP core to provide fallback + * conversion */ + return title; +} + static void vorbis_seek(int time) { @@ -586,7 +611,6 @@ *title = NULL; *title = vorbis_generate_title(&vf, filename); - /* * once the ov_open succeeds, the stream belongs to * vorbisfile.a. ov_clear will fclose it @@ -598,6 +622,10 @@ /* streaming song info */ *length = -1; *title = (char *) vorbis_http_get_title(filename); +/* Encoding patch */ + if (vorbis_cfg.title_encoding_enabled) + *title = convert_tag_title(*title); +/* Encoding patch */ } } @@ -769,6 +797,10 @@ g_free(input->genre); g_free(input->comment); g_free(input); +/* Encoding patch */ + if (vorbis_cfg.title_encoding_enabled) + displaytitle = convert_tag_title(displaytitle); +/* Encoding patch */ return displaytitle; } @@ -823,6 +855,10 @@ vorbis_cfg.use_replaygain = FALSE; vorbis_cfg.replaygain_mode = REPLAYGAIN_MODE_TRACK; vorbis_cfg.use_booster = FALSE; +/* Encoding patch */ + vorbis_cfg.title_encoding_enabled = FALSE; + vorbis_cfg.title_encoding = NULL; +/* Encoding patch */ db = bmp_cfg_db_open(); bmp_cfg_db_get_int(db, "vorbis", "http_buffer_size", @@ -856,6 +892,13 @@ bmp_cfg_db_get_int(db, "vorbis", "replaygain_mode", &vorbis_cfg.replaygain_mode); bmp_cfg_db_get_bool(db, "vorbis", "use_booster", &vorbis_cfg.use_booster); + /* Encoding patch */ + bmp_cfg_db_get_bool(db, "vorbis", "title_encoding_enabled", &vorbis_cfg.title_encoding_enabled); + bmp_cfg_db_get_string(db, "vorbis", "title_encoding", &vorbis_cfg.title_encoding); + if (vorbis_cfg.title_encoding_enabled) + vorbis_tag_encoding_list = g_strsplit_set(vorbis_cfg.title_encoding, ENCODING_SEPARATOR, 0); + + /* Encoding patch */ bmp_cfg_db_close(db); vf_mutex = g_mutex_new(); @@ -864,6 +907,7 @@ static void vorbis_cleanup(void) { + g_strfreev(vorbis_tag_encoding_list); g_mutex_free(vf_mutex); } diff -r 374a11c096d2 -r e85198a7f34d Plugins/Input/vorbis/vorbis.h --- a/Plugins/Input/vorbis/vorbis.h Sat Dec 10 19:12:53 2005 -0800 +++ b/Plugins/Input/vorbis/vorbis.h Mon Dec 12 23:11:30 2005 -0800 @@ -30,6 +30,8 @@ gboolean use_replaygain; gint replaygain_mode; gboolean use_booster; + gboolean title_encoding_enabled; + gchar *title_encoding; } vorbis_config_t; enum { @@ -38,4 +40,6 @@ REPLAYGAIN_MODE_LAST }; +#define ENCODING_SEPARATOR " ,:;|/" + #endif /* __VORBIS_H__ */