Skip to content

Commit

Permalink
Merge pull request #1192 from koying/noop-scraper
Browse files Browse the repository at this point in the history
ADD: No-Op scraper support to allow nfo based only library
  • Loading branch information
koying committed Apr 1, 2013
2 parents 84b61ee + 5527a6b commit 9fdb68a
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 7 deletions.
29 changes: 29 additions & 0 deletions addons/metadata.local/addon.xml
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="metadata.local"
name="Local information only"
version="1.0.0"
provider-name="Team XBMC">
<requires>
<import addon="xbmc.metadata" version="1.0"/>
</requires>
<extension point="xbmc.metadata.scraper.albums"
language="multi"
library="local.xml"/>
<extension point="xbmc.metadata.scraper.artists"
language="multi"
library="local.xml"/>
<extension point="xbmc.metadata.scraper.musicvideos"
language="multi"
library="local.xml"/>
<extension point="xbmc.metadata.scraper.tvshows"
language="multi"
library="local.xml"/>
<extension point="xbmc.metadata.scraper.movies"
language="multi"
library="local.xml"/>
<extension point="xbmc.addon.metadata">
<summary lang="en">Local Infomation only pseudo-scraper</summary>
<description lang="en">Use local information only</description>
<platform>all</platform>
</extension>
</addon>
3 changes: 3 additions & 0 deletions addons/metadata.local/local.xml
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<scraper framework="1.1">
</scraper>
5 changes: 5 additions & 0 deletions xbmc/NfoFile.cpp
Expand Up @@ -131,6 +131,11 @@ CNfoFile::NFOResult CNfoFile::Create(const CStdString& strPath, const ScraperPtr
// return value: 0 - success; 1 - no result; skip; 2 - error
int CNfoFile::Scrape(ScraperPtr& scraper)
{
if (scraper->IsNoop())
{
m_scurl = CScraperUrl();
return 0;
}
if (scraper->Type() != m_type)
return 1;
scraper->ClearCache();
Expand Down
32 changes: 26 additions & 6 deletions xbmc/addons/Scraper.cpp
Expand Up @@ -412,12 +412,23 @@ bool CScraper::IsInUse() const
return false;
}

bool CScraper::IsNoop()
{
if (!Load())
throw CScraperError();

return m_parser.IsNoop();
}

// pass in contents of .nfo file; returns URL (possibly empty if none found)
// and may populate strId, or throws CScraperError on error
CScraperUrl CScraper::NfoUrl(const CStdString &sNfoContent)
{
CScraperUrl scurlRet;

if (IsNoop())
return scurlRet;

// scraper function takes contents of .nfo file, returns XML (see below)
vector<CStdString> vcsIn;
vcsIn.push_back(sNfoContent);
Expand Down Expand Up @@ -490,14 +501,18 @@ std::vector<CScraperUrl> CScraper::FindMovie(XFILE::CCurlFile &fcurl, const CStd
CStdString sTitle, sTitleYear, sYear;
CUtil::CleanString(sMovie, sTitle, sTitleYear, sYear, true/*fRemoveExt*/, fFirst);

if (!fFirst || Content() == CONTENT_MUSICVIDEOS)
sTitle.Replace("-"," ");

CLog::Log(LOGDEBUG, "%s: Searching for '%s' using %s scraper "
"(path: '%s', content: '%s', version: '%s')", __FUNCTION__, sTitle.c_str(),
Name().c_str(), Path().c_str(),
ADDON::TranslateContent(Content()).c_str(), Version().c_str());

std::vector<CScraperUrl> vcscurl;
if (IsNoop())
return vcscurl;

if (!fFirst || Content() == CONTENT_MUSICVIDEOS)
sTitle.Replace("-"," ");

sTitle.ToLower();

vector<CStdString> vcsIn(1);
Expand All @@ -509,7 +524,6 @@ std::vector<CScraperUrl> CScraper::FindMovie(XFILE::CCurlFile &fcurl, const CStd
// request a search URL from the title/filename/etc.
CScraperUrl scurl;
vector<CStdString> vcsOut = Run("CreateSearchUrl", scurl, fcurl, &vcsIn);
std::vector<CScraperUrl> vcscurl;
if (vcsOut.empty())
{
CLog::Log(LOGDEBUG, "%s: CreateSearchUrl failed", __FUNCTION__);
Expand Down Expand Up @@ -616,6 +630,10 @@ std::vector<CMusicAlbumInfo> CScraper::FindAlbum(CCurlFile &fcurl, const CStdStr
sAlbum.c_str(), Name().c_str(), Path().c_str(),
ADDON::TranslateContent(Content()).c_str(), Version().c_str());

std::vector<CMusicAlbumInfo> vcali;
if (IsNoop())
return vcali;

// scraper function is given the album and artist as parameters and
// returns an XML <url> element parseable by CScraperUrl
std::vector<CStdString> extras(2);
Expand All @@ -628,7 +646,6 @@ std::vector<CMusicAlbumInfo> CScraper::FindAlbum(CCurlFile &fcurl, const CStdStr
if (vcsOut.size() > 1)
CLog::Log(LOGWARNING, "%s: scraper returned multiple results; using first", __FUNCTION__);

std::vector<CMusicAlbumInfo> vcali;
if (vcsOut.empty() || vcsOut[0].empty())
return vcali;
scurl.ParseString(vcsOut[0]);
Expand Down Expand Up @@ -710,6 +727,10 @@ std::vector<CMusicArtistInfo> CScraper::FindArtist(CCurlFile &fcurl,
Name().c_str(), Path().c_str(),
ADDON::TranslateContent(Content()).c_str(), Version().c_str());

std::vector<CMusicArtistInfo> vcari;
if (IsNoop())
return vcari;

// scraper function is given the artist as parameter and
// returns an XML <url> element parseable by CScraperUrl
std::vector<CStdString> extras(1);
Expand All @@ -718,7 +739,6 @@ std::vector<CMusicArtistInfo> CScraper::FindArtist(CCurlFile &fcurl,
CScraperUrl scurl;
vector<CStdString> vcsOut = RunNoThrow("CreateArtistSearchUrl", scurl, fcurl, &extras);

std::vector<CMusicArtistInfo> vcari;
if (vcsOut.empty() || vcsOut[0].empty())
return vcari;
scurl.ParseString(vcsOut[0]);
Expand Down
1 change: 1 addition & 0 deletions xbmc/addons/Scraper.h
Expand Up @@ -116,6 +116,7 @@ class CScraper : public CAddon
bool Supports(const CONTENT_TYPE &content) const;

bool IsInUse() const;
bool IsNoop();

// scraper media functions
CScraperUrl NfoUrl(const CStdString &sNfoContent);
Expand Down
5 changes: 5 additions & 0 deletions xbmc/utils/ScraperParser.cpp
Expand Up @@ -42,6 +42,7 @@ CScraperParser::CScraperParser()
m_document = NULL;
m_SearchStringEncoding = "UTF-8";
m_scraper = NULL;
m_isNoop = true;
}

CScraperParser::CScraperParser(const CScraperParser& parser)
Expand All @@ -50,6 +51,7 @@ CScraperParser::CScraperParser(const CScraperParser& parser)
m_document = NULL;
m_SearchStringEncoding = "UTF-8";
m_scraper = NULL;
m_isNoop = true;
*this = parser;
}

Expand Down Expand Up @@ -115,19 +117,22 @@ bool CScraperParser::LoadFromXML()
TiXmlElement* pChildElement = m_pRootElement->FirstChildElement("CreateSearchUrl");
if (pChildElement)
{
m_isNoop = false;
if (!(m_SearchStringEncoding = pChildElement->Attribute("SearchStringEncoding")))
m_SearchStringEncoding = "UTF-8";
}

pChildElement = m_pRootElement->FirstChildElement("CreateArtistSearchUrl");
if (pChildElement)
{
m_isNoop = false;
if (!(m_SearchStringEncoding = pChildElement->Attribute("SearchStringEncoding")))
m_SearchStringEncoding = "UTF-8";
}
pChildElement = m_pRootElement->FirstChildElement("CreateAlbumSearchUrl");
if (pChildElement)
{
m_isNoop = false;
if (!(m_SearchStringEncoding = pChildElement->Attribute("SearchStringEncoding")))
m_SearchStringEncoding = "UTF-8";
}
Expand Down
2 changes: 2 additions & 0 deletions xbmc/utils/ScraperParser.h
Expand Up @@ -45,6 +45,7 @@ class CScraperParser
~CScraperParser();
CScraperParser& operator= (const CScraperParser& parser);
bool Load(const CStdString& strXMLFile);
bool IsNoop() { return m_isNoop; };

void Clear();
const CStdString GetFilename() { return m_strFile; }
Expand Down Expand Up @@ -76,6 +77,7 @@ class CScraperParser
TiXmlElement* m_pRootElement;

const char* m_SearchStringEncoding;
bool m_isNoop;

CStdString m_strFile;
ADDON::CScraper* m_scraper;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/windows/GUIWindowVideoBase.cpp
Expand Up @@ -511,7 +511,7 @@ bool CGUIWindowVideoBase::ShowIMDB(CFileItem *item, const ScraperPtr &info2)
if (needsRefresh)
{
bHasInfo = true;
if (nfoResult == CNfoFile::URL_NFO || nfoResult == CNfoFile::COMBINED_NFO || nfoResult == CNfoFile::FULL_NFO)
if (!info->IsNoop() && (nfoResult == CNfoFile::URL_NFO || nfoResult == CNfoFile::COMBINED_NFO || nfoResult == CNfoFile::FULL_NFO))
{
if (CGUIDialogYesNo::ShowAndGetInput(13346,20446,20447,20022))
{
Expand Down

0 comments on commit 9fdb68a

Please sign in to comment.