123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- #include "main.h"
- #include "WinampPlaylist.h"
- #include "../nu/AutoChar.h"
- #include "../nu/AutoWide.h"
- #include "api.h"
- WinampDirectoryLoad::WinampDirectoryLoad( bool _forceRecurse, char *_exts ) : forceRecurse( _forceRecurse ), exts( _exts ), needsFree( false ), listStart( 0 )
- {
- listStart = PlayList_getlength();
- if ( !exts )
- {
- exts = in_getextlist();
- needsFree = false;
- }
- }
- WinampDirectoryLoad::~WinampDirectoryLoad()
- {
- if ( config_rofiob & 1 )
- PlayList_sort( 2, listStart );
- if ( needsFree )
- GlobalFree( (HGLOBAL)exts );
- }
- WinampPlaylist::WinampPlaylist( const wchar_t *_base, bool _loadDirectories ) : base( _base ), terminateOnEnd( false ), loadDirectories( _loadDirectories )
- {}
- bool WhitelistOK( wchar_t *url )
- {
- bool validurl = false;
- wchar_t *p = url;
- // Whitelist the url...
- if ( *p == L'a' ) p++; // get passed the ad-fullscreen blob.
- if ( *p )
- {
- wchar_t *whitelist;
- whitelist = wcsstr( p, L"http://www.winamp.com/" );
- if ( whitelist && whitelist == p )
- {
- validurl = true;
- }
- if ( validurl == false ) // Check for javscript command
- {
- whitelist = wcsstr( p, L"javascript:onCommand(" );
- if ( whitelist && whitelist == p )
- {
- wchar_t *semi = wcsstr( whitelist, L";" );
- if ( semi )
- {
- semi++;
- if ( *semi )
- *semi = 0;
- }
- validurl = true;
- }
- }
- }
- return validurl;
- }
- WinampPlaylist::~WinampPlaylist()
- {
- //if ( terminateOnEnd )
- //{
- //}
- }
- void WinampPlaylist::OnFile(const wchar_t *filename, const wchar_t *title, int lengthInMs, ifc_plentryinfo *info)
- {
- BOOL hidden = false;
- int playcount = 0;
- unsigned long starttime = 0, endtime = 0;
- wchar_t fcurtain[FILENAME_SIZE] = L"";
- wchar_t fileExt[ 10 ] = L"";
- //wchar_t fbrowser[FILENAME_SIZE] = L"";
- if (LoadPlaylist(filename, 1, 0) == 0) //(playlistManager->Load(filename, this) == PLAYLISTMANAGER_SUCCESS) // if it's another playlist file, load recursively
- return ;
- // check for trailing backslash
- /*
- if (filename[lstrlenW(filename)] == '\\')
- {
- WinampDirectoryLoad dir(true);
- playlistManager->LoadDirectory(filename, this, &dir);
- return;
- }
- */
- // see if it's a directory
- if ( loadDirectories && !PathIsURLW( filename ) && !PathIsNetworkPathW( filename ) )
- {
- HANDLE h;
- WIN32_FIND_DATAW d;
- h = FindFirstFileW( filename, &d );
- if ( h != INVALID_HANDLE_VALUE )
- {
- FindClose( h );
- if ( d.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
- {
- WinampDirectoryLoad dir( true );
- playlistManager->LoadDirectory( filename, this, &dir );
- return;
- }
- }
- }
- if (info)
- {
- const wchar_t *ext = 0;
- ext = info->GetExtendedInfo(L"Repeat");
- if (ext) playcount = _wtoi(ext);
- ext = info->GetExtendedInfo(L"Start");
- if (ext) starttime = _wtoi(ext);
- ext = info->GetExtendedInfo(L"End");
- if (ext) endtime = _wtoi(ext);
- ext = info->GetExtendedInfo(L"Hidden");
- if (ext)
- hidden = _wtoi(ext);
- else
- {
- ext = info->GetExtendedInfo(L"Context");
- if (ext)
- {
- if (!lstrcmpiW(ext, L"radio"))
- {
- hidden = true;
- terminateOnEnd = true;
- }
- }
- }
- ext = info->GetExtendedInfo(L"Curtain");
- if (ext)
- {
- StringCchCopyW(fcurtain, FILENAME_SIZE, ext);
- if (!WhitelistOK(fcurtain))
- fcurtain[0] = 0;
- }
- ext = info->GetExtendedInfo( L"ext" );
- if ( ext )
- {
- StringCchCopyW( fileExt, 10, ext );
- }
- /*
- ext = info->GetExtendedInfo(L"Browser");
- if (ext)
- {
- StringCchCopyW(fbrowser, FILENAME_SIZE, ext);
- if (!WhitelistOK(fbrowser))
- fbrowser[0] = 0;
- }
- */
- }
- if ( lengthInMs != -1 )
- lengthInMs /= 1000;
- if ( !hidden )
- {
- PlayList_append_withinfo_curtain( filename, title, lengthInMs, fcurtain[ 0 ] ? AutoChar( fcurtain ) : 0, fileExt, 0 );
- }
- else
- {
- PlayList_append_withinfo_hidden( filename, title, lengthInMs, fcurtain[ 0 ] ? AutoChar( fcurtain ) : 0/*, fbrowser[0] ? AutoChar(fbrowser) : 0*/ );
- }
- PlayList_SetLastItem_RepeatCount(playcount);
- PlayList_SetLastItem_Range(starttime, endtime);
- }
- const wchar_t *WinampPlaylist::GetBasePath()
- {
- return base;
- }
- bool WinampDirectoryLoad::ShouldRecurse(const wchar_t *path)
- {
- if (config_rofiob&1)
- PlayList_sort(2, listStart);
- listStart = PlayList_getlength();
- if (forceRecurse)
- return true;
- else
- return (config_rofiob&2) ? false : true;
- }
- bool WinampDirectoryLoad::ShouldLoad(const wchar_t *filename)
- {
- if (!exts)
- return true;
- const wchar_t *ext = extensionW(filename);
- char *a = exts;
- while (a && *a)
- {
- if (!_wcsicmp(AutoWide(a), ext))
- return true;
- a += lstrlenA(a) + 1;
- }
- return false;
- }
- #define CBCLASS WinampPlaylist
- START_DISPATCH;
- VCB(IFC_PLAYLISTLOADERCALLBACK_ONFILE, OnFile)
- CB(IFC_PLAYLISTLOADERCALLBACK_GETBASEPATH, GetBasePath)
- END_DISPATCH;
- #undef CBCLASS
- #define CBCLASS WinampDirectoryLoad
- START_DISPATCH;
- CB(IFC_PLAYLISTDIRECTORYCALLBACK_SHOULDRECURSE, ShouldRecurse)
- CB(IFC_PLAYLISTDIRECTORYCALLBACK_SHOULDLOAD, ShouldLoad)
- END_DISPATCH;
- #undef CBCLASS
|