Skip to content

Commit

Permalink
Merge pull request #654 from jmarshallnz/set_nfo_scraping
Browse files Browse the repository at this point in the history
Set nfo scraping - fixes for Eden
  • Loading branch information
jmarshallnz committed Jan 24, 2012
2 parents a83b761 + cd69c70 commit 1c82327
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 52 deletions.
1 change: 1 addition & 0 deletions language/English/strings.xml
Expand Up @@ -1902,6 +1902,7 @@
<string id="20455">Listeners</string>
<string id="20456">Set movieset fanart</string>
<string id="20457">Movie set</string>
<string id="20458">Group movies in sets</string>
<!-- up to 21329 is reserved for the video db !! !-->

<string id="21330">Show hidden files and directories</string>
Expand Down
4 changes: 2 additions & 2 deletions xbmc/NfoFile.h
Expand Up @@ -51,7 +51,7 @@ class CNfoFile
NFOResult Create(const CStdString&, const ADDON::ScraperPtr&, int episode=-1,
const CStdString& strPath2="");
template<class T>
bool GetDetails(T& details,const char* document=NULL, bool prefix=false)
bool GetDetails(T& details,const char* document=NULL, bool prioritise=false)
{
TiXmlDocument doc;
CStdString strDoc;
Expand All @@ -64,7 +64,7 @@ class CNfoFile
g_charsetConverter.unknownToUTF8(strDoc);

doc.Parse(strDoc.c_str());
return details.Load(doc.RootElement(),true,prefix);
return details.Load(doc.RootElement(), true, prioritise);
}

void Close();
Expand Down
20 changes: 10 additions & 10 deletions xbmc/music/Album.cpp
Expand Up @@ -28,19 +28,19 @@
using namespace std;
using namespace MUSIC_INFO;

bool CAlbum::Load(const TiXmlElement *album, bool chained, bool prefix)
bool CAlbum::Load(const TiXmlElement *album, bool append, bool prioritise)
{
if (!album) return false;
if (!chained)
if (!append)
Reset();

XMLUtils::GetString(album,"title",strAlbum);

XMLUtils::GetAdditiveString(album,"artist",g_advancedSettings.m_musicItemSeparator,strArtist);
XMLUtils::GetAdditiveString(album,"genre",g_advancedSettings.m_musicItemSeparator,strGenre);
XMLUtils::GetAdditiveString(album,"style",g_advancedSettings.m_musicItemSeparator,strStyles);
XMLUtils::GetAdditiveString(album,"mood",g_advancedSettings.m_musicItemSeparator,strMoods);
XMLUtils::GetAdditiveString(album,"theme",g_advancedSettings.m_musicItemSeparator,strThemes);
XMLUtils::GetAdditiveString(album, "artist", g_advancedSettings.m_musicItemSeparator, strArtist, prioritise);
XMLUtils::GetAdditiveString(album, "genre", g_advancedSettings.m_musicItemSeparator, strGenre, prioritise);
XMLUtils::GetAdditiveString(album, "style", g_advancedSettings.m_musicItemSeparator, strStyles, prioritise);
XMLUtils::GetAdditiveString(album, "mood", g_advancedSettings.m_musicItemSeparator, strMoods, prioritise);
XMLUtils::GetAdditiveString(album, "theme", g_advancedSettings.m_musicItemSeparator, strThemes, prioritise);

XMLUtils::GetString(album,"review",strReview);
XMLUtils::GetString(album,"releasedate",m_strDateOfRelease);
Expand All @@ -65,16 +65,16 @@ bool CAlbum::Load(const TiXmlElement *album, bool chained, bool prefix)
while (thumb)
{
thumbURL.ParseElement(thumb);
if (prefix)
if (prioritise)
{
CStdString temp;
temp << *thumb;
xmlAdd = temp+xmlAdd;
}
thumb = thumb->NextSiblingElement("thumb");
}
// prefix thumbs from nfos
if (prefix && iThumbCount && iThumbCount != thumbURL.m_url.size())
// prioritise thumbs from nfos
if (prioritise && iThumbCount && iThumbCount != thumbURL.m_url.size())
{
rotate(thumbURL.m_url.begin(),
thumbURL.m_url.begin()+iThumbCount,
Expand Down
9 changes: 8 additions & 1 deletion xbmc/music/Album.h
Expand Up @@ -62,7 +62,14 @@ class CAlbum
songs.clear();
}

bool Load(const TiXmlElement *movie, bool chained=false, bool prefix=false);
/*! \brief Load album information from an XML file.
See CVideoInfoTag::Load for a description of the types of elements we load.
\param element the root XML element to parse.
\param append whether information should be added to the existing tag, or whether it should be reset first.
\param prioritise if appending, whether additive tags should be prioritised (i.e. replace or prepend) over existing values. Defaults to false.
\sa CVideoInfoTag::Load
*/
bool Load(const TiXmlElement *element, bool append = false, bool prioritise = false);
bool Save(TiXmlNode *node, const CStdString &tag, const CStdString& strPath);

long idAlbum;
Expand Down
20 changes: 10 additions & 10 deletions xbmc/music/Artist.cpp
Expand Up @@ -25,18 +25,18 @@

using namespace std;

bool CArtist::Load(const TiXmlElement *artist, bool chained, bool prefix)
bool CArtist::Load(const TiXmlElement *artist, bool append, bool prioritise)
{
if (!artist) return false;
if (!chained)
if (!append)
Reset();

XMLUtils::GetString(artist,"name",strArtist);
XMLUtils::GetAdditiveString(artist,"genre",g_advancedSettings.m_musicItemSeparator,strGenre);
XMLUtils::GetAdditiveString(artist,"style",g_advancedSettings.m_musicItemSeparator,strStyles);
XMLUtils::GetAdditiveString(artist,"mood",g_advancedSettings.m_musicItemSeparator,strMoods);
XMLUtils::GetAdditiveString(artist,"yearsactive",g_advancedSettings.m_musicItemSeparator,strYearsActive);
XMLUtils::GetAdditiveString(artist,"instruments",g_advancedSettings.m_musicItemSeparator,strInstruments);
XMLUtils::GetAdditiveString(artist, "genre", g_advancedSettings.m_musicItemSeparator, strGenre, prioritise);
XMLUtils::GetAdditiveString(artist, "style", g_advancedSettings.m_musicItemSeparator, strStyles, prioritise);
XMLUtils::GetAdditiveString(artist, "mood", g_advancedSettings.m_musicItemSeparator, strMoods, prioritise);
XMLUtils::GetAdditiveString(artist, "yearsactive", g_advancedSettings.m_musicItemSeparator, strYearsActive, prioritise);
XMLUtils::GetAdditiveString(artist, "instruments", g_advancedSettings.m_musicItemSeparator, strInstruments, prioritise);

XMLUtils::GetString(artist,"born",strBorn);
XMLUtils::GetString(artist,"formed",strFormed);
Expand All @@ -51,7 +51,7 @@ bool CArtist::Load(const TiXmlElement *artist, bool chained, bool prefix)
while (thumb)
{
thumbURL.ParseElement(thumb);
if (prefix)
if (prioritise)
{
CStdString temp;
temp << *thumb;
Expand All @@ -60,7 +60,7 @@ bool CArtist::Load(const TiXmlElement *artist, bool chained, bool prefix)
thumb = thumb->NextSiblingElement("thumb");
}
// prefix thumbs from nfos
if (prefix && iThumbCount && iThumbCount != thumbURL.m_url.size())
if (prioritise && iThumbCount && iThumbCount != thumbURL.m_url.size())
{
rotate(thumbURL.m_url.begin(),
thumbURL.m_url.begin()+iThumbCount,
Expand Down Expand Up @@ -88,7 +88,7 @@ bool CArtist::Load(const TiXmlElement *artist, bool chained, bool prefix)
if (fanart2)
{
// we prefix to handle mixed-mode nfo's with fanart set
if (prefix)
if (prioritise)
{
CStdString temp;
temp << *fanart2;
Expand Down
9 changes: 8 additions & 1 deletion xbmc/music/Artist.h
Expand Up @@ -56,7 +56,14 @@ class CArtist
idArtist = -1;
}

bool Load(const TiXmlElement *movie, bool chained=false, bool prefix=false);
/*! \brief Load artist information from an XML file.
See CVideoInfoTag::Load for a description of the types of elements we load.
\param element the root XML element to parse.
\param append whether information should be added to the existing tag, or whether it should be reset first.
\param prioritise if appending, whether additive tags should be prioritised (i.e. replace or prepend) over existing values. Defaults to false.
\sa CVideoInfoTag::Load
*/
bool Load(const TiXmlElement *element, bool append = false, bool prioritise = false);
bool Save(TiXmlNode *node, const CStdString &tag, const CStdString& strPath);

CStdString strArtist;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/settings/GUISettings.cpp
Expand Up @@ -554,7 +554,7 @@ void CGUISettings::Initialize()
flattenTVShowOptions.insert(make_pair(20422, 2));
AddInt(vdl, "videolibrary.flattentvshows", 20412, 1, flattenTVShowOptions, SPIN_CONTROL_TEXT);

AddBool(NULL, "videolibrary.flattenmoviesets", 22002, false);
AddBool(vdl, "videolibrary.groupmoviesets", 20458, false);
AddBool(vdl, "videolibrary.updateonstartup", 22000, false);
AddBool(vdl, "videolibrary.backgroundupdate", 22001, false);
AddSeparator(vdl, "videolibrary.sep3");
Expand Down
5 changes: 4 additions & 1 deletion xbmc/utils/XMLUtils.cpp
Expand Up @@ -133,11 +133,14 @@ bool XMLUtils::GetString(const TiXmlNode* pRootNode, const char* strTag, CStdStr
}

bool XMLUtils::GetAdditiveString(const TiXmlNode* pRootNode, const char* strTag,
const CStdString& strSeparator, CStdString& strStringValue)
const CStdString& strSeparator, CStdString& strStringValue,
bool clear)
{
CStdString strTemp;
const TiXmlElement* node = pRootNode->FirstChildElement(strTag);
bool bResult=false;
if (node && node->FirstChild() && clear)
strStringValue.clear();
while (node)
{
if (node->FirstChild())
Expand Down
16 changes: 15 additions & 1 deletion xbmc/utils/XMLUtils.h
Expand Up @@ -38,7 +38,21 @@ class XMLUtils
static bool GetInt(const TiXmlNode* pRootNode, const char* strTag, int& iIntValue);
static bool GetBoolean(const TiXmlNode* pRootNode, const char* strTag, bool& bBoolValue);
static bool GetString(const TiXmlNode* pRootNode, const char* strTag, CStdString& strStringValue);
static bool GetAdditiveString(const TiXmlNode* pRootNode, const char* strTag, const CStdString& strSeparator, CStdString& strStringValue);
/*! \brief Get multiple tags, concatenating the values together.
Transforms
<tag>value1</tag>
<tag clear="true">value2</tag>
...
<tag>valuen</tag>
into value2<sep>...<sep>valuen, appending it to the value string. Note that <value1> is overwritten by the clear="true" tag.
\param rootNode the parent containing the <tag>'s.
\param tag the <tag> in question.
\param separator the separator to use when concatenating values.
\param value [out] the resulting string. Remains untouched if no <tag> is available, else is appended (or cleared based on the clear parameter).
\param clear if true, clears the string prior to adding tags, if tags are available. Defaults to false.
*/
static bool GetAdditiveString(const TiXmlNode* rootNode, const char* tag, const CStdString& separator, CStdString& value, bool clear = false);
static bool GetEncoding(const TiXmlDocument* pDoc, CStdString& strEncoding);
static bool GetPath(const TiXmlNode* pRootNode, const char* strTag, CStdString& strStringValue);
static bool GetFloat(const TiXmlNode* pRootNode, const char* strTag, float& value, const float min, const float max);
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/VideoDatabase.cpp
Expand Up @@ -4715,7 +4715,7 @@ bool CVideoDatabase::GetMoviesByWhere(const CStdString& strBaseDir, const CStdSt
strSQL += where;
else
{
if (fetchSets && !g_guiSettings.GetBool("videolibrary.flattenmoviesets"))
if (fetchSets && g_guiSettings.GetBool("videolibrary.groupmoviesets"))
{
GetSetsNav("videodb://1/7/", items, VIDEODB_CONTENT_MOVIES, "");
strSQL += PrepareSQL("WHERE movieview.idMovie NOT IN (SELECT idMovie FROM setlinkmovie s1 JOIN(SELECT idSet, COUNT(1) AS c FROM setlinkmovie GROUP BY idSet HAVING c>1) s2 ON s2.idSet=s1.idSet)");
Expand Down
47 changes: 25 additions & 22 deletions xbmc/video/VideoInfoTag.cpp
Expand Up @@ -250,16 +250,13 @@ bool CVideoInfoTag::Save(TiXmlNode *node, const CStdString &tag, bool savePathIn
return true;
}

bool CVideoInfoTag::Load(const TiXmlElement *movie, bool chained /* = false */,
bool prefix /* = false */)
bool CVideoInfoTag::Load(const TiXmlElement *element, bool append, bool prioritise)
{
if (!movie) return false;

// reset our details if we aren't chained.
if (!chained) Reset();

ParseNative(movie,prefix);

if (!element)
return false;
if (!append)
Reset();
ParseNative(element, prioritise);
return true;
}

Expand Down Expand Up @@ -508,7 +505,7 @@ const CStdString CVideoInfoTag::GetCast(bool bIncludeRole /*= false*/) const
return strLabel.TrimRight("\n");
}

void CVideoInfoTag::ParseNative(const TiXmlElement* movie, bool prefix)
void CVideoInfoTag::ParseNative(const TiXmlElement* movie, bool prioritise)
{
XMLUtils::GetString(movie, "title", m_strTitle);
XMLUtils::GetString(movie, "originaltitle", m_strOriginalTitle);
Expand Down Expand Up @@ -563,7 +560,7 @@ void CVideoInfoTag::ParseNative(const TiXmlElement* movie, bool prefix)
while (thumb)
{
m_strPictureURL.ParseElement(thumb);
if (prefix)
if (prioritise)
{
CStdString temp;
temp << *thumb;
Expand All @@ -572,23 +569,25 @@ void CVideoInfoTag::ParseNative(const TiXmlElement* movie, bool prefix)
thumb = thumb->NextSiblingElement("thumb");
}

// prefix thumbs from nfos
if (prefix && iThumbCount && iThumbCount != m_strPictureURL.m_url.size())
// prioritise thumbs from nfos
if (prioritise && iThumbCount && iThumbCount != m_strPictureURL.m_url.size())
{
rotate(m_strPictureURL.m_url.begin(),
m_strPictureURL.m_url.begin()+iThumbCount,
m_strPictureURL.m_url.end());
m_strPictureURL.m_xml = xmlAdd;
}

XMLUtils::GetAdditiveString(movie,"genre",g_advancedSettings.m_videoItemSeparator,m_strGenre);
XMLUtils::GetAdditiveString(movie,"country",g_advancedSettings.m_videoItemSeparator,m_strCountry);
XMLUtils::GetAdditiveString(movie,"credits",g_advancedSettings.m_videoItemSeparator,m_strWritingCredits);
XMLUtils::GetAdditiveString(movie,"director",g_advancedSettings.m_videoItemSeparator,m_strDirector);
XMLUtils::GetAdditiveString(movie,"showlink",g_advancedSettings.m_videoItemSeparator,m_strShowLink);
XMLUtils::GetAdditiveString(movie, "genre", g_advancedSettings.m_videoItemSeparator, m_strGenre, prioritise);
XMLUtils::GetAdditiveString(movie, "country", g_advancedSettings.m_videoItemSeparator, m_strCountry, prioritise);
XMLUtils::GetAdditiveString(movie, "credits", g_advancedSettings.m_videoItemSeparator, m_strWritingCredits, prioritise);
XMLUtils::GetAdditiveString(movie, "director", g_advancedSettings.m_videoItemSeparator, m_strDirector, prioritise);
XMLUtils::GetAdditiveString(movie, "showlink", g_advancedSettings.m_videoItemSeparator, m_strShowLink, prioritise);

// cast
const TiXmlElement* node = movie->FirstChildElement("actor");
if (node && node->FirstChild() && prioritise)
m_cast.clear();
while (node)
{
const TiXmlNode *actor = node->FirstChild("name");
Expand All @@ -614,6 +613,8 @@ void CVideoInfoTag::ParseNative(const TiXmlElement* movie, bool prefix)
}

node = movie->FirstChildElement("set");
if (node && node->FirstChild() && prioritise)
m_set.clear();
while (node)
{
if (node->FirstChild())
Expand All @@ -622,9 +623,11 @@ void CVideoInfoTag::ParseNative(const TiXmlElement* movie, bool prefix)
node = node->NextSiblingElement("set");
}

XMLUtils::GetAdditiveString(movie,"studio",g_advancedSettings.m_videoItemSeparator,m_strStudio);
XMLUtils::GetAdditiveString(movie, "studio", g_advancedSettings.m_videoItemSeparator, m_strStudio, prioritise);
// artists
node = movie->FirstChildElement("artist");
if (node && node->FirstChild() && prioritise)
m_strArtist.clear();
while (node)
{
const TiXmlNode* pNode = node->FirstChild("name");
Expand All @@ -637,7 +640,7 @@ void CVideoInfoTag::ParseNative(const TiXmlElement* movie, bool prefix)
{
const char* clear=node->Attribute("clear");
if (m_strArtist.IsEmpty() || (clear && stricmp(clear,"true")==0))
m_strArtist += pValue;
m_strArtist = pValue;
else
m_strArtist += g_advancedSettings.m_videoItemSeparator + pValue;
}
Expand Down Expand Up @@ -704,8 +707,8 @@ void CVideoInfoTag::ParseNative(const TiXmlElement* movie, bool prefix)
const TiXmlElement *fanart = movie->FirstChildElement("fanart");
if (fanart)
{
// we prefix to handle mixed-mode nfo's with fanart set
if (prefix)
// we prioritise mixed-mode nfo's with fanart set
if (prioritise)
{
CStdString temp;
temp << *fanart;
Expand Down
26 changes: 24 additions & 2 deletions xbmc/video/VideoInfoTag.h
Expand Up @@ -43,7 +43,22 @@ class CVideoInfoTag : public IArchivable, public ISerializable
public:
CVideoInfoTag() { Reset(); };
void Reset();
bool Load(const TiXmlElement *movie, bool chained = false, bool prefix=false);
/* \brief Load information to a videoinfotag from an XML element
There are three types of tags supported:
1. Single-value tags, such as <title>. These are set if available, else are left untouched.
2. Additive tags, such as <set> or <genre>. These are appended to or replaced (if available) based on the value
of the prioritise parameter. In addition, a clear attribute is available in the XML to clear the current value prior
to appending.
3. Image tags such as <thumb> and <fanart>. If the prioritise value is specified, any additional values are prepended
to the existing values.
\param element the root XML element to parse.
\param append whether information should be added to the existing tag, or whether it should be reset first.
\param prioritise if appending, whether additive tags should be prioritised (i.e. replace or prepend) over existing values. Defaults to false.
\sa ParseNative
*/
bool Load(const TiXmlElement *element, bool append = false, bool prioritise = false);
bool Save(TiXmlNode *node, const CStdString &tag, bool savePathInfo = true);
virtual void Archive(CArchive& ar);
virtual void Serialize(CVariant& value);
Expand Down Expand Up @@ -114,7 +129,14 @@ class CVideoInfoTag : public IArchivable, public ISerializable
CBookmark m_resumePoint;

private:
void ParseNative(const TiXmlElement* movie, bool prefix);
/* \brief Parse our native XML format for video info.
See Load for a description of the available tag types.
\param element the root XML element to parse.
\param prioritise whether additive tags should be replaced (or prepended) by the content of the tags, or appended to.
\sa Load
*/
void ParseNative(const TiXmlElement* element, bool prioritise);
};

typedef std::vector<CVideoInfoTag> VECMOVIES;

0 comments on commit 1c82327

Please sign in to comment.