NowPlayingPlugin: Minor tweaks.

This commit is contained in:
Birunthan Mohanathas 2011-09-08 12:42:03 +00:00
parent 6b06548260
commit d598c56b76
14 changed files with 47 additions and 67 deletions

View File

@ -39,8 +39,7 @@ bool CCover::GetCached(std::wstring& path)
*/
bool CCover::GetLocal(std::wstring filename, const std::wstring& folder, std::wstring& target)
{
std::wstring testPath = folder;
testPath += filename;
std::wstring testPath = folder + filename;
testPath += L".";
std::wstring::size_type origLen = testPath.length();

View File

@ -257,7 +257,7 @@ void CInternet::DecodeReferences(std::wstring& str)
/*
** ConvertToWide
**
** Convert from multibyte ti wide string.
** Convert multibyte string to wide string.
**
*/
std::wstring CInternet::ConvertToWide(LPCSTR str, int codepage)
@ -266,15 +266,12 @@ std::wstring CInternet::ConvertToWide(LPCSTR str, int codepage)
if (str && *str)
{
int strLen = (int)strlen(str) + 1;
int strLen = (int)strlen(str);
int bufLen = MultiByteToWideChar(codepage, 0, str, strLen, NULL, 0);
if (bufLen > 0)
{
WCHAR* wideSz = new WCHAR[bufLen];
wideSz[0] = 0;
MultiByteToWideChar(codepage, 0, str, strLen, wideSz, bufLen);
szWide = wideSz;
delete [] wideSz;
szWide.resize(bufLen);
MultiByteToWideChar(codepage, 0, str, strLen, &szWide[0], bufLen);
}
}

View File

@ -49,8 +49,7 @@ bool CLyrics::GetFromWikia(const std::wstring& artist, const std::wstring& title
{
bool ret = false;
std::wstring url = L"http://lyrics.wikia.com/api.php?func=getSong&fmt=json&artist=";
url += artist;
std::wstring url = L"http://lyrics.wikia.com/api.php?func=getSong&fmt=json&artist=" + artist;
url += L"&song=";
url += title;
@ -126,8 +125,7 @@ bool CLyrics::GetFromLYRDB(const std::wstring& artist, const std::wstring& title
{
bool ret = false;
std::wstring query = artist;
query += L"|";
std::wstring query = artist + L"|";
query += title;
// LYRDB doesn't like apostrophes
@ -137,8 +135,7 @@ bool CLyrics::GetFromLYRDB(const std::wstring& artist, const std::wstring& title
query.erase(pos, 3);
}
std::wstring url = L"http://webservices.lyrdb.com/lookup.php?q=";
url += query;
std::wstring url = L"http://webservices.lyrdb.com/lookup.php?q=" + query;
url += L"&for=match&agent=RainmeterNowPlaying";
data = CInternet::DownloadUrl(url, CP_ACP);
@ -172,8 +169,7 @@ bool CLyrics::GetFromLetras(const std::wstring& artist, const std::wstring& titl
{
bool ret = false;
std::wstring url = L"http://letras.terra.com.br/winamp.php?musica=";
url += title;
std::wstring url = L"http://letras.terra.com.br/winamp.php?musica=" + title;
url += L"&artista=";
url += artist;
data = CInternet::DownloadUrl(url, CP_ACP);

View File

@ -242,6 +242,7 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
}
else if (_wcsicmp(L"LYRICS", str) == 0)
{
LSLog(LOG_WARNING, L"Rainmeter", L"NowPlayingPlugin: Using undocumented PlayerType=LYRICS!");
child->type = MEASURE_LYRICS;
}
else if (_wcsicmp(L"FILE", str) == 0)

View File

@ -29,11 +29,10 @@ extern std::wstring g_CachePath;
*/
CPlayer::CPlayer() :
m_Initialized(false),
m_HasCoverMeasure(false),
m_HasLyricsMeasure(false),
m_InstanceCount(),
m_UpdateCount(),
m_TrackCount(),
m_Measures(),
m_State(),
m_Duration(),
m_Position(),
@ -90,18 +89,9 @@ void CPlayer::RemoveInstance()
** Called during initialization of any measure.
**
*/
void CPlayer::AddMeasure(MEASURETYPE measure)
void CPlayer::AddMeasure(INT type)
{
switch (measure)
{
case MEASURE_LYRICS:
m_HasLyricsMeasure = true;
break;
case MEASURE_COVER:
m_HasCoverMeasure = true;
break;
}
m_Measures |= type;
}
/*
@ -135,8 +125,7 @@ std::wstring CPlayer::GetCacheFile()
}
else
{
std::wstring name = m_Artist;
name += L" - ";
std::wstring name = m_Artist + L" - ";
name += m_Title;
// Replace reserved chars with _

View File

@ -34,19 +34,19 @@ enum PLAYSTATE
enum MEASURETYPE
{
MEASURE_ARTIST,
MEASURE_TITLE,
MEASURE_ALBUM,
MEASURE_LYRICS,
MEASURE_COVER,
MEASURE_FILE,
MEASURE_DURATION,
MEASURE_POSITION,
MEASURE_PROGRESS,
MEASURE_RATING,
MEASURE_VOLUME,
MEASURE_STATE,
MEASURE_STATUS
MEASURE_ARTIST = 0x00000001,
MEASURE_TITLE = 0x00000002,
MEASURE_ALBUM = 0x00000004,
MEASURE_LYRICS = 0x00000008,
MEASURE_COVER = 0x00000010,
MEASURE_FILE = 0x00000020,
MEASURE_DURATION = 0x00000040,
MEASURE_POSITION = 0x00000080,
MEASURE_PROGRESS = 0x00000100,
MEASURE_RATING = 0x00000200,
MEASURE_VOLUME = 0x00000400,
MEASURE_STATE = 0x00000800,
MEASURE_STATUS = 0x00001000
};
class CPlayer
@ -58,7 +58,7 @@ public:
void AddInstance();
void RemoveInstance();
void UpdateMeasure();
virtual void AddMeasure(MEASURETYPE measure);
virtual void AddMeasure(INT type);
virtual void UpdateData() = 0;
bool IsInitialized() { return m_Initialized; }
@ -95,12 +95,11 @@ protected:
void ClearData();
bool m_Initialized;
bool m_HasCoverMeasure;
bool m_HasLyricsMeasure;
UINT m_InstanceCount;
UINT m_UpdateCount;
UINT m_TrackCount;
INT m_Measures;
PLAYSTATE m_State;
std::wstring m_Artist;
std::wstring m_Title;

View File

@ -118,8 +118,8 @@ bool CPlayerAIMP::CheckWindow()
*/
void CPlayerAIMP::UpdateData()
{
static long oldFileSize = 0;
static UINT oldTitleLen = 0;
static INT64 oldFileSize = 0;
static long oldTitleLen = 0;
if (!m_Initialized)
{
@ -198,12 +198,12 @@ void CPlayerAIMP::UpdateData()
++m_TrackCount;
// Find cover if needed
if (m_HasCoverMeasure)
if (m_Measures & MEASURE_COVER)
{
FindCover();
}
if (m_HasLyricsMeasure)
if (m_Measures & MEASURE_LYRICS)
{
FindLyrics();
}

View File

@ -310,7 +310,7 @@ LRESULT CALLBACK CPlayerCAD::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
player->m_CoverPath.assign(data, 0, len);
data.erase(0, ++len);
if (player->m_HasLyricsMeasure)
if (player->m_Measures & MEASURE_LYRICS)
{
player->FindLyrics();
}

View File

@ -98,8 +98,7 @@ void CPlayerFoobar::Initialize()
int version = (int)SendMessage(m_FooWindow, WM_USER, 0, FOO_GETVERSION);
if (version < 100)
{
std::wstring error = L"Your copy of the foo_rainmeter.dll plugin for foobar2000 is outdated.\n";
error += L"Please download the latest version from foo-rainmeter.googlecode.com and try again.";
std::wstring error = L"Your copy of the foo_rainmeter.dll plugin for foobar2000 is outdated.\nDownload the latest version from foo-rainmeter.googlecode.com and try again.";
MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_ICONERROR | MB_TOPMOST);
m_FooWindow = NULL;
}
@ -264,12 +263,12 @@ LRESULT CALLBACK CPlayerFoobar::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR
player->m_FilePath = token;
player->m_Position = 0;
if (player->m_HasCoverMeasure || player->m_InstanceCount == 0)
if (player->m_Measures & MEASURE_COVER || player->m_InstanceCount == 0)
{
player->FindCover();
}
if (player->m_HasLyricsMeasure)
if (player->m_Measures & MEASURE_LYRICS)
{
player->FindLyrics();
}

View File

@ -387,7 +387,7 @@ void CPlayerITunes::OnTrackChange()
++m_TrackCount;
m_FilePath = tmpStr;
if (m_HasCoverMeasure)
if (m_Measures & MEASURE_COVER)
{
m_CoverPath = GetCacheFile();
if (!CCover::GetCached(m_CoverPath))
@ -432,7 +432,7 @@ void CPlayerITunes::OnTrackChange()
}
}
if (m_HasLyricsMeasure)
if (m_Measures & MEASURE_LYRICS)
{
FindLyrics();
}

View File

@ -115,7 +115,7 @@ void CPlayerSpotify::UpdateData()
m_Artist = artist;
++m_TrackCount;
if (m_HasLyricsMeasure)
if (m_Measures & MEASURE_LYRICS)
{
FindLyrics();
}

View File

@ -138,7 +138,7 @@ LRESULT CALLBACK CPlayerWLM::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM
len = data.find_first_of(L'\\');
player->m_Album.assign(data, 0, len);
if (player->m_HasLyricsMeasure)
if (player->m_Measures & MEASURE_LYRICS)
{
player->FindLyrics();
}

View File

@ -451,7 +451,7 @@ void CPlayerWMP::UpdateData()
// Find cover if needed
// TODO: Fix temp solution
if (m_HasCoverMeasure || m_InstanceCount == 0)
if (m_Measures & MEASURE_COVER || m_InstanceCount == 0)
{
spMedia->getItemInfo(CComBSTR("WM/WMCollectionID"), &val);
targetPath.resize(targetPath.find_last_of(L'\\') + 1);
@ -469,7 +469,7 @@ void CPlayerWMP::UpdateData()
}
}
if (m_HasLyricsMeasure)
if (m_Measures & MEASURE_LYRICS)
{
FindLyrics();
}

View File

@ -184,18 +184,18 @@ void CPlayerWinamp::UpdateData()
m_Album = tag->album().toWString();
m_Title = tag->title().toWString();
if (m_HasLyricsMeasure)
if (m_Measures & MEASURE_LYRICS)
{
FindLyrics();
}
}
else if (m_HasLyricsMeasure)
else if (m_Measures & MEASURE_LYRICS)
{
m_Lyrics.clear();
}
// Find cover if needed
if (m_HasCoverMeasure)
if (m_Measures & MEASURE_COVER)
{
m_CoverPath = GetCacheFile();
if (!CCover::GetCached(m_CoverPath) &&
@ -266,7 +266,7 @@ void CPlayerWinamp::UpdateData()
m_Rating = 0;
m_Duration = 0;
if (m_HasCoverMeasure)
if (m_Measures & MEASURE_COVER)
{
m_CoverPath.clear();
}