pass1.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "main.h"
  2. #include "playlist.h"
  3. #include <atlbase.h>
  4. #include "IDScanner.h"
  5. #include "api__ml_plg.h"
  6. static long PlaylistManagerCount()
  7. {
  8. ICddbPL2FindDataPtr pFindData;
  9. ICddbDisc2Ptr pDisc;
  10. long count =0;
  11. HRESULT hr = pFindData.CreateInstance(CLSID_CddbPL2FindData);
  12. if (FAILED(hr))
  13. return count;
  14. // empty FindData iterator means ALL FILES
  15. hr = playlistMgr->FindOpen(pFindData);
  16. if (FAILED(hr))
  17. return count;
  18. while (SUCCEEDED(playlistMgr->FindNext(pFindData, &pDisc)))
  19. {
  20. count++;
  21. }
  22. playlistMgr->FindClose(pFindData);
  23. return count;
  24. }
  25. /*
  26. Pass 1 Algorithm
  27. Find all files with gnpl_crit_field_xdev1 == "1"
  28. for each:
  29. GetFileInfo "GracenoteFileID"
  30. if success
  31. {
  32. xdev1 = "2"
  33. GetFileInfo "GracenoteExtData"
  34. if success
  35. xdev1 = "done"
  36. }
  37. else
  38. xdev="3"
  39. */
  40. void IDScanner::Pass1()
  41. {
  42. // benski> this function REALLY SUCKS but there's not much we can do about it unfortunately.
  43. // because Gracenote's Playlist SDK doesn't give us a good way to run queries like this
  44. ICddbPL2FindDataPtr pFindData;
  45. ICddbDisc2Ptr pDisc;
  46. HRESULT hr;
  47. filesTotal = PlaylistManagerCount(); // super slow, but hey this whole function is slow, anyway
  48. hr = pFindData.CreateInstance(CLSID_CddbPL2FindData);
  49. if (FAILED(hr))
  50. return ;
  51. // empty FindData iterator means ALL FILES
  52. hr = playlistMgr->FindOpen(pFindData);
  53. if (FAILED(hr))
  54. return;
  55. while (SUCCEEDED(playlistMgr->FindNext(pFindData, &pDisc)))
  56. {
  57. if (killswitch)
  58. break;
  59. CComBSTR path,filespec;
  60. wchar_t file[MAX_PATH] = {0};
  61. CComBSTR phase;
  62. pDisc->GetProperty(PROP_Default, PLM_Filename, &filespec);
  63. pDisc->GetProperty(PROP_Default, PLM_Pathname, &path);
  64. PathCombineW(file, path, filespec);
  65. playlistMgr->FileGetFieldVal(file, gnpl_crit_field_xdev1, &phase);
  66. if (phase && phase[0] && phase[0]=='1')
  67. {
  68. wchar_t gracenoteFileId[256]=L"";
  69. if (GetFileInfo(file, L"GracenoteFileID", gracenoteFileId, 256) && gracenoteFileId[0])
  70. {
  71. wchar_t gracenoteExtData[65536]=L"";
  72. GetFileInfo(file, L"GracenoteExtData", gracenoteExtData, 65536);
  73. // write back to Media Library database (since if we got here, it wasn't in the itemRecordList)
  74. AGAVE_API_MLDB->SetField(file, "GracenoteFileID", gracenoteFileId);
  75. if (gracenoteExtData[0]) AGAVE_API_MLDB->SetField(file, "GracenoteExtData", gracenoteExtData);
  76. SetGracenoteData(file, gracenoteFileId, gracenoteExtData);
  77. playlistMgr->FileSetFieldVal(file, gnpl_crit_field_xdev1, L"0"); // mark as done!
  78. }
  79. else // no Tag ID, so we'll have to use AlbumID
  80. {
  81. playlistMgr->FileSetFieldVal(file, gnpl_crit_field_xdev1, L"2"); // move to phase 2
  82. }
  83. }
  84. filesComplete++;
  85. }
  86. playlistMgr->FindClose(pFindData);
  87. }