aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Input/in_mp3/uvox_3901.cpp
blob: d385a1aa24ee39d9d28f90ae980b5dc0b7c2c579 (plain) (blame)
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
70
71
72
73
74
75
76
77
78
79
#include "uvox_3901.h"
#include "api__in_mp3.h"
#include "api/service/waservicefactory.h"
#include <strsafe.h>
#include "in2.h"
extern In_Module mod;

#include "FactoryHelper.h"


Ultravox3901::Ultravox3901() : parser(0)
{
	title[0]=album[0]=artist[0]=album_art_url[0]=0;
	ServiceBuild(parser, obj_xmlGUID);
	if (parser)
	{
		parser->xmlreader_registerCallback(L"metadata\fsong\f*", this);
		parser->xmlreader_open();
	}
}

Ultravox3901::~Ultravox3901()
{
	ServiceRelease(parser, obj_xmlGUID);
}

int Ultravox3901::Parse(const char *xml_data)
{
	if (parser)
	{
		int ret = parser->xmlreader_feed((void *)xml_data, strlen(xml_data));
		if (ret != API_XML_SUCCESS)
			return ret;
		return parser->xmlreader_feed(0, 0);
	}
	return API_XML_FAILURE;
}

void Ultravox3901::TextHandler(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *str)
{
	if (!_wcsicmp(xmltag, L"name"))
	{
		StringCbCatW(title, sizeof(title), str);
	}
	else if (!_wcsicmp(xmltag, L"album"))
	{
		StringCbCatW(album, sizeof(album), str);
	}
	else if (!_wcsicmp(xmltag, L"artist"))
	{
		StringCbCatW(artist, sizeof(artist), str);
	}
	else if (!_wcsicmp(xmltag, L"album_art"))
	{
		StringCbCatW(album_art_url, sizeof(album_art_url), str);
	}
}

int Ultravox3901::GetExtendedData(const char *tag, wchar_t *data, int dataLen)
{
	if (!_stricmp(tag, "uvox/title"))
		StringCchCopy(data, dataLen, title);
	else if (!_stricmp(tag, "uvox/album"))
		StringCchCopy(data, dataLen, album);
	else if (!_stricmp(tag, "uvox/artist"))
		StringCchCopy(data, dataLen, artist);
	else if (!_stricmp(tag, "uvox/albumart"))
		StringCchCopy(data, dataLen, album_art_url);
	else
		return 0;

	return 1;
}

#define CBCLASS Ultravox3901
START_DISPATCH;
VCB(ONCHARDATA, TextHandler)
END_DISPATCH;
#undef CBCLASS