ExtendedFileInfo.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include <bfc/platform/types.h>
  2. #include <windows.h>
  3. #include "api__in_avi.h"
  4. #include "win32_avi_reader.h"
  5. #include "../nsavi/metadata.h"
  6. #include "../nu/ns_wc.h"
  7. #include <strsafe.h>
  8. #include "resource.h"
  9. static void ReadMetadata(nsavi::Metadata &metadata, uint32_t id, wchar_t *dest, size_t destlen)
  10. {
  11. nsavi::Info *info=0;
  12. const char *str = 0;
  13. if (metadata.GetInfo(&info) == nsavi::READ_OK && (str = info->GetMetadata(id)))
  14. {
  15. MultiByteToWideCharSZ(CP_ACP/*UTF8*/, 0, str, -1, dest, (int)destlen);
  16. }
  17. else
  18. dest[0]=0;
  19. }
  20. extern "C" __declspec(dllexport)
  21. int winampGetExtendedFileInfoW(const wchar_t *fn, const char *data, wchar_t *dest, size_t destlen)
  22. {
  23. if (!_stricmp(data, "type"))
  24. {
  25. dest[0]='1';
  26. dest[1]=0;
  27. return 1;
  28. }
  29. else if (!_stricmp(data, "family"))
  30. {
  31. int len;
  32. const wchar_t *p;
  33. if (!fn || !fn[0]) return 0;
  34. len = lstrlenW(fn);
  35. if (len < 4 || L'.' != fn[len - 4]) return 0;
  36. p = &fn[len - 3];
  37. if (!_wcsicmp(p, L"AVI") && S_OK == StringCchCopyW(dest, destlen, WASABI_API_LNGSTRINGW(IDS_FAMILY_STRING))) return 1;
  38. return 0;
  39. }
  40. else
  41. {
  42. AVIReaderWin32 reader;
  43. if (reader.Open(fn) == nsavi::READ_OK)
  44. {
  45. nsavi::Metadata metadata(&reader);
  46. uint32_t riff_type;
  47. metadata.GetRIFFType(&riff_type); // need to call this to get the party started
  48. // TODO: cache metadata object
  49. if (!_stricmp(data, "length"))
  50. {
  51. int time_ms;
  52. if (metadata.GetDuration(&time_ms) == nsavi::READ_OK)
  53. StringCchPrintf(dest, destlen, L"%d", time_ms);
  54. else
  55. dest[0]=0;
  56. }
  57. else if (!_stricmp(data, "height"))
  58. {
  59. nsavi::HeaderList header_list;
  60. if (metadata.GetHeaderList(&header_list) == nsavi::READ_OK && header_list.avi_header && header_list.avi_header->height)
  61. StringCchPrintf(dest, destlen, L"%d", header_list.avi_header->height);
  62. else
  63. dest[0]=0;
  64. }
  65. else if (!_stricmp(data, "width"))
  66. {
  67. nsavi::HeaderList header_list;
  68. if (metadata.GetHeaderList(&header_list) == nsavi::READ_OK && header_list.avi_header && header_list.avi_header->width)
  69. StringCchPrintf(dest, destlen, L"%d", header_list.avi_header->width);
  70. else
  71. dest[0]=0;
  72. }
  73. else if (!_stricmp(data, "bitrate"))
  74. {
  75. int time_ms = 0;
  76. uint64_t file_length = 0;
  77. if (metadata.GetDuration(&time_ms) == nsavi::READ_OK
  78. && (file_length = reader.GetContentLength())
  79. && time_ms > 0 && file_length > 0)
  80. {
  81. uint64_t bitrate = 8ULL * file_length / (uint64_t)time_ms;
  82. StringCchPrintf(dest, destlen, L"%I64u", bitrate);
  83. }
  84. else
  85. dest[0]=0;
  86. }
  87. else if (!_stricmp(data, "artist"))
  88. {
  89. ReadMetadata(metadata, nsaviFOURCC('I','A','R','T'), dest, destlen);
  90. }
  91. else if (!_stricmp(data, "publisher"))
  92. {
  93. ReadMetadata(metadata, nsaviFOURCC('I','P','U','B'), dest, destlen);
  94. }
  95. else if (!_stricmp(data, "album"))
  96. {
  97. ReadMetadata(metadata, nsaviFOURCC('I','A','L','B'), dest, destlen);
  98. }
  99. else if (!_stricmp(data, "composer"))
  100. {
  101. ReadMetadata(metadata, nsaviFOURCC('I','C','O','M'), dest, destlen);
  102. }
  103. else if (!_stricmp(data, "genre"))
  104. {
  105. ReadMetadata(metadata, nsaviFOURCC('I','G','N','R'), dest, destlen);
  106. }
  107. else if (!_stricmp(data, "comment"))
  108. {
  109. ReadMetadata(metadata, nsaviFOURCC('I','C','M','T'), dest, destlen);
  110. }
  111. else if (!_stricmp(data, "title"))
  112. {
  113. ReadMetadata(metadata, nsaviFOURCC('I','N','A','M'), dest, destlen);
  114. }
  115. else if (!_stricmp(data, "tool"))
  116. {
  117. ReadMetadata(metadata, nsaviFOURCC('I','S','F','T'), dest, destlen);
  118. }
  119. else if (!_stricmp(data, "copyright"))
  120. {
  121. ReadMetadata(metadata, nsaviFOURCC('I','C','O','P'), dest, destlen);
  122. }
  123. else
  124. {
  125. reader.Close();
  126. return 0;
  127. }
  128. reader.Close();
  129. return 1;
  130. }
  131. }
  132. return 0;
  133. }