Example #1
0
enum file_type
get_file_type(gchar *file)
{
	gint ret = -1;
	gchar *result = NULL;

	if (!file)
		return -1;

	result = get_mime_type(file);

	if (result) {
		if (is_valid_mime(result, mime_wav))
			ret = FILE_WAV;
		else if(is_valid_mime(result, mime_mpeg))
			ret = FILE_MP3;
		else if(is_valid_mime(result, mime_flac))
			ret = FILE_FLAC;
		else if(is_valid_mime(result, mime_ogg))
			ret = FILE_OGGVORBIS;
		else if(is_valid_mime(result, mime_modplug))
			ret = FILE_MODPLUG;
		else ret = -1;
	}

	g_free(result);
	return ret;
}
Example #2
0
PraghaMediaType
pragha_file_get_media_type (const gchar *filename)
{
	PraghaMediaType ret = MEDIA_TYPE_UNKNOWN;
	gchar *result = NULL;

	if (!filename)
		return ret;

#ifdef G_OS_WIN32
	result = get_mime_type_from_uri (filename, NULL);
#else
	result = get_mime_type (filename);
#endif

	if (result) {
		if (is_valid_mime(result, mime_flac) ||
		    is_valid_mime(result, mime_mpeg) ||
		    is_valid_mime(result, mime_ogg) ||
		    is_valid_mime(result, mime_wav) ||
		    is_valid_mime(result, mime_asf) ||
		    is_valid_mime(result, mime_mp4) ||
		    is_valid_mime(result, mime_ape) ||
		    is_valid_mime(result, mime_tracker))
			ret = MEDIA_TYPE_AUDIO;
		#ifdef HAVE_PLPARSER
		else if (is_valid_mime(result, mime_playlist))
		#else
		else if (g_str_has_suffix (filename, ".m3u") || g_str_has_suffix (filename, ".M3U") ||
		         g_str_has_suffix (filename, ".pls") || g_str_has_suffix (filename, ".PLS") ||
		         g_str_has_suffix (filename, ".xspf") || g_str_has_suffix (filename, ".XSPF") ||
		         g_str_has_suffix (filename, ".asx") || g_str_has_suffix (filename, ".ASX") ||
		         g_str_has_suffix (filename, ".wax") || g_str_has_suffix (filename, ".WAX"))
		#endif
			ret = MEDIA_TYPE_PLAYLIST;
		else if (is_valid_mime(result, mime_image))
			ret = MEDIA_TYPE_IMAGE;
	}

	g_free(result);

	return ret;
}
Example #3
0
gboolean is_image_file(const gchar *file)
{
	gboolean uncertain = FALSE, ret = FALSE;
	gchar *result = NULL;

	if (!file)
		return FALSE;

	/* Type: JPG, PNG */

	result = g_content_type_guess(file, NULL, 0, &uncertain);

	if (!result)
		return FALSE;
	else {
		ret = is_valid_mime(result, mime_image);
		g_free(result);
		return ret;
	}
}
Example #4
0
PraghaMusicType
pragha_file_get_music_type(const gchar *filename)
{
	PraghaMusicType ret = FILE_NONE;
	gchar *result = NULL;

	if (!filename)
		return ret;

#ifdef G_OS_WIN32
	result = get_mime_type_from_uri (filename, NULL);
#else
	result = get_mime_type (filename);
#endif

	if (result) {
		if(is_valid_mime(result, mime_flac))
			ret = FILE_FLAC;
		else if(is_valid_mime(result, mime_mpeg))
			ret = FILE_MP3;
		else if(is_valid_mime(result, mime_ogg))
			ret = FILE_OGGVORBIS;
		else if (is_valid_mime(result, mime_wav))
			ret = FILE_WAV;
		else if (is_valid_mime(result, mime_asf))
			ret = FILE_ASF;
		else if (is_valid_mime(result, mime_mp4))
			ret = FILE_MP4;
		else if (is_valid_mime(result, mime_ape))
			ret = FILE_APE;
		else if (is_valid_mime(result, mime_tracker))
			ret = FILE_TRACKER;
	}
	g_free(result);

	return ret;
}
Example #5
0
enum file_type
get_file_type(const gchar *file)
{
	gint ret = -1;
	gchar *result = NULL;

	if (!file)
		return -1;

	result = get_mime_type(file);

	if (result) {
		if(is_valid_mime(result, mime_flac))
			ret = FILE_FLAC;
		else if(is_valid_mime(result, mime_mpeg))
			ret = FILE_MP3;
		else if(is_valid_mime(result, mime_ogg))
			ret = FILE_OGGVORBIS;
		else if (is_valid_mime(result, mime_wav))
			ret = FILE_WAV;
		#if defined(TAGLIB_WITH_ASF) && (TAGLIB_WITH_ASF==1)
		else if (is_valid_mime(result, mime_asf))
			ret = FILE_ASF;
		#endif
		#if defined(TAGLIB_WITH_MP4) && (TAGLIB_WITH_MP4==1)
		else if (is_valid_mime(result, mime_mp4))
			ret = FILE_MP4;
		#endif
		#ifdef HAVE_TAGLIB_1_7
		else if (is_valid_mime(result, mime_ape))
			ret = FILE_APE;
		#endif

		else ret = -1;
	}

	g_free(result);
	return ret;
}
Example #6
0
static gboolean
is_image_file(const gchar *file)
{
	gboolean ret = FALSE;
	gchar *result = NULL;

	if (!file)
		return FALSE;

	/* Type: JPG, PNG */

#ifdef G_OS_WIN32
	result = get_mime_type_from_uri (file, NULL);
#else
	result = get_mime_type (file);
#endif
	if (!result)
		return FALSE;
	else {
		ret = is_valid_mime(result, mime_image);
		g_free(result);
		return ret;
	}
}
LIBMTP_track_t *
mtp_track_new_from_pragha_musicobject (LIBMTP_mtpdevice_t *mtp_device, PraghaMusicobject *mobj)
{
	LIBMTP_track_t *tr;
	LIBMTP_filetype_t filetype;
	gchar *filename;
	const gchar *mime_type;
	struct stat sbuf;

	mime_type = pragha_musicobject_get_mime_type (mobj);

	if (is_valid_mime(mime_type, mime_flac))
		filetype = LIBMTP_FILETYPE_FLAC;
	else if (is_valid_mime(mime_type, mime_mpeg))
		filetype = LIBMTP_FILETYPE_MP3;
	else if (is_valid_mime(mime_type, mime_ogg))
		filetype = LIBMTP_FILETYPE_OGG;
	else if (is_valid_mime(mime_type, mime_wav))
		filetype = LIBMTP_FILETYPE_WAV;
	else if (is_valid_mime(mime_type, mime_asf))
		filetype = LIBMTP_FILETYPE_WMA;
	else if (is_valid_mime(mime_type, mime_mp4))
		filetype = LIBMTP_FILETYPE_MP4;
	else
		filetype = LIBMTP_FILETYPE_UNKNOWN;

	if (filetype == LIBMTP_FILETYPE_UNKNOWN)
		return NULL;

	filename = g_strdup(pragha_musicobject_get_file(mobj));
	if (g_stat(filename, &sbuf) == -1) {
		g_free(filename);
		return NULL;
	}

	tr = LIBMTP_new_track_t();

	/* Minimun data. */

	tr->filesize = (uint64_t) sbuf.st_size;
	tr->filename = get_display_name(mobj);
	tr->filetype = filetype;

	/* Metadata. */

	tr->title = g_strdup(pragha_musicobject_get_title(mobj));
	tr->artist = g_strdup(pragha_musicobject_get_artist(mobj));
	tr->album = g_strdup(pragha_musicobject_get_album(mobj));
	tr->duration = (1000 * pragha_musicobject_get_length(mobj));
	tr->genre = g_strdup(pragha_musicobject_get_genre (mobj));
	tr->date = g_strdup_printf("%d", pragha_musicobject_get_year (mobj));

	/* Storage data. */

	tr->parent_id = mtp_device->default_music_folder;
	tr->storage_id = 0;

	g_free(filename);

	return tr;
}