
#include "includes.h"
#include "common-externs.h"

void	get_meta(libvlc_media_t *media) {

	char meta_album[1024] = "";
	char meta_artist[1024] = "";
	char meta_title[1024] = "";
	char meta_genre[1024] = "";
	char meta_date[1024] = "";
	char meta_artwork[4096] = "";       /* Added this for retrieving artwork from ".m4a" files */
	char *p1;

//	libvlc_media_parse(media);

#ifdef VLC4
	libvlc_media_parse_request(inst, media, libvlc_media_parse_local,  -1);
#else
	libvlc_media_parse(media);
#endif

	p1 = libvlc_media_get_meta(media,libvlc_meta_Album);
	if (p1) strncpy(meta_album, libvlc_media_get_meta(media,libvlc_meta_Album), 1024);

	p1 = libvlc_media_get_meta(media,libvlc_meta_Title);
	if (p1) strncpy(meta_title, libvlc_media_get_meta(media,libvlc_meta_Title), 1024);

	p1 = libvlc_media_get_meta(media,libvlc_meta_Genre);
	if (p1) strncpy(meta_genre, libvlc_media_get_meta(media,libvlc_meta_Genre), 1024);

	p1 = libvlc_media_get_meta(media,libvlc_meta_Date);
	if (p1) strncpy(meta_date, libvlc_media_get_meta(media,libvlc_meta_Date), 1024);

	p1 = libvlc_media_get_meta(media,libvlc_meta_Artist);
	if (p1) strncpy(meta_artist, libvlc_media_get_meta(media,libvlc_meta_Artist), 1024);

	/* Retrieve artwork contributed by Craig Schulstad*/
	p1 = libvlc_media_get_meta(media,libvlc_meta_ArtworkURL);
	if (p1) strncpy(meta_artwork, libvlc_media_get_meta(media,libvlc_meta_ArtworkURL), 4096);

	/* Place the artwork in the web window */
	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(art_metadata)))
		if (meta_artwork[0] != '\0')
			webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webkit), meta_artwork);

	printf("\n-->Album: %s\n-->Artist: %s\n-->Title: %s\n-->Genre: %s\n-->Date: %s\n-->Artwork URL: %s\n\n",
	       meta_album, meta_artist, meta_title, meta_genre, meta_date, meta_artwork);
	}
