| 1 |
/* |
| 2 |
* Copyright (C) 2005-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "VideoTagLoaderPlugin.h" |
| 10 |
|
| 11 |
#include "FileItem.h" |
| 12 |
#include "URL.h" |
| 13 |
#include "filesystem/PluginDirectory.h" |
| 14 |
|
| 15 |
#include <memory> |
| 16 |
|
| 17 |
using namespace XFILE; |
| 18 |
|
| 19 |
CVideoTagLoaderPlugin::CVideoTagLoaderPlugin(const CFileItem& item, bool forceRefresh) |
| 20 |
: IVideoInfoTagLoader(item, nullptr, false), m_force_refresh(forceRefresh) |
| 21 |
{ |
| 22 |
if (forceRefresh) |
| 23 |
return; |
| 24 |
// Preserve CFileItem video info and art to avoid info loss between creating VideoInfoTagLoaderFactory and calling Load() |
| 25 |
if (m_item.HasVideoInfoTag()) |
| 26 |
m_tag = std::make_unique<CVideoInfoTag>(*m_item.GetVideoInfoTag()); |
| 27 |
auto& art = item.GetArt(); |
| 28 |
if (!art.empty()) |
| 29 |
m_art = std::make_unique<CGUIListItem::ArtMap>(art); |
| 30 |
} |
| 31 |
|
| 32 |
bool CVideoTagLoaderPlugin::HasInfo() const |
| 33 |
{ |
| 34 |
return m_tag || m_force_refresh; |
| 35 |
} |
| 36 |
|
| 37 |
CInfoScanner::INFO_TYPE CVideoTagLoaderPlugin::Load(CVideoInfoTag& tag, bool, std::vector<EmbeddedArt>*) |
| 38 |
{ |
| 39 |
if (m_force_refresh) |
| 40 |
{ |
| 41 |
// In case of force refresh call our plugin with option "kodi_action=refresh_info" |
| 42 |
// Plugin must do all refreshing work at specified path and return directory containing one ListItem with video tag and art |
| 43 |
// We cannot obtain all info from setResolvedUrl, because CPluginDirectory::GetPluginResult doesn't copy full art |
| 44 |
CURL url(m_item.GetPath()); |
| 45 |
url.SetOption("kodi_action", "refresh_info"); |
| 46 |
CPluginDirectory plugin; |
| 47 |
CFileItemList items; |
| 48 |
if (!plugin.GetDirectory(url, items)) |
| 49 |
return CInfoScanner::ERROR_NFO; |
| 50 |
if (!items.IsEmpty()) |
| 51 |
{ |
| 52 |
const CFileItemPtr &item = items[0]; |
| 53 |
m_art = std::make_unique<CGUIListItem::ArtMap>(item->GetArt()); |
| 54 |
if (item->HasVideoInfoTag()) |
| 55 |
{ |
| 56 |
tag = *item->GetVideoInfoTag(); |
| 57 |
return CInfoScanner::FULL_NFO; |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
else if (m_tag) |
| 62 |
{ |
| 63 |
// Otherwise just copy CFileItem video info to tag |
| 64 |
tag = *m_tag; |
| 65 |
return CInfoScanner::FULL_NFO; |
| 66 |
} |
| 67 |
return CInfoScanner::NO_NFO; |
| 68 |
} |