WinampPlaylist.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #include "main.h"
  2. #include "WinampPlaylist.h"
  3. #include "../nu/AutoChar.h"
  4. #include "../nu/AutoWide.h"
  5. #include "api.h"
  6. WinampDirectoryLoad::WinampDirectoryLoad( bool _forceRecurse, char *_exts ) : forceRecurse( _forceRecurse ), exts( _exts ), needsFree( false ), listStart( 0 )
  7. {
  8. listStart = PlayList_getlength();
  9. if ( !exts )
  10. {
  11. exts = in_getextlist();
  12. needsFree = false;
  13. }
  14. }
  15. WinampDirectoryLoad::~WinampDirectoryLoad()
  16. {
  17. if ( config_rofiob & 1 )
  18. PlayList_sort( 2, listStart );
  19. if ( needsFree )
  20. GlobalFree( (HGLOBAL)exts );
  21. }
  22. WinampPlaylist::WinampPlaylist( const wchar_t *_base, bool _loadDirectories ) : base( _base ), terminateOnEnd( false ), loadDirectories( _loadDirectories )
  23. {}
  24. bool WhitelistOK( wchar_t *url )
  25. {
  26. bool validurl = false;
  27. wchar_t *p = url;
  28. // Whitelist the url...
  29. if ( *p == L'a' ) p++; // get passed the ad-fullscreen blob.
  30. if ( *p )
  31. {
  32. wchar_t *whitelist;
  33. whitelist = wcsstr( p, L"http://www.winamp.com/" );
  34. if ( whitelist && whitelist == p )
  35. {
  36. validurl = true;
  37. }
  38. if ( validurl == false ) // Check for javscript command
  39. {
  40. whitelist = wcsstr( p, L"javascript:onCommand(" );
  41. if ( whitelist && whitelist == p )
  42. {
  43. wchar_t *semi = wcsstr( whitelist, L";" );
  44. if ( semi )
  45. {
  46. semi++;
  47. if ( *semi )
  48. *semi = 0;
  49. }
  50. validurl = true;
  51. }
  52. }
  53. }
  54. return validurl;
  55. }
  56. WinampPlaylist::~WinampPlaylist()
  57. {
  58. //if ( terminateOnEnd )
  59. //{
  60. //}
  61. }
  62. void WinampPlaylist::OnFile(const wchar_t *filename, const wchar_t *title, int lengthInMs, ifc_plentryinfo *info)
  63. {
  64. BOOL hidden = false;
  65. int playcount = 0;
  66. unsigned long starttime = 0, endtime = 0;
  67. wchar_t fcurtain[FILENAME_SIZE] = L"";
  68. wchar_t fileExt[ 10 ] = L"";
  69. //wchar_t fbrowser[FILENAME_SIZE] = L"";
  70. if (LoadPlaylist(filename, 1, 0) == 0) //(playlistManager->Load(filename, this) == PLAYLISTMANAGER_SUCCESS) // if it's another playlist file, load recursively
  71. return ;
  72. // check for trailing backslash
  73. /*
  74. if (filename[lstrlenW(filename)] == '\\')
  75. {
  76. WinampDirectoryLoad dir(true);
  77. playlistManager->LoadDirectory(filename, this, &dir);
  78. return;
  79. }
  80. */
  81. // see if it's a directory
  82. if ( loadDirectories && !PathIsURLW( filename ) && !PathIsNetworkPathW( filename ) )
  83. {
  84. HANDLE h;
  85. WIN32_FIND_DATAW d;
  86. h = FindFirstFileW( filename, &d );
  87. if ( h != INVALID_HANDLE_VALUE )
  88. {
  89. FindClose( h );
  90. if ( d.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
  91. {
  92. WinampDirectoryLoad dir( true );
  93. playlistManager->LoadDirectory( filename, this, &dir );
  94. return;
  95. }
  96. }
  97. }
  98. if (info)
  99. {
  100. const wchar_t *ext = 0;
  101. ext = info->GetExtendedInfo(L"Repeat");
  102. if (ext) playcount = _wtoi(ext);
  103. ext = info->GetExtendedInfo(L"Start");
  104. if (ext) starttime = _wtoi(ext);
  105. ext = info->GetExtendedInfo(L"End");
  106. if (ext) endtime = _wtoi(ext);
  107. ext = info->GetExtendedInfo(L"Hidden");
  108. if (ext)
  109. hidden = _wtoi(ext);
  110. else
  111. {
  112. ext = info->GetExtendedInfo(L"Context");
  113. if (ext)
  114. {
  115. if (!lstrcmpiW(ext, L"radio"))
  116. {
  117. hidden = true;
  118. terminateOnEnd = true;
  119. }
  120. }
  121. }
  122. ext = info->GetExtendedInfo(L"Curtain");
  123. if (ext)
  124. {
  125. StringCchCopyW(fcurtain, FILENAME_SIZE, ext);
  126. if (!WhitelistOK(fcurtain))
  127. fcurtain[0] = 0;
  128. }
  129. ext = info->GetExtendedInfo( L"ext" );
  130. if ( ext )
  131. {
  132. StringCchCopyW( fileExt, 10, ext );
  133. }
  134. /*
  135. ext = info->GetExtendedInfo(L"Browser");
  136. if (ext)
  137. {
  138. StringCchCopyW(fbrowser, FILENAME_SIZE, ext);
  139. if (!WhitelistOK(fbrowser))
  140. fbrowser[0] = 0;
  141. }
  142. */
  143. }
  144. if ( lengthInMs != -1 )
  145. lengthInMs /= 1000;
  146. if ( !hidden )
  147. {
  148. PlayList_append_withinfo_curtain( filename, title, lengthInMs, fcurtain[ 0 ] ? AutoChar( fcurtain ) : 0, fileExt, 0 );
  149. }
  150. else
  151. {
  152. PlayList_append_withinfo_hidden( filename, title, lengthInMs, fcurtain[ 0 ] ? AutoChar( fcurtain ) : 0/*, fbrowser[0] ? AutoChar(fbrowser) : 0*/ );
  153. }
  154. PlayList_SetLastItem_RepeatCount(playcount);
  155. PlayList_SetLastItem_Range(starttime, endtime);
  156. }
  157. const wchar_t *WinampPlaylist::GetBasePath()
  158. {
  159. return base;
  160. }
  161. bool WinampDirectoryLoad::ShouldRecurse(const wchar_t *path)
  162. {
  163. if (config_rofiob&1)
  164. PlayList_sort(2, listStart);
  165. listStart = PlayList_getlength();
  166. if (forceRecurse)
  167. return true;
  168. else
  169. return (config_rofiob&2) ? false : true;
  170. }
  171. bool WinampDirectoryLoad::ShouldLoad(const wchar_t *filename)
  172. {
  173. if (!exts)
  174. return true;
  175. const wchar_t *ext = extensionW(filename);
  176. char *a = exts;
  177. while (a && *a)
  178. {
  179. if (!_wcsicmp(AutoWide(a), ext))
  180. return true;
  181. a += lstrlenA(a) + 1;
  182. }
  183. return false;
  184. }
  185. #define CBCLASS WinampPlaylist
  186. START_DISPATCH;
  187. VCB(IFC_PLAYLISTLOADERCALLBACK_ONFILE, OnFile)
  188. CB(IFC_PLAYLISTLOADERCALLBACK_GETBASEPATH, GetBasePath)
  189. END_DISPATCH;
  190. #undef CBCLASS
  191. #define CBCLASS WinampDirectoryLoad
  192. START_DISPATCH;
  193. CB(IFC_PLAYLISTDIRECTORYCALLBACK_SHOULDRECURSE, ShouldRecurse)
  194. CB(IFC_PLAYLISTDIRECTORYCALLBACK_SHOULDLOAD, ShouldLoad)
  195. END_DISPATCH;
  196. #undef CBCLASS