frame_url.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "nsid3v2.h"
  2. #include "nsid3v2/header.h"
  3. #include "nsid3v2/tag.h"
  4. #include "nu/ByteReader.h"
  5. #include "nx/nxstring.h"
  6. #include "nsid3v2/frame_utils.h"
  7. static int ParseText(const void *data, size_t data_len, ParsedString &parsed)
  8. {
  9. bytereader_value_t byte_reader;
  10. bytereader_init(&byte_reader, data, data_len);
  11. return ParseFrameTerminatedString(&byte_reader, 0, parsed);
  12. }
  13. int NSID3v2_Frame_URL_Get(const nsid3v2_frame_t f, nx_string_t *value, int text_flags)
  14. {
  15. const ID3v2::Frame *frame = (const ID3v2::Frame *)f;
  16. if (frame)
  17. {
  18. const void *data;
  19. size_t data_len;
  20. ParsedString parsed;
  21. if (frame->GetData(&data, &data_len) == NErr_Success && ParseText(data, data_len, parsed) == NErr_Success)
  22. {
  23. return NXStringCreateFromParsedString(value, parsed, text_flags);
  24. }
  25. }
  26. return NErr_Empty;
  27. }
  28. int NSID3v2_Tag_URL_Get(const nsid3v2_tag_t t, int frame_enum, nx_string_t *value, int text_flags)
  29. {
  30. const ID3v2::Tag *tag = (const ID3v2::Tag *)t;
  31. if (!tag)
  32. return NErr_Empty;
  33. const ID3v2::Frame *frame = tag->FindFirstFrame(frame_enum);
  34. return NSID3v2_Frame_URL_Get((const nsid3v2_frame_t)frame, value, text_flags);
  35. }