Skip to content

Commit

Permalink
Merge pull request #31 from ryanjay0/myBranch
Browse files Browse the repository at this point in the history
updated parsing. fixed metascore. fixed delete.
  • Loading branch information
ryanjay0 committed Apr 18, 2016
2 parents 104002e + 258a8bb commit 694049e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 43 deletions.
3 changes: 3 additions & 0 deletions MovieExplorer/CategoryBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ void CCategoryBar::FilterDB()
else if (m_nAutoCategories > CB_TV_BUTTON && m_buttons[CB_TV_BUTTON].state == CTBBSTATE_SELECTED)
GetDB()->SetOnlyTV(true);
GetDB()->FilterByCategories(categories);

SendMessage(GetMainWnd(), WM_LISTVIEW_ITEM, 0); //Reset scroll bar to start

}

void CCategoryBar::PrepareDraw()
Expand Down
9 changes: 9 additions & 0 deletions MovieExplorer/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,15 @@ void CDatabase::SetOnlyMovies(bool bFlag)
m_bShowOnlyMovies = bFlag;
}

float scoreDiff(DBMOVIE *pMov)
{
if (pMov->nMetascore >= 0)
{
return(pMov->fRating - ((float)pMov->nMetascore / 10.0));
}
else
return(0);
}
void CDatabase::Filter()
{
m_movies.SetSize(0);
Expand Down
23 changes: 13 additions & 10 deletions MovieExplorer/ListView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ void CListView::OnCommand(WORD id, WORD notifyCode, HWND hWndControl)
if (MessageBox(GetMainWnd(), GETSTR(IDS_SURETODELETEDIRECTORY),
_T("Movie Explorer"), MB_ICONQUESTION | MB_YESNO) == IDYES)
{
RemoveDirectory(strFilePath, true); // Delete directory, all subdirectories, and files.
DeleteDirectoryAndAllSubfolders(strFilePath);
//RemoveDirectory(strFilePath, true); // Delete directory, all subdirectories, and files.
LOG(_T("Deleted Directory: ") + mov.strFileName + _T("\n"));
GetDB()->SyncAndUpdate();
}
Expand Down Expand Up @@ -837,20 +838,22 @@ void CListView::Draw()
else
{
strTitle = mov.strTitle.IsEmpty() ? mov.strFileName : mov.strTitle;
str = (mov.strEpisodeName.IsEmpty() ? mov.strTitle : (mov.strEpisodeName +
(strDate.IsEmpty() ? _T("") : _T(" (") + strDate + _T(")"))));
if (!strDate.IsEmpty())
strTitle = strTitle + _T(" (") + strDate + _T(")");

TextOut(m_mdc, SCX(200) + SCX(35), y + SCY(14), str);
TextOut(m_mdc, SCX(200) + SCX(35), y + SCY(14), strTitle);
SelectObject(m_mdc, hPrevFont);


str.Empty();
if (mov.nSeason >= 0)
str = _T("Season ") + NumberToString(mov.nSeason);
if (mov.nEpisode >= 0)
str = str + _T(" Episode ") + NumberToString(mov.nEpisode) + _T(": ");
str = str + _T("\"") + mov.strEpisodeName + _T("\"");

hPrevFont = (HFONT)SelectObject(m_mdc, m_fntTextBold);
SetTextColor(m_mdc, m_clrTitle);
str = strTitle;
if (mov.nSeason >= 0)
str = str + _T(": Season ") + NumberToString(mov.nSeason);
if(mov.nEpisode >= 0)
str = str + _T(" Episode ") + NumberToString(mov.nEpisode);

TextOut(m_mdc, SCX(200) + SCX(35), y + SCY(40), str);
SelectObject(m_mdc, hPrevFont);

Expand Down
30 changes: 23 additions & 7 deletions MovieExplorer/ScrapeIMDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ DWORD ScrapeIMDb(DBINFO *pInfo)
}

RRegEx regex, regex2;
RString str, strSeasonPage, strEpisodePage, strTemp, strTemp2;
RString str, strOriginal, strSeasonPage, strEpisodePage, strTemp, strTemp2;
RString strSeasonTmp, strEpisodeTmp;
const TCHAR *p, *pEnd;

Expand Down Expand Up @@ -95,11 +95,10 @@ DWORD ScrapeIMDb(DBINFO *pInfo)
}
else
{
// 1. try exact title match
// 1. try exact title match (allow trailing characters)
// 2. take the first one

if (!GetFirstMatch(str, _T("href=\"http://www\\.imdb\\.com/title/(tt\\d+)/[^>]*><strong>(?:The |A )?") +
pInfo->strSearchTitle + _T("(?:</strong>)? \\("), &pInfo->strID, NULL) &&
pInfo->strSearchTitle + _T("(?:</strong>)?[^\\(]*?\\("), &pInfo->strID, NULL) &&
!GetFirstMatch(str, _T("<a href=\"http://www\\.imdb\\.com/title/(tt\\d+)/[^\"]*\"[^>]*>.+?</a>"),
&pInfo->strID, NULL))
return DBI_STATUS_UNKNOWN;
Expand Down Expand Up @@ -210,6 +209,7 @@ DWORD ScrapeIMDb(DBINFO *pInfo)
strEpisodePage = FixLineEnds(HTMLEntitiesDecode(URLToString(_T("http://www.imdb.com/title/") + strTmpID + _T("/"))));
if (!strEpisodePage.IsEmpty())
{
strOriginal = str;
str = strEpisodePage;
pInfo->strID = strTmpID;
}
Expand All @@ -231,6 +231,7 @@ DWORD ScrapeIMDb(DBINFO *pInfo)
strEpisodePage = FixLineEnds(HTMLEntitiesDecode(URLToString(_T("http://www.imdb.com/title/") + strTmpID + _T("/"))));
if (!strEpisodePage.IsEmpty())
{
strOriginal = str;
str = strEpisodePage;
pInfo->strID = strTmpID;
}
Expand All @@ -248,6 +249,19 @@ DWORD ScrapeIMDb(DBINFO *pInfo)
strTemp = strTemp + _T(".") + strTemp2; // take the server's default cropping and resizing
URLToData(strTemp, pInfo->posterData);
}
else
{
//didn't find a poster, so if it's a tv show check original show page also
if (pInfo->bType == DB_TYPE_TV && !strOriginal.IsEmpty())
{
if (GetFirstMatch(strOriginal, _T("title=\"[^\"]*?Poster\"[^>]*?(http://ia\\.media-imdb\\.com/images/M/[^\"]+?_V1\\.?_[^\"]*?)\\.([^\"]+?)\""),
&strTemp, &strTemp2, NULL))
{
strTemp = strTemp + _T(".") + strTemp2; // take the server's default cropping and resizing
URLToData(strTemp, pInfo->posterData);
}
}
}
}

// Get rating
Expand All @@ -258,13 +272,15 @@ DWORD ScrapeIMDb(DBINFO *pInfo)
pInfo->fRatingMax = 10.0f;

// Get Metacritic rating

if (GetFirstMatch(str, _T("Metascore[ \\t]*:[ \\t]*<[^>]+>[ \\t]*(1?\\d?\\d)/100"), &strTemp, NULL))

if (GetFirstMatch(str, _T("metacriticScore[^<]+?<span>(1?\\d?\\d)</span>"), &strTemp, NULL))
pInfo->nMetascore = StringToNumber(strTemp);
else if (GetFirstMatch(str, _T("Metascore[ \\t]*:[ \\t]*<[^>]+>[ \\t]*(1?\\d?\\d)/100"), &strTemp, NULL))
pInfo->nMetascore = StringToNumber(strTemp);

// Get votes

if (GetFirstMatch(str, _T("<span itemprop=\"ratingCount\">([^<]+?)</span>"), &strTemp, NULL))
if (GetFirstMatch(str, _T("\"ratingCount\">([^<]+?)</span>"), &strTemp, NULL))
{
strTemp.Replace(_T(","), _T(""));
pInfo->nVotes = StringToNumber(strTemp);
Expand Down
41 changes: 15 additions & 26 deletions RClasses/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#define CHARSET_UTF8 4
#define CHARSET_UTF16 CHARSET_UTF16LE

#include <strsafe.h>

inline RString GetAppPath()
{
RString str;
Expand Down Expand Up @@ -94,37 +96,24 @@ inline RString GetDir(RString_ strFilePath)
return strDir;
}

inline bool RemoveDirectory(const TCHAR* lpszPathName, bool bDeleteContents)
{
if (!bDeleteContents)
return RemoveDirectory(lpszPathName) != FALSE;

RString strPathName(lpszPathName);
WIN32_FIND_DATA ffd;
HANDLE hFindFile = FindFirstFile(strPathName + _T("\\*.*"), &ffd);

if (hFindFile != INVALID_HANDLE_VALUE)
{
do
{
if (_tcscmp(ffd.cFileName, _T(".")) == 0 || _tcscmp(ffd.cFileName, _T("..")) == 0)
continue;

if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
if (!RemoveDirectory(strPathName + _T("\\") + ffd.cFileName, true))
{FindClose(hFindFile); return false;}

if (!DeleteFile(strPathName + _T("\\") + ffd.cFileName))
{FindClose(hFindFile); return false;}

} while (FindNextFile(hFindFile, &ffd));
inline LONG DeleteDirectoryAndAllSubfolders(const TCHAR* lpszDirectory)
{
TCHAR szDir[MAX_PATH + 1]; // +1 for the double null terminate
SHFILEOPSTRUCTW fos = { 0 };

FindClose(hFindFile);
}
StringCchCopy(szDir, MAX_PATH, lpszDirectory);
int len = lstrlenW(szDir);
szDir[len + 1] = 0; // double null terminate for SHFileOperation

return RemoveDirectory(lpszPathName) != FALSE;
// delete the folder and everything inside
fos.wFunc = FO_DELETE;
fos.pFrom = szDir;
fos.fFlags = FOF_NO_UI;
return SHFileOperation(&fos);
}


inline RString GetComputerName()
{
static RString str;
Expand Down

0 comments on commit 694049e

Please sign in to comment.