File: Metadata.cpp

package info (click to toggle)
android-file-transfer 4.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,496 kB
  • sloc: cpp: 12,909; python: 140; lex: 47; xml: 26; sh: 13; makefile: 6
file content (69 lines) | stat: -rw-r--r-- 1,794 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <mtp/metadata/Metadata.h>
#include <mtp/log.h>

#ifdef HAVE_TAGLIB
#	include <fileref.h>
#	include <tag.h>
#	include <tpropertymap.h>
#endif

namespace mtp
{
#ifdef HAVE_TAGLIB
	MetadataPtr Metadata::Read(const std::string & path)
	{
		TagLib::FileRef f(path.c_str());
		auto tag = f.tag();
		if (f.isNull() || !tag)
			return nullptr;

		auto meta = std::make_shared<Metadata>();
		auto artist = tag->artist();

		const auto & props = tag->properties();
		auto album_it = props.find("ALBUMARTIST");
		if (album_it == props.end())
			album_it = props.find("ALBUM ARTIST");
		if (album_it == props.end())
			album_it = props.find("MUSICBRAINZ_ALBUMARTIST");
		if (album_it != props.end())
			artist = album_it->second.toString();

		meta->Title 	= tag->title().to8Bit(true);
		meta->Artist 	= artist.to8Bit(true);
		meta->Album 	= tag->album().to8Bit(true);
		meta->Genre 	= tag->genre().to8Bit(true);
		meta->Year 		= tag->year();
		meta->Track		= tag->track();

#if TAGLIB_MAJOR_VERSION >= 2
		for(auto & props : tag->complexProperties("PICTURE"))
		{
			auto &picture = meta->Picture;
			for(auto &kv : props)
			{
				auto &name = kv.first;
				auto &value = kv.second;
				if (name == "data") {
					auto data = value.toByteVector();
					picture.Data.assign(data.begin(), data.end());
				} else if (name == "pictureType") {
					picture.Type = value.toString().to8Bit(true);
				} else if (name == "mimeType") {
					picture.MimeType = value.toString().to8Bit(true);
				} else if (name == "description") {
					picture.Description = value.toString().to8Bit(true);
				} else {
					mtp::debug("unhandled PICTURE property ", name.toCString(true));
				}
			}
		}
#endif
		return meta;
	}

#else
	MetadataPtr Metadata::Read(const std::string & path)
	{ return nullptr; }
#endif
}