Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

ADD: No-Op scraper support to allow nfo based only library #1192

Merged
merged 1 commit into from Apr 1, 2013
Jump to file or symbol
Failed to load files and symbols.
+72 −7
Split
@@ -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>
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<scraper framework="1.1">
+</scraper>
View
@@ -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();
View
@@ -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);
@@ -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);
@@ -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__);
@@ -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);
@@ -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]);
@@ -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);
@@ -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]);
View
@@ -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);
@@ -42,6 +42,7 @@ CScraperParser::CScraperParser()
m_document = NULL;
m_SearchStringEncoding = "UTF-8";
m_scraper = NULL;
+ m_isNoop = true;
}
CScraperParser::CScraperParser(const CScraperParser& parser)
@@ -50,6 +51,7 @@ CScraperParser::CScraperParser(const CScraperParser& parser)
m_document = NULL;
m_SearchStringEncoding = "UTF-8";
m_scraper = NULL;
+ m_isNoop = true;
*this = parser;
}
@@ -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";
}
@@ -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; }
@@ -76,6 +77,7 @@ class CScraperParser
TiXmlElement* m_pRootElement;
const char* m_SearchStringEncoding;
+ bool m_isNoop;
CStdString m_strFile;
ADDON::CScraper* m_scraper;
@@ -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))
{