void CFileItemHandler::HandleFileItem(const char *ID, bool allowFile, const char *resultname, CFileItemPtr item, const CVariant ¶meterObject, const std::set<std::string> &validFields, CVariant &result, bool append /* = true */, CThumbLoader *thumbLoader /* = NULL */) { CVariant object; std::set<std::string> fields(validFields.begin(), validFields.end()); if (item.get()) { std::set<std::string>::const_iterator fileField = fields.find("file"); if (fileField != fields.end()) { if (allowFile) { if (item->HasVideoInfoTag() && !item->GetVideoInfoTag()->GetPath().IsEmpty()) object["file"] = item->GetVideoInfoTag()->GetPath().c_str(); if (item->HasMusicInfoTag() && !item->GetMusicInfoTag()->GetURL().IsEmpty()) object["file"] = item->GetMusicInfoTag()->GetURL().c_str(); if (!object.isMember("file")) object["file"] = item->GetPath().c_str(); } fields.erase(fileField); } if (ID) { if (item->HasPVRChannelInfoTag() && item->GetPVRChannelInfoTag()->ChannelID() > 0) object[ID] = item->GetPVRChannelInfoTag()->ChannelID(); else if (item->HasMusicInfoTag() && item->GetMusicInfoTag()->GetDatabaseId() > 0) object[ID] = (int)item->GetMusicInfoTag()->GetDatabaseId(); else if (item->HasVideoInfoTag() && item->GetVideoInfoTag()->m_iDbId > 0) object[ID] = item->GetVideoInfoTag()->m_iDbId; if (stricmp(ID, "id") == 0) { if (item->HasPVRChannelInfoTag()) object["type"] = "channel"; else if (item->HasMusicInfoTag()) { if (item->m_bIsFolder && item->IsAlbum()) object["type"] = "album"; else object["type"] = "song"; } else if (item->HasVideoInfoTag() && !item->GetVideoInfoTag()->m_type.empty()) { std::string type = item->GetVideoInfoTag()->m_type; if (type == "movie" || type == "tvshow" || type == "episode" || type == "musicvideo") object["type"] = type; } else if (item->HasPictureInfoTag()) object["type"] = "picture"; if (!object.isMember("type")) object["type"] = "unknown"; } } bool deleteThumbloader = false; if (thumbLoader == NULL) { if (item->HasVideoInfoTag()) thumbLoader = new CVideoThumbLoader(); else if (item->HasMusicInfoTag()) thumbLoader = new CMusicThumbLoader(); if (thumbLoader != NULL) { deleteThumbloader = true; thumbLoader->Initialize(); } } if (item->HasPVRChannelInfoTag()) FillDetails(item->GetPVRChannelInfoTag(), item, fields, object, thumbLoader); if (item->HasVideoInfoTag()) FillDetails(item->GetVideoInfoTag(), item, fields, object, thumbLoader); if (item->HasMusicInfoTag()) FillDetails(item->GetMusicInfoTag(), item, fields, object, thumbLoader); if (item->HasPictureInfoTag()) FillDetails(item->GetPictureInfoTag(), item, fields, object, thumbLoader); FillDetails(item.get(), item, fields, object, thumbLoader); if (deleteThumbloader) delete thumbLoader; object["label"] = item->GetLabel().c_str(); } else object = CVariant(CVariant::VariantTypeNull); if (resultname) { if (append) result[resultname].append(object); else result[resultname] = object; } }
void CFileItemHandler::HandleFileItem(const char *ID, bool allowFile, const char *resultname, CFileItemPtr item, const CVariant ¶meterObject, const CVariant &validFields, CVariant &result, bool append /* = true */) { CVariant object; bool hasFileField = false; bool hasThumbnailField = false; if (item.get()) { for (unsigned int i = 0; i < validFields.size(); i++) { CStdString field = validFields[i].asString(); if (field == "file") hasFileField = true; if (field == "thumbnail") hasThumbnailField = true; } if (allowFile && hasFileField) { if (item->HasVideoInfoTag() && !item->GetVideoInfoTag()->GetPath().IsEmpty()) object["file"] = item->GetVideoInfoTag()->GetPath().c_str(); if (item->HasMusicInfoTag() && !item->GetMusicInfoTag()->GetURL().IsEmpty()) object["file"] = item->GetMusicInfoTag()->GetURL().c_str(); if (!object.isMember("file")) object["file"] = item->GetPath().c_str(); } if (ID) { if (item->HasMusicInfoTag() && item->GetMusicInfoTag()->GetDatabaseId() > 0) object[ID] = (int)item->GetMusicInfoTag()->GetDatabaseId(); else if (item->HasVideoInfoTag() && item->GetVideoInfoTag()->m_iDbId > 0) object[ID] = item->GetVideoInfoTag()->m_iDbId; if (stricmp(ID, "id") == 0) { if (item->HasMusicInfoTag()) { if (item->m_bIsFolder && item->IsAlbum()) object["type"] = "album"; else object["type"] = "song"; } else if (item->HasVideoInfoTag()) { switch (item->GetVideoContentType()) { case VIDEODB_CONTENT_EPISODES: object["type"] = "episode"; break; case VIDEODB_CONTENT_MUSICVIDEOS: object["type"] = "musicvideo"; break; case VIDEODB_CONTENT_MOVIES: object["type"] = "movie"; break; case VIDEODB_CONTENT_TVSHOWS: object["type"] = "tvshow"; break; default: break; } } else if (item->HasPictureInfoTag()) object["type"] = "picture"; if (!object.isMember("type")) object["type"] = "unknown"; } } if (hasThumbnailField) { if (item->HasThumbnail()) object["thumbnail"] = CTextureCache::Get().CheckAndCacheImage(item->GetThumbnailImage()); else if (item->HasVideoInfoTag()) { CStdString strPath, strFileName; URIUtils::Split(item->GetCachedVideoThumb(), strPath, strFileName); CStdString cachedThumb = strPath + "auto-" + strFileName; if (CFile::Exists(cachedThumb)) object["thumbnail"] = cachedThumb; } else if (item->HasPictureInfoTag()) { CStdString thumb = CTextureCache::Get().CheckAndCacheImage(CTextureCache::GetWrappedThumbURL(item->GetPath())); if (!thumb.empty()) object["thumbnail"] = thumb; } if (!object.isMember("thumbnail")) object["thumbnail"] = ""; } FillDetails(item.get(), item, validFields, object); if (item->HasVideoInfoTag()) FillDetails(item->GetVideoInfoTag(), item, validFields, object); if (item->HasMusicInfoTag()) FillDetails(item->GetMusicInfoTag(), item, validFields, object); if (item->HasPictureInfoTag()) FillDetails(item->GetPictureInfoTag(), item, validFields, object); object["label"] = item->GetLabel().c_str(); } else object = CVariant(CVariant::VariantTypeNull); if (resultname) { if (append) result[resultname].append(object); else result[resultname] = object; } }
void CFileItemHandler::FillDetails(ISerializable* info, CFileItemPtr item, const CVariant& fields, CVariant &result) { if (info == NULL || fields.size() == 0) return; CVariant serialization; info->Serialize(serialization); for (unsigned int i = 0; i < fields.size(); i++) { CStdString field = fields[i].asString(); if (item) { if (item->IsAlbum() && field.Equals("albumlabel")) field = "label"; if (item->IsAlbum()) { if (field == "label") { result["albumlabel"] = item->GetProperty("album_label"); continue; } /* This would break backwards compatibility to JSON-RPC API v4 if (item->HasProperty("album_" + field + "_array")) { result[field] = item->GetProperty("album_" + field + "_array"); continue; }*/ if (item->HasProperty("album_" + field)) { result[field] = item->GetProperty("album_" + field); continue; } } /* This would break backwards compatibility to JSON-RPC API v4 if (item->HasProperty("artist_" + field + "_array")) { result[field] = item->GetProperty("artist_" + field + "_array"); continue; }*/ if (item->HasProperty("artist_" + field)) { result[field] = item->GetProperty("artist_" + field); continue; } if (field == "fanart" && !item->HasPictureInfoTag()) { CStdString fanart; if (item->HasProperty("fanart_image")) fanart = item->GetProperty("fanart_image").asString(); if (fanart.empty()) fanart = item->GetCachedFanart(); if (!fanart.empty()) result["fanart"] = fanart.c_str(); continue; } if (item->HasVideoInfoTag() && item->GetVideoContentType() == VIDEODB_CONTENT_TVSHOWS) { if (item->GetVideoInfoTag()->m_iSeason < 0 && field == "season") { result[field] = (int)item->GetProperty("totalseasons").asInteger(); continue; } if (field == "watchedepisodes") { result[field] = (int)item->GetProperty("watchedepisodes").asInteger(); continue; } } if (field == "lastmodified" && item->m_dateTime.IsValid()) { result[field] = item->m_dateTime.GetAsLocalizedDateTime(); continue; } } if (serialization.isMember(field) && (!result.isMember(field) || result[field].empty())) result[field] = serialization[field]; } }
bool CFileItemHandler::GetField(const std::string &field, const CVariant &info, const CFileItemPtr &item, CVariant &result, bool &fetchedArt, CThumbLoader *thumbLoader /* = NULL */) { if (result.isMember(field) && !result[field].empty()) return true; // overwrite serialized values if (item) { if (field == "mimetype" && item->GetMimeType().empty()) { item->FillInMimeType(false); result[field] = item->GetMimeType(); return true; } } // check for serialized values if (info.isMember(field) && !info[field].isNull()) { result[field] = info[field]; return true; } // check if the field requires special handling if (item) { if (item->IsAlbum()) { if (field == "albumlabel") { result[field] = item->GetProperty("album_label"); return true; } if (item->HasProperty("album_" + field + "_array")) { result[field] = item->GetProperty("album_" + field + "_array"); return true; } if (item->HasProperty("album_" + field)) { result[field] = item->GetProperty("album_" + field); return true; } } if (item->HasProperty("artist_" + field + "_array")) { result[field] = item->GetProperty("artist_" + field + "_array"); return true; } if (item->HasProperty("artist_" + field)) { result[field] = item->GetProperty("artist_" + field); return true; } if (field == "art") { if (thumbLoader != NULL && item->GetArt().size() <= 0 && !fetchedArt && ((item->HasVideoInfoTag() && item->GetVideoInfoTag()->m_iDbId > -1) || (item->HasMusicInfoTag() && item->GetMusicInfoTag()->GetDatabaseId() > -1))) { thumbLoader->FillLibraryArt(*item); fetchedArt = true; } CGUIListItem::ArtMap artMap = item->GetArt(); CVariant artObj(CVariant::VariantTypeObject); for (CGUIListItem::ArtMap::const_iterator artIt = artMap.begin(); artIt != artMap.end(); ++artIt) { if (!artIt->second.empty()) artObj[artIt->first] = CTextureUtils::GetWrappedImageURL(artIt->second); } result["art"] = artObj; return true; } if (field == "thumbnail") { if (thumbLoader != NULL && !item->HasArt("thumb") && !fetchedArt && ((item->HasVideoInfoTag() && item->GetVideoInfoTag()->m_iDbId > -1) || (item->HasMusicInfoTag() && item->GetMusicInfoTag()->GetDatabaseId() > -1))) { thumbLoader->FillLibraryArt(*item); fetchedArt = true; } else if (item->HasPictureInfoTag() && !item->HasArt("thumb")) item->SetArt("thumb", CTextureUtils::GetWrappedThumbURL(item->GetPath())); if (item->HasArt("thumb")) result["thumbnail"] = CTextureUtils::GetWrappedImageURL(item->GetArt("thumb")); else result["thumbnail"] = ""; return true; } if (field == "fanart") { if (thumbLoader != NULL && !item->HasArt("fanart") && !fetchedArt && ((item->HasVideoInfoTag() && item->GetVideoInfoTag()->m_iDbId > -1) || (item->HasMusicInfoTag() && item->GetMusicInfoTag()->GetDatabaseId() > -1))) { thumbLoader->FillLibraryArt(*item); fetchedArt = true; } if (item->HasArt("fanart")) result["fanart"] = CTextureUtils::GetWrappedImageURL(item->GetArt("fanart")); else result["fanart"] = ""; return true; } if (item->HasVideoInfoTag() && item->GetVideoContentType() == VIDEODB_CONTENT_TVSHOWS) { if (item->GetVideoInfoTag()->m_iSeason < 0 && field == "season") { result[field] = (int)item->GetProperty("totalseasons").asInteger(); return true; } if (field == "watchedepisodes") { result[field] = (int)item->GetProperty("watchedepisodes").asInteger(); return true; } } if (field == "lastmodified" && item->m_dateTime.IsValid()) { result[field] = item->m_dateTime.GetAsLocalizedDateTime(); return true; } if (item->HasProperty(field)) { result[field] = item->GetProperty(field); return true; } } return false; }