pass2.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "IDScanner.h"
  2. #include "playlist.h"
  3. #include <atlbase.h>
  4. #include "main.h"
  5. #include "api__ml_plg.h"
  6. static ICddbFileInfoList *CreateScanList(volatile int *killswitch)
  7. {
  8. // benski> this function REALLY SUCKS but there's not much we can do about it unfortunately.
  9. // because Gracenote's Playlist SDK doesn't give us a good way to run queries like this
  10. ICddbPL2FindDataPtr pFindData;
  11. ICddbDisc2Ptr pDisc;
  12. if (FAILED(pFindData.CreateInstance(CLSID_CddbPL2FindData)))
  13. return 0;
  14. if (FAILED(playlistMgr->FindOpen(pFindData)))
  15. return 0;
  16. ICddbFileInfoListPtr infoList;
  17. infoList.CreateInstance(CLSID_CddbFileInfoList);
  18. while (SUCCEEDED(playlistMgr->FindNext(pFindData, &pDisc)))
  19. {
  20. if (*killswitch)
  21. return 0;
  22. CComBSTR path,filespec;
  23. wchar_t file[MAX_PATH] = {0};
  24. CComBSTR phase;
  25. pDisc->GetProperty(PROP_Default, PLM_Filename, &filespec);
  26. pDisc->GetProperty(PROP_Default, PLM_Pathname, &path);
  27. PathCombineW(file, path, filespec);
  28. playlistMgr->FileGetFieldVal(file, gnpl_crit_field_xdev1, &phase);
  29. if (!phase || !phase[0] || phase[0]!='2')
  30. continue;
  31. ICddbFileInfoPtr info;
  32. info.CreateInstance(CLSID_CddbFileInfo);
  33. info->put_Filename(file);
  34. infoList->AddFileInfo(info);
  35. }
  36. playlistMgr->FindClose(pFindData);
  37. infoList->AddRef();
  38. return infoList;
  39. }
  40. /*
  41. Pass 2 Algorithm
  42. Find all files with gnpl_crit_field_xdev1 == "2" and run them through MusicID
  43. */
  44. void IDScanner::Pass2()
  45. {
  46. if (SetupMusicID())
  47. {
  48. ICddbFileInfoList *infoList = CreateScanList(&killswitch);
  49. if (infoList)
  50. {
  51. musicID->LibraryID(infoList, MUSICID_RETURN_EXACT_ONLY | MUSICID_GET_FP_FROM_APP | MUSICID_GET_TAG_FROM_APP | MUSICID_PREFER_WF_MATCHES);
  52. infoList->Release();
  53. }
  54. }
  55. }
  56. int IDScanner::Pass2OnThread(HANDLE handle, void *user_data, intptr_t id)
  57. {
  58. IDScanner *scanner = (IDScanner *)id;
  59. scanner->Pass2();
  60. return 0;
  61. }