uvox_3902.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "uvox_3902.h"
  2. #include "api__in_mp3.h"
  3. #include "api/service/waservicefactory.h"
  4. #include <strsafe.h>
  5. #include "in2.h"
  6. extern In_Module mod;
  7. #include "FactoryHelper.h"
  8. Ultravox3902::Ultravox3902() : parser(0)
  9. {
  10. title[0]=album[0]=artist[0]=0;
  11. ServiceBuild(parser, obj_xmlGUID);
  12. if (parser)
  13. {
  14. parser->xmlreader_setCaseSensitive();
  15. parser->xmlreader_registerCallback(L"metadata\f*", this);
  16. parser->xmlreader_open();
  17. }
  18. }
  19. Ultravox3902::~Ultravox3902()
  20. {
  21. if (parser)
  22. {
  23. parser->xmlreader_unregisterCallback(this);
  24. parser->xmlreader_close();
  25. }
  26. ServiceRelease(parser, obj_xmlGUID);
  27. }
  28. int Ultravox3902::Parse(const char *xml_data)
  29. {
  30. if (parser)
  31. {
  32. int ret = parser->xmlreader_feed((void *)xml_data, strlen(xml_data));
  33. if (ret != API_XML_SUCCESS)
  34. return ret;
  35. return parser->xmlreader_feed(0, 0);
  36. }
  37. return API_XML_FAILURE;
  38. }
  39. void Ultravox3902::TextHandler(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *str)
  40. {
  41. if (!_wcsicmp(xmlpath, L"metadata\fTIT2"))
  42. {
  43. StringCbCatW(title, sizeof(title), str);
  44. }
  45. else if (!_wcsicmp(xmlpath, L"metadata\fTALB"))
  46. {
  47. StringCbCatW(album, sizeof(album), str);
  48. }
  49. else if (!_wcsicmp(xmlpath, L"metadata\fTPE1"))
  50. {
  51. StringCbCatW(artist, sizeof(artist), str);
  52. }
  53. }
  54. int Ultravox3902::GetExtendedData(const char *tag, wchar_t *data, int dataLen)
  55. {
  56. if (!_stricmp(tag, "title"))
  57. StringCchCopy(data, dataLen, title);
  58. else if (!_stricmp(tag, "album"))
  59. StringCchCopy(data, dataLen, album);
  60. else if (!_stricmp(tag, "artist"))
  61. StringCchCopy(data, dataLen, artist);
  62. else
  63. return 0;
  64. return 1;
  65. }
  66. #define CBCLASS Ultravox3902
  67. START_DISPATCH;
  68. VCB(ONCHARDATA, TextHandler)
  69. END_DISPATCH;
  70. #undef CBCLASS