1 /* gmpc-exiftool (GMPC plugin)
2 * Copyright (C) 2006-2010 Qball Cow <qball@sarine.nl>
3 * Project homepage: http://gmpcwiki.sarine.nl/
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <gmpc/plugin.h>
26 #include <gmpc/metadata.h>
27 #include <libmpd/libmpd.h>
28 #include <libmpd/debug_printf.h>
32 static PerlInterpreter
*my_perl
;
33 int fetch_get_image(mpd_Song
*song
,MetaDataType type
,void (*callback
)(GList
*uris
, gpointer data
), gpointer data
) ;
34 void music_dir_cover_art_pref_construct(GtkWidget
*container
);
35 void music_dir_cover_art_pref_destroy(GtkWidget
*container
);
36 GList
* fetch_cover_art_path_list(mpd_Song
*song
);
37 GList
* fetch_cover_art_path(mpd_Song
*song
);
38 static GtkWidget
*wp_pref_vbox
= NULL
;
46 * Enable/Disable state of the plugins
48 static int exiftool_get_enabled()
50 return cfg_get_single_value_as_int_with_default(config
, "exiftool-cover", "enable", TRUE
);
52 static void exiftool_set_enabled(int enabled
)
54 cfg_set_single_value_as_int(config
, "exiftool-cover", "enable", enabled
);
57 static int fetch_cover_priority()
59 return cfg_get_single_value_as_int_with_default(config
, "exiftool-cover", "priority", 10);
62 static void fetch_cover_priority_set(int priority
)
64 cfg_set_single_value_as_int(config
, "exiftool-cover", "priority", priority
);
69 int fetch_get_image(mpd_Song
*song
,MetaDataType type
,void (*callback
)(GList
*uris
, gpointer data
), gpointer data
)
75 int retval
= META_DATA_UNAVAILABLE
;
76 if(song
== NULL
|| song
->file
== NULL
)
78 debug_printf(DEBUG_INFO
, "ExifTool: No file path to look at.");
80 return META_DATA_UNAVAILABLE
;
82 if(type
== META_ALBUM_ART
)
84 const gchar
*musicroot
= connection_get_music_directory();
87 gchar
*file
= g_build_filename(musicroot
, song
->file
, NULL
);
88 if(g_file_test( file
, G_FILE_TEST_EXISTS
))
92 char *embedding
[] = {"", "-e", "0"};
94 my_perl
= perl_alloc();
95 perl_construct( my_perl
);
96 perl_parse(my_perl
, NULL
, 3,embedding
, (char **)NULL
);
97 PL_exit_flags
|= PERL_EXIT_DESTRUCT_END
;
100 eval_pv("use Image::ExifTool ':Public'", TRUE
);
101 SV
*sv2
= get_sv ("path", TRUE
);
103 eval_pv("$info = ImageInfo($path)", TRUE
);
104 eval_pv("$return = $$info{'Picture'};", TRUE
);
105 SV
*sv
= get_sv("return", FALSE
);
106 while(sv
&& SvROK(sv
) != 0)
110 gchar
*image
= SvPV(sv
, length
);
113 printf("Exif data tool got image: %s\n", file
);
114 md
= meta_data_new();
116 md
->plugin_name
= plugin
.name
;
117 md
->content_type
= META_DATA_CONTENT_RAW
;
118 md
->content
= g_memdup(image
, length
);
120 list
= g_list_append(list
, md
);
121 retval
= META_DATA_AVAILABLE
;
124 path
= g_strdup_printf("$return = $$info{'Picture (%i)'};",num_image
);
127 sv
= get_sv("return", FALSE
);
129 perl_destruct(my_perl
);
131 g_free(perl_program
);
137 callback(list
, data
);
143 gmpcMetaDataPlugin exiftool_cover
= {
144 .get_priority
= fetch_cover_priority
,
145 .set_priority
= fetch_cover_priority_set
,
146 .get_metadata
= fetch_get_image
148 /* a workaround so gmpc has some sort of api checking */
149 int plugin_api_version
= PLUGIN_API_VERSION
;
151 void exiftool_init(void)
154 static const gchar
*exiftool_get_translation_domain(void)
159 gmpcPlugin plugin
= {
160 .name
= ("Exiftool Dir Fetcher"),
162 .plugin_type
= GMPC_PLUGIN_META_DATA
,
163 .init
= exiftool_init
,
164 .metadata
= &exiftool_cover
, /* meta data */
165 .get_enabled
= exiftool_get_enabled
,
166 .set_enabled
= exiftool_set_enabled
,
167 .get_translation_domain
= exiftool_get_translation_domain