Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added: POC mp4 movie/episode tag support #5416

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions xbmc/music/tags/TagLoaderTagLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "utils/CharsetConverter.h"
#include "utils/Base64.h"
#include "settings/AdvancedSettings.h"
#include "video/VideoInfoTag.h"

using namespace std;
using namespace TagLib;
Expand Down Expand Up @@ -258,6 +259,45 @@ bool CTagLoaderTagLib::Load(const std::string& strFileName, CMusicInfoTag& tag,
return true;
}

bool CTagLoaderTagLib::Load(const CStdString& strFileName, CVideoInfoTag& tag)
{
CStdString strExtension = URIUtils::GetExtension(strFileName);
StringUtils::ToLower(strExtension);
StringUtils::TrimLeft(strExtension, ".");

TagLibVFSStream* stream = new TagLibVFSStream(strFileName, true);
if (!stream)
{
CLog::Log(LOGERROR, "could not create TagLib VFS stream for: %s", strFileName.c_str());
return false;
}

TagLib::File* file = NULL;
TagLib::MP4::File* mp4File = NULL;

if (strExtension == "mp4")
file = mp4File = new MP4::File(stream);

if (file && !file->isOpen())
{
delete file;
delete stream;
CLog::Log(LOGDEBUG, "file could not be opened for tag reading");
return false;
}
if (!file)
return true;

MP4::Tag *mp4 = NULL;
mp4 = mp4File->tag();
ParseMP4Tag(mp4, tag);

delete file;
delete stream;

return true;
}

bool CTagLoaderTagLib::ParseASF(ASF::Tag *asf, EmbeddedArt *art, CMusicInfoTag& tag)
{
if (!asf)
Expand Down Expand Up @@ -673,6 +713,33 @@ bool CTagLoaderTagLib::ParseMP4Tag(MP4::Tag *mp4, EmbeddedArt *art, CMusicInfoTa
return true;
}

bool CTagLoaderTagLib::ParseMP4Tag(MP4::Tag *mp4, CVideoInfoTag& tag)
{
if (!mp4)
return false;

MP4::ItemListMap& itemListMap = mp4->itemListMap();
for (MP4::ItemListMap::ConstIterator it = itemListMap.begin(); it != itemListMap.end(); ++it)
{
if (it->first == "\251nam")
tag.m_strTitle = it->second.toStringList().front().to8Bit(true);
else if (it->first == "\251vsh")
tag.m_strShowTitle = it->second.toStringList().front().to8Bit(true);
else if (it->first == "\251gen")
tag.m_genre = StringListToVectorString(it->second.toStringList());
else if (it->first == "\251cmt")
tag.m_strPlot = it->second.toStringList().front().to8Bit(true);
else if (it->first == "\251desc")
tag.m_strPlotOutline = it->second.toStringList().front().to8Bit(true);
else if (it->first == "tvsn")
tag.m_iSeason = it->second.toIntPair().first;
else if (it->first == "tves")
tag.m_iEpisode = it->second.toIntPair().first;
}

This comment was marked as spam.


return true;
}

bool CTagLoaderTagLib::ParseGenericTag(Tag *generic, EmbeddedArt *art, CMusicInfoTag& tag)
{
if (!generic)
Expand Down
6 changes: 5 additions & 1 deletion xbmc/music/tags/TagLoaderTagLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ namespace MUSIC_INFO
class EmbeddedArt;
};

class CVideoInfoTag;

class CTagLoaderTagLib : public MUSIC_INFO::IMusicInfoTagLoader
{
public:
CTagLoaderTagLib();
virtual ~CTagLoaderTagLib();
virtual bool Load(const std::string& strFileName, MUSIC_INFO::CMusicInfoTag& tag, MUSIC_INFO::EmbeddedArt *art = NULL);

bool Load(const std::string& strFileName, CVideoInfoTag& tag);

bool Load(const std::string& strFileName, MUSIC_INFO::CMusicInfoTag& tag, const std::string& fallbackFileExtension, MUSIC_INFO::EmbeddedArt *art = NULL);

const std::vector<std::string> SplitMBID(const std::vector<std::string> &values);
Expand All @@ -72,6 +75,7 @@ class CTagLoaderTagLib : public MUSIC_INFO::IMusicInfoTagLoader
bool ParseID3v2Tag(TagLib::ID3v2::Tag *id3v2, MUSIC_INFO::EmbeddedArt *art, MUSIC_INFO::CMusicInfoTag& tag);
bool ParseXiphComment(TagLib::Ogg::XiphComment *id3v2, MUSIC_INFO::EmbeddedArt *art, MUSIC_INFO::CMusicInfoTag& tag);
bool ParseMP4Tag(TagLib::MP4::Tag *mp4, MUSIC_INFO::EmbeddedArt *art, MUSIC_INFO::CMusicInfoTag& tag);
bool ParseMP4Tag(TagLib::MP4::Tag *mp4, CVideoInfoTag& tag);
bool ParseGenericTag(TagLib::Tag *generic, MUSIC_INFO::EmbeddedArt *art, MUSIC_INFO::CMusicInfoTag& tag);
void SetFlacArt(TagLib::FLAC::File *flacFile, MUSIC_INFO::EmbeddedArt *art, MUSIC_INFO::CMusicInfoTag &tag);
void SetArtist(MUSIC_INFO::CMusicInfoTag &tag, const std::vector<std::string> &values);
Expand Down
23 changes: 20 additions & 3 deletions xbmc/video/VideoInfoScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "TextureCache.h"
#include "GUIUserMessages.h"
#include "URL.h"
#include "music/tags/TagLoaderTagLib.h"

using namespace std;
using namespace XFILE;
Expand Down Expand Up @@ -615,10 +616,20 @@ namespace VIDEO
// handle .nfo files
if (useLocal)
result = CheckForNFOFile(pItem, bDirNames, info2, scrUrl);
if (result == CNfoFile::FULL_NFO)
if (pItem->IsType(".mp4"))
{
pItem->GetVideoInfoTag()->Reset();
m_nfoReader.GetDetails(*pItem->GetVideoInfoTag());
CTagLoaderTagLib loader;
loader.Load(pItem->GetPath(), *pItem->GetVideoInfoTag());
}
if (result == CNfoFile::FULL_NFO ||
( pItem->HasVideoInfoTag() &&
!pItem->GetVideoInfoTag()->m_strTitle.empty()))
{
if (result == CNfoFile::FULL_NFO)
{
pItem->GetVideoInfoTag()->Reset();
m_nfoReader.GetDetails(*pItem->GetVideoInfoTag());
}

if (AddVideo(pItem, info2->Content(), bDirNames, true) < 0)
return INFO_ERROR;
Expand Down Expand Up @@ -848,6 +859,12 @@ namespace VIDEO
if (CUtil::ExcludeFileOrFolder(items[i]->GetPath(), regexps))
continue;

if (items[i]->IsType(".mp4"))
{
CTagLoaderTagLib loader;
loader.Load(items[i]->GetPath(), *items[i]->GetVideoInfoTag());
}

/*
* Check if the media source has already set the season and episode or original air date in
* the VideoInfoTag. If it has, do not try to parse any of them from the file path to avoid
Expand Down