| 1 | /* |
| 2 | * Copyright (C) 2012-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 "guilib/guiinfo/VideoGUIInfo.h" |
| 10 | |
| 11 | #include "FileItem.h" |
| 12 | #include "PlayListPlayer.h" |
| 13 | #include "ServiceBroker.h" |
| 14 | #include "URL.h" |
| 15 | #include "Util.h" |
| 16 | #include "application/Application.h" |
| 17 | #include "application/ApplicationComponents.h" |
| 18 | #include "application/ApplicationPlayer.h" |
| 19 | #include "cores/DataCacheCore.h" |
| 20 | #include "cores/VideoPlayer/VideoRenderers/BaseRenderer.h" |
| 21 | #include "guilib/GUIComponent.h" |
| 22 | #include "guilib/GUIWindowManager.h" |
| 23 | #include "guilib/LocalizeStrings.h" |
| 24 | #include "guilib/StereoscopicsManager.h" |
| 25 | #include "guilib/WindowIDs.h" |
| 26 | #include "guilib/guiinfo/GUIInfo.h" |
| 27 | #include "guilib/guiinfo/GUIInfoHelper.h" |
| 28 | #include "guilib/guiinfo/GUIInfoLabels.h" |
| 29 | #include "playlists/PlayList.h" |
| 30 | #include "settings/AdvancedSettings.h" |
| 31 | #include "settings/SettingUtils.h" |
| 32 | #include "settings/Settings.h" |
| 33 | #include "settings/SettingsComponent.h" |
| 34 | #include "settings/lib/Setting.h" |
| 35 | #include "utils/StringUtils.h" |
| 36 | #include "utils/URIUtils.h" |
| 37 | #include "utils/log.h" |
| 38 | #include "video/VideoInfoTag.h" |
| 39 | #include "video/VideoManagerTypes.h" |
| 40 | #include "video/VideoThumbLoader.h" |
| 41 | |
| 42 | #include <math.h> |
| 43 | |
| 44 | using namespace KODI::GUILIB; |
| 45 | using namespace KODI::GUILIB::GUIINFO; |
| 46 | |
| 47 | CVideoGUIInfo::CVideoGUIInfo() |
| 48 | : m_appPlayer(CServiceBroker::GetAppComponents().GetComponent<CApplicationPlayer>()) |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | int CVideoGUIInfo::GetPercentPlayed(const CVideoInfoTag* tag) const |
| 53 | { |
| 54 | CBookmark bookmark = tag->GetResumePoint(); |
| 55 | if (bookmark.IsPartWay()) |
| 56 | return std::lrintf(static_cast<float>(bookmark.timeInSeconds) / |
| 57 | static_cast<float>(bookmark.totalTimeInSeconds) * 100.0f); |
| 58 | else |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | bool CVideoGUIInfo::InitCurrentItem(CFileItem *item) |
| 63 | { |
| 64 | if (item && item->IsVideo()) |
| 65 | { |
| 66 | // special case where .strm is used to start an audio stream |
| 67 | if (item->IsInternetStream() && m_appPlayer->IsPlayingAudio()) |
| 68 | return false; |
| 69 | |
| 70 | CLog::Log(LOGDEBUG, "CVideoGUIInfo::InitCurrentItem({})", CURL::GetRedacted(item->GetPath())); |
| 71 | |
| 72 | // Find a thumb for this file. |
| 73 | if (!item->HasArt("thumb")) |
| 74 | { |
| 75 | CVideoThumbLoader loader; |
| 76 | loader.LoadItem(item); |
| 77 | } |
| 78 | |
| 79 | // find a thumb for this stream |
| 80 | if (item->IsInternetStream()) |
| 81 | { |
| 82 | if (!g_application.m_strPlayListFile.empty()) |
| 83 | { |
| 84 | CLog::Log(LOGDEBUG, "Streaming media detected... using {} to find a thumb", |
| 85 | g_application.m_strPlayListFile); |
| 86 | CFileItem thumbItem(g_application.m_strPlayListFile,false); |
| 87 | |
| 88 | CVideoThumbLoader loader; |
| 89 | if (loader.FillThumb(thumbItem)) |
| 90 | item->SetArt("thumb", thumbItem.GetArt("thumb")); |
| 91 | } |
| 92 | } |
| 93 | return true; |
| 94 | } |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | bool CVideoGUIInfo::GetLabel(std::string& value, const CFileItem *item, int contextWindow, const CGUIInfo &info, std::string *fallback) const |
| 99 | { |
| 100 | // For videoplayer "offset" and "position" info labels check playlist |
| 101 | if (info.GetData1() && ((info.m_info >= VIDEOPLAYER_OFFSET_POSITION_FIRST && |
| 102 | info.m_info <= VIDEOPLAYER_OFFSET_POSITION_LAST) || |
| 103 | (info.m_info >= PLAYER_OFFSET_POSITION_FIRST && info.m_info <= PLAYER_OFFSET_POSITION_LAST))) |
| 104 | return GetPlaylistInfo(value, info); |
| 105 | |
| 106 | const CVideoInfoTag* tag = item->GetVideoInfoTag(); |
| 107 | if (tag) |
| 108 | { |
| 109 | switch (info.m_info) |
| 110 | { |
| 111 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 112 | // PLAYER_* / VIDEOPLAYER_* / LISTITEM_* |
| 113 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 114 | case VIDEOPLAYER_ART: |
| 115 | value = item->GetArt(info.GetData3()); |
| 116 | return true; |
| 117 | case PLAYER_PATH: |
| 118 | case PLAYER_FILENAME: |
| 119 | case PLAYER_FILEPATH: |
| 120 | if (item->HasMusicInfoTag()) // special handling for music videos, which have both a videotag and a musictag |
| 121 | break; |
| 122 | |
| 123 | value = tag->m_strFileNameAndPath; |
| 124 | if (value.empty()) |
| 125 | value = item->GetPath(); |
| 126 | value = GUIINFO::GetFileInfoLabelValueFromPath(info.m_info, value); |
| 127 | return true; |
| 128 | case PLAYER_TITLE: |
| 129 | value = tag->m_strTitle; |
| 130 | return !value.empty(); |
| 131 | case VIDEOPLAYER_TITLE: |
| 132 | value = tag->m_strTitle; |
| 133 | return !value.empty(); |
| 134 | case LISTITEM_TITLE: |
| 135 | value = tag->m_strTitle; |
| 136 | return true; |
| 137 | case VIDEOPLAYER_ORIGINALTITLE: |
| 138 | case LISTITEM_ORIGINALTITLE: |
| 139 | value = tag->m_strOriginalTitle; |
| 140 | return true; |
| 141 | case VIDEOPLAYER_GENRE: |
| 142 | case LISTITEM_GENRE: |
| 143 | value = StringUtils::Join(tag->m_genre, CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_videoItemSeparator); |
| 144 | return true; |
| 145 | case VIDEOPLAYER_DIRECTOR: |
| 146 | case LISTITEM_DIRECTOR: |
| 147 | value = StringUtils::Join(tag->m_director, CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_videoItemSeparator); |
| 148 | return true; |
| 149 | case VIDEOPLAYER_IMDBNUMBER: |
| 150 | case LISTITEM_IMDBNUMBER: |
| 151 | value = tag->GetUniqueID(); |
| 152 | return true; |
| 153 | case VIDEOPLAYER_DBID: |
| 154 | case LISTITEM_DBID: |
| 155 | if (tag->m_iDbId > -1) |
| 156 | { |
| 157 | value = std::to_string(tag->m_iDbId); |
| 158 | return true; |
| 159 | } |
| 160 | break; |
| 161 | case VIDEOPLAYER_TVSHOWDBID: |
| 162 | case LISTITEM_TVSHOWDBID: |
| 163 | if (tag->m_iIdShow > -1) |
| 164 | { |
| 165 | value = std::to_string(tag->m_iIdShow); |
| 166 | return true; |
| 167 | } |
| 168 | break; |
| 169 | case VIDEOPLAYER_UNIQUEID: |
| 170 | case LISTITEM_UNIQUEID: |
| 171 | if (!info.GetData3().empty()) |
| 172 | value = tag->GetUniqueID(info.GetData3()); |
| 173 | return true; |
| 174 | case VIDEOPLAYER_RATING: |
| 175 | case LISTITEM_RATING: |
| 176 | { |
| 177 | float rating = tag->GetRating(info.GetData3()).rating; |
| 178 | if (rating > 0.f) |
| 179 | { |
| 180 | value = StringUtils::FormatNumber(rating); |
| 181 | return true; |
| 182 | } |
| 183 | break; |
| 184 | } |
| 185 | case VIDEOPLAYER_RATING_AND_VOTES: |
| 186 | case LISTITEM_RATING_AND_VOTES: |
| 187 | { |
| 188 | CRating rating = tag->GetRating(info.GetData3()); |
| 189 | if (rating.rating >= 0.f) |
| 190 | { |
| 191 | if (rating.rating > 0.f && rating.votes == 0) |
| 192 | value = StringUtils::FormatNumber(rating.rating); |
| 193 | else if (rating.votes > 0) |
| 194 | value = StringUtils::Format(g_localizeStrings.Get(20350), |
| 195 | StringUtils::FormatNumber(rating.rating), |
| 196 | StringUtils::FormatNumber(rating.votes)); |
| 197 | else |
| 198 | break; |
| 199 | return true; |
| 200 | } |
| 201 | break; |
| 202 | } |
| 203 | case VIDEOPLAYER_USER_RATING: |
| 204 | case LISTITEM_USER_RATING: |
| 205 | if (tag->m_iUserRating > 0) |
| 206 | { |
| 207 | value = std::to_string(tag->m_iUserRating); |
| 208 | return true; |
| 209 | } |
| 210 | break; |
| 211 | case VIDEOPLAYER_VOTES: |
| 212 | case LISTITEM_VOTES: |
| 213 | value = StringUtils::FormatNumber(tag->GetRating(info.GetData3()).votes); |
| 214 | return true; |
| 215 | case VIDEOPLAYER_YEAR: |
| 216 | case LISTITEM_YEAR: |
| 217 | if (tag->HasYear()) |
| 218 | { |
| 219 | value = std::to_string(tag->GetYear()); |
| 220 | return true; |
| 221 | } |
| 222 | break; |
| 223 | case VIDEOPLAYER_PREMIERED: |
| 224 | case LISTITEM_PREMIERED: |
| 225 | { |
| 226 | CDateTime dateTime; |
| 227 | if (tag->m_firstAired.IsValid()) |
| 228 | dateTime = tag->m_firstAired; |
| 229 | else if (tag->HasPremiered()) |
| 230 | dateTime = tag->GetPremiered(); |
| 231 | |
| 232 | if (dateTime.IsValid()) |
| 233 | { |
| 234 | value = dateTime.GetAsLocalizedDate(); |
| 235 | return true; |
| 236 | } |
| 237 | break; |
| 238 | } |
| 239 | case VIDEOPLAYER_PLOT: |
| 240 | value = tag->m_strPlot; |
| 241 | return true; |
| 242 | case VIDEOPLAYER_TRAILER: |
| 243 | case LISTITEM_TRAILER: |
| 244 | value = tag->m_strTrailer; |
| 245 | return true; |
| 246 | case VIDEOPLAYER_PLOT_OUTLINE: |
| 247 | case LISTITEM_PLOT_OUTLINE: |
| 248 | value = tag->m_strPlotOutline; |
| 249 | return true; |
| 250 | case VIDEOPLAYER_EPISODE: |
| 251 | case LISTITEM_EPISODE: |
| 252 | { |
| 253 | int iEpisode = -1; |
| 254 | if (tag->m_iEpisode > 0) |
| 255 | { |
| 256 | iEpisode = tag->m_iEpisode; |
| 257 | } |
| 258 | |
| 259 | if (iEpisode >= 0) |
| 260 | { |
| 261 | value = std::to_string(iEpisode); |
| 262 | return true; |
| 263 | } |
| 264 | break; |
| 265 | } |
| 266 | case VIDEOPLAYER_SEASON: |
| 267 | case LISTITEM_SEASON: |
| 268 | if (tag->m_iSeason >= 0) |
| 269 | { |
| 270 | value = std::to_string(tag->m_iSeason); |
| 271 | return true; |
| 272 | } |
| 273 | break; |
| 274 | case VIDEOPLAYER_TVSHOW: |
| 275 | case LISTITEM_TVSHOW: |
| 276 | value = tag->m_strShowTitle; |
| 277 | return true; |
| 278 | case VIDEOPLAYER_STUDIO: |
| 279 | case LISTITEM_STUDIO: |
| 280 | value = StringUtils::Join(tag->m_studio, CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_videoItemSeparator); |
| 281 | return true; |
| 282 | case VIDEOPLAYER_COUNTRY: |
| 283 | case LISTITEM_COUNTRY: |
| 284 | value = StringUtils::Join(tag->m_country, CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_videoItemSeparator); |
| 285 | return true; |
| 286 | case VIDEOPLAYER_MPAA: |
| 287 | case LISTITEM_MPAA: |
| 288 | value = tag->m_strMPAARating; |
| 289 | return true; |
| 290 | case VIDEOPLAYER_TOP250: |
| 291 | case LISTITEM_TOP250: |
| 292 | if (tag->m_iTop250 > 0) |
| 293 | { |
| 294 | value = std::to_string(tag->m_iTop250); |
| 295 | return true; |
| 296 | } |
| 297 | break; |
| 298 | case VIDEOPLAYER_CAST: |
| 299 | case LISTITEM_CAST: |
| 300 | value = tag->GetCast(); |
| 301 | return true; |
| 302 | case VIDEOPLAYER_CAST_AND_ROLE: |
| 303 | case LISTITEM_CAST_AND_ROLE: |
| 304 | value = tag->GetCast(true); |
| 305 | return true; |
| 306 | case VIDEOPLAYER_ARTIST: |
| 307 | case LISTITEM_ARTIST: |
| 308 | value = StringUtils::Join(tag->m_artist, CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_videoItemSeparator); |
| 309 | return true; |
| 310 | case VIDEOPLAYER_ALBUM: |
| 311 | case LISTITEM_ALBUM: |
| 312 | value = tag->m_strAlbum; |
| 313 | return true; |
| 314 | case VIDEOPLAYER_WRITER: |
| 315 | case LISTITEM_WRITER: |
| 316 | value = StringUtils::Join(tag->m_writingCredits, CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_videoItemSeparator); |
| 317 | return true; |
| 318 | case VIDEOPLAYER_TAGLINE: |
| 319 | case LISTITEM_TAGLINE: |
| 320 | value = tag->m_strTagLine; |
| 321 | return true; |
| 322 | case VIDEOPLAYER_VIDEOVERSION_NAME: |
| 323 | case LISTITEM_VIDEOVERSION_NAME: |
| 324 | value = tag->GetAssetInfo().GetType() == VideoAssetType::VERSION |
| 325 | ? tag->GetAssetInfo().GetTitle() |
| 326 | : ""; |
| 327 | return true; |
| 328 | case VIDEOPLAYER_LASTPLAYED: |
| 329 | case LISTITEM_LASTPLAYED: |
| 330 | { |
| 331 | const CDateTime dateTime = tag->m_lastPlayed; |
| 332 | if (dateTime.IsValid()) |
| 333 | { |
| 334 | value = dateTime.GetAsLocalizedDate(); |
| 335 | return true; |
| 336 | } |
| 337 | break; |
| 338 | } |
| 339 | case VIDEOPLAYER_PLAYCOUNT: |
| 340 | case LISTITEM_PLAYCOUNT: |
| 341 | if (tag->GetPlayCount() > 0) |
| 342 | { |
| 343 | value = std::to_string(tag->GetPlayCount()); |
| 344 | return true; |
| 345 | } |
| 346 | break; |
| 347 | |
| 348 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 349 | // LISTITEM_* |
| 350 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 351 | case LISTITEM_DURATION: |
| 352 | { |
| 353 | int iDuration = tag->GetDuration(); |
| 354 | if (iDuration > 0) |
| 355 | { |
| 356 | value = StringUtils::SecondsToTimeString(iDuration, static_cast<TIME_FORMAT>(info.GetData4())); |
| 357 | return true; |
| 358 | } |
| 359 | break; |
| 360 | } |
| 361 | case LISTITEM_TRACKNUMBER: |
| 362 | if (tag->m_iTrack > -1 ) |
| 363 | { |
| 364 | value = std::to_string(tag->m_iTrack); |
| 365 | return true; |
| 366 | } |
| 367 | break; |
| 368 | case LISTITEM_PLOT: |
| 369 | { |
| 370 | std::shared_ptr<CSettingList> setting(std::dynamic_pointer_cast<CSettingList>( |
| 371 | CServiceBroker::GetSettingsComponent()->GetSettings()->GetSetting( |
| 372 | CSettings::SETTING_VIDEOLIBRARY_SHOWUNWATCHEDPLOTS))); |
| 373 | if (tag->m_type != MediaTypeTvShow && tag->m_type != MediaTypeVideoCollection && |
| 374 | tag->GetPlayCount() == 0 && setting && |
| 375 | ((tag->m_type == MediaTypeMovie && |
| 376 | !CSettingUtils::FindIntInList( |
| 377 | setting, CSettings::VIDEOLIBRARY_PLOTS_SHOW_UNWATCHED_MOVIES)) || |
| 378 | (tag->m_type == MediaTypeEpisode && |
| 379 | !CSettingUtils::FindIntInList( |
| 380 | setting, CSettings::VIDEOLIBRARY_PLOTS_SHOW_UNWATCHED_TVSHOWEPISODES)))) |
| 381 | { |
| 382 | value = g_localizeStrings.Get(20370); |
| 383 | } |
| 384 | else |
| 385 | { |
| 386 | value = tag->m_strPlot; |
| 387 | } |
| 388 | return true; |
| 389 | } |
| 390 | case LISTITEM_STATUS: |
| 391 | value = tag->m_strStatus; |
| 392 | return true; |
| 393 | case LISTITEM_TAG: |
| 394 | value = StringUtils::Join(tag->m_tags, CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_videoItemSeparator); |
| 395 | return true; |
| 396 | case LISTITEM_SET: |
| 397 | value = tag->m_set.title; |
| 398 | return true; |
| 399 | case LISTITEM_SETID: |
| 400 | if (tag->m_set.id > 0) |
| 401 | { |
| 402 | value = std::to_string(tag->m_set.id); |
| 403 | return true; |
| 404 | } |
| 405 | break; |
| 406 | case LISTITEM_ENDTIME_RESUME: |
| 407 | { |
| 408 | const CDateTimeSpan duration(0, 0, 0, tag->GetDuration() - tag->GetResumePoint().timeInSeconds); |
| 409 | value = (CDateTime::GetCurrentDateTime() + duration).GetAsLocalizedTime("", false); |
| 410 | return true; |
| 411 | } |
| 412 | case LISTITEM_ENDTIME: |
| 413 | { |
| 414 | const CDateTimeSpan duration(0, 0, 0, tag->GetDuration()); |
| 415 | value = (CDateTime::GetCurrentDateTime() + duration).GetAsLocalizedTime("", false); |
| 416 | return true; |
| 417 | } |
| 418 | case LISTITEM_DATE_ADDED: |
| 419 | if (tag->m_dateAdded.IsValid()) |
| 420 | { |
| 421 | value = tag->m_dateAdded.GetAsLocalizedDate(); |
| 422 | return true; |
| 423 | } |
| 424 | break; |
| 425 | case LISTITEM_DBTYPE: |
| 426 | value = tag->m_type; |
| 427 | return true; |
| 428 | case LISTITEM_APPEARANCES: |
| 429 | if (tag->m_relevance > -1) |
| 430 | { |
| 431 | value = std::to_string(tag->m_relevance); |
| 432 | return true; |
| 433 | } |
| 434 | break; |
| 435 | case LISTITEM_PERCENT_PLAYED: |
| 436 | value = std::to_string(GetPercentPlayed(tag)); |
| 437 | return true; |
| 438 | case LISTITEM_VIDEO_CODEC: |
| 439 | value = tag->m_streamDetails.GetVideoCodec(); |
| 440 | return true; |
| 441 | case LISTITEM_VIDEO_RESOLUTION: |
| 442 | value = CStreamDetails::VideoDimsToResolutionDescription(tag->m_streamDetails.GetVideoWidth(), tag->m_streamDetails.GetVideoHeight()); |
| 443 | return true; |
| 444 | case LISTITEM_VIDEO_ASPECT: |
| 445 | value = CStreamDetails::VideoAspectToAspectDescription(tag->m_streamDetails.GetVideoAspect()); |
| 446 | return true; |
| 447 | case LISTITEM_VIDEO_WIDTH: |
| 448 | { |
| 449 | const int val = tag->m_streamDetails.GetVideoWidth(); |
| 450 | if (val > 0) |
| 451 | value = std::to_string(val); |
| 452 | return true; |
| 453 | } |
| 454 | case LISTITEM_VIDEO_HEIGHT: |
| 455 | { |
| 456 | const int val = tag->m_streamDetails.GetVideoHeight(); |
| 457 | if (val > 0) |
| 458 | value = std::to_string(val); |
| 459 | return true; |
| 460 | } |
| 461 | case LISTITEM_AUDIO_CODEC: |
| 462 | value = tag->m_streamDetails.GetAudioCodec(); |
| 463 | return true; |
| 464 | case LISTITEM_AUDIO_CHANNELS: |
| 465 | { |
| 466 | int iChannels = tag->m_streamDetails.GetAudioChannels(); |
| 467 | if (iChannels > 0) |
| 468 | { |
| 469 | value = std::to_string(iChannels); |
| 470 | return true; |
| 471 | } |
| 472 | break; |
| 473 | } |
| 474 | case LISTITEM_AUDIO_LANGUAGE: |
| 475 | value = tag->m_streamDetails.GetAudioLanguage(); |
| 476 | return true; |
| 477 | case LISTITEM_SUBTITLE_LANGUAGE: |
| 478 | value = tag->m_streamDetails.GetSubtitleLanguage(); |
| 479 | return true; |
| 480 | case LISTITEM_FILENAME: |
| 481 | case LISTITEM_FILE_EXTENSION: |
| 482 | if (item->IsVideoDb()) |
| 483 | value = URIUtils::GetFileName(tag->m_strFileNameAndPath); |
| 484 | else if (item->HasMusicInfoTag()) // special handling for music videos, which have both a videotag and a musictag |
| 485 | break; |
| 486 | else |
| 487 | value = URIUtils::GetFileName(item->GetPath()); |
| 488 | |
| 489 | if (info.m_info == LISTITEM_FILE_EXTENSION) |
| 490 | { |
| 491 | std::string strExtension = URIUtils::GetExtension(value); |
| 492 | value = StringUtils::TrimLeft(strExtension, "."); |
| 493 | } |
| 494 | return true; |
| 495 | case LISTITEM_FOLDERNAME: |
| 496 | case LISTITEM_PATH: |
| 497 | if (item->IsVideoDb()) |
| 498 | { |
| 499 | if (item->m_bIsFolder) |
| 500 | value = tag->m_strPath; |
| 501 | else |
| 502 | URIUtils::GetParentPath(tag->m_strFileNameAndPath, value); |
| 503 | } |
| 504 | else if (item->HasMusicInfoTag()) // special handling for music videos, which have both a videotag and a musictag |
| 505 | break; |
| 506 | else |
| 507 | URIUtils::GetParentPath(item->GetPath(), value); |
| 508 | |
| 509 | value = CURL(value).GetWithoutUserDetails(); |
| 510 | |
| 511 | if (info.m_info == LISTITEM_FOLDERNAME) |
| 512 | { |
| 513 | URIUtils::RemoveSlashAtEnd(value); |
| 514 | value = URIUtils::GetFileName(value); |
| 515 | } |
| 516 | return true; |
| 517 | case LISTITEM_FILENAME_AND_PATH: |
| 518 | if (item->IsVideoDb()) |
| 519 | value = tag->m_strFileNameAndPath; |
| 520 | else if (item->HasMusicInfoTag()) // special handling for music videos, which have both a videotag and a musictag |
| 521 | break; |
| 522 | else |
| 523 | value = item->GetPath(); |
| 524 | |
| 525 | value = CURL(value).GetWithoutUserDetails(); |
| 526 | return true; |
| 527 | case LISTITEM_VIDEO_HDR_TYPE: |
| 528 | value = tag->m_streamDetails.GetVideoHdrType(); |
| 529 | return true; |
| 530 | case LISTITEM_LABEL: |
| 531 | { |
| 532 | //! @todo get rid of "videos with versions as folder" hack! |
| 533 | |
| 534 | // special casing for "show videos with multiple versions as folders", where the label |
| 535 | // should be the video version, not the movie title. |
| 536 | if (!item->HasVideoVersions()) |
| 537 | break; |
| 538 | |
| 539 | CGUIWindow* videoNav{ |
| 540 | CServiceBroker::GetGUI()->GetWindowManager().GetWindow(WINDOW_VIDEO_NAV)}; |
| 541 | if (videoNav && videoNav->GetProperty("VideoVersionsFolderView").asBoolean() && |
| 542 | videoNav->IsActive()) |
| 543 | { |
| 544 | value = tag->GetAssetInfo().GetTitle(); |
| 545 | return true; |
| 546 | } |
| 547 | break; |
| 548 | } |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | switch (info.m_info) |
| 553 | { |
| 554 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 555 | // VIDEOPLAYER_* |
| 556 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 557 | case VIDEOPLAYER_PLAYLISTLEN: |
| 558 | if (CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() == PLAYLIST::TYPE_VIDEO) |
| 559 | { |
| 560 | value = GUIINFO::GetPlaylistLabel(PLAYLIST_LENGTH); |
| 561 | return true; |
| 562 | } |
| 563 | break; |
| 564 | case VIDEOPLAYER_PLAYLISTPOS: |
| 565 | if (CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() == PLAYLIST::TYPE_VIDEO) |
| 566 | { |
| 567 | value = GUIINFO::GetPlaylistLabel(PLAYLIST_POSITION); |
| 568 | return true; |
| 569 | } |
| 570 | break; |
| 571 | case VIDEOPLAYER_VIDEO_ASPECT: |
| 572 | value = CStreamDetails::VideoAspectToAspectDescription(CServiceBroker::GetDataCacheCore().GetVideoDAR()); |
| 573 | return true; |
| 574 | case VIDEOPLAYER_STEREOSCOPIC_MODE: |
| 575 | value = CServiceBroker::GetDataCacheCore().GetVideoStereoMode(); |
| 576 | return true; |
| 577 | case VIDEOPLAYER_SUBTITLES_LANG: |
| 578 | value = m_subtitleInfo.language; |
| 579 | return true; |
| 580 | break; |
| 581 | case VIDEOPLAYER_COVER: |
| 582 | if (m_appPlayer->IsPlayingVideo()) |
| 583 | { |
| 584 | if (fallback) |
| 585 | *fallback = "DefaultVideoCover.png"; |
| 586 | |
| 587 | value = item->HasArt("thumb") ? item->GetArt("thumb") : "DefaultVideoCover.png"; |
| 588 | return true; |
| 589 | } |
| 590 | break; |
| 591 | |
| 592 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 593 | // LISTITEM_* |
| 594 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 595 | case LISTITEM_STEREOSCOPIC_MODE: |
| 596 | value = item->GetProperty("stereomode").asString(); |
| 597 | if (value.empty() && tag) |
| 598 | value = CStereoscopicsManager::NormalizeStereoMode(tag->m_streamDetails.GetStereoMode()); |
| 599 | return true; |
| 600 | |
| 601 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 602 | // VIDEOPLAYER_* |
| 603 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 604 | case VIDEOPLAYER_VIDEO_CODEC: |
| 605 | value = m_videoInfo.codecName; |
| 606 | return true; |
| 607 | case VIDEOPLAYER_VIDEO_RESOLUTION: |
| 608 | value = CStreamDetails::VideoDimsToResolutionDescription(m_videoInfo.width, m_videoInfo.height); |
| 609 | return true; |
| 610 | case VIDEOPLAYER_HDR_TYPE: |
| 611 | value = CStreamDetails::HdrTypeToString(m_videoInfo.hdrType); |
| 612 | return true; |
| 613 | case VIDEOPLAYER_AUDIO_CODEC: |
| 614 | value = m_audioInfo.codecName; |
| 615 | return true; |
| 616 | case VIDEOPLAYER_AUDIO_CHANNELS: |
| 617 | { |
| 618 | int iChannels = m_audioInfo.channels; |
| 619 | if (iChannels > 0) |
| 620 | { |
| 621 | value = std::to_string(iChannels); |
| 622 | return true; |
| 623 | } |
| 624 | break; |
| 625 | } |
| 626 | case VIDEOPLAYER_AUDIO_BITRATE: |
| 627 | { |
| 628 | int iBitrate = m_audioInfo.bitrate; |
| 629 | if (iBitrate > 0) |
| 630 | { |
| 631 | value = std::to_string(std::lrint(static_cast<double>(iBitrate) / 1000.0)); |
| 632 | return true; |
| 633 | } |
| 634 | break; |
| 635 | } |
| 636 | case VIDEOPLAYER_VIDEO_BITRATE: |
| 637 | { |
| 638 | int iBitrate = m_videoInfo.bitrate; |
| 639 | if (iBitrate > 0) |
| 640 | { |
| 641 | value = std::to_string(std::lrint(static_cast<double>(iBitrate) / 1000.0)); |
| 642 | return true; |
| 643 | } |
| 644 | break; |
| 645 | } |
| 646 | case VIDEOPLAYER_AUDIO_LANG: |
| 647 | value = m_audioInfo.language; |
| 648 | return true; |
| 649 | } |
| 650 | |
| 651 | return false; |
| 652 | } |
| 653 | |
| 654 | bool CVideoGUIInfo::GetPlaylistInfo(std::string& value, const CGUIInfo& info) const |
| 655 | { |
| 656 | const PLAYLIST::CPlayList& playlist = |
| 657 | CServiceBroker::GetPlaylistPlayer().GetPlaylist(PLAYLIST::TYPE_VIDEO); |
| 658 | if (playlist.size() < 1) |
| 659 | return false; |
| 660 | |
| 661 | int index = info.GetData2(); |
| 662 | if (info.GetData1() == 1) |
| 663 | { // relative index (requires current playlist is TYPE_VIDEO) |
| 664 | if (CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() != PLAYLIST::TYPE_VIDEO) |
| 665 | return false; |
| 666 | |
| 667 | index = CServiceBroker::GetPlaylistPlayer().GetNextItemIdx(index); |
| 668 | } |
| 669 | |
| 670 | if (index < 0 || index >= playlist.size()) |
| 671 | return false; |
| 672 | |
| 673 | const CFileItemPtr playlistItem = playlist[index]; |
| 674 | // try to set a thumbnail |
| 675 | if (!playlistItem->HasArt("thumb")) |
| 676 | { |
| 677 | CVideoThumbLoader loader; |
| 678 | loader.LoadItem(playlistItem.get()); |
| 679 | // still no thumb? then just the set the default cover |
| 680 | if (!playlistItem->HasArt("thumb")) |
| 681 | playlistItem->SetArt("thumb", "DefaultVideoCover.png"); |
| 682 | } |
| 683 | if (info.m_info == VIDEOPLAYER_PLAYLISTPOS) |
| 684 | { |
| 685 | value = std::to_string(index + 1); |
| 686 | return true; |
| 687 | } |
| 688 | else if (info.m_info == VIDEOPLAYER_COVER) |
| 689 | { |
| 690 | value = playlistItem->GetArt("thumb"); |
| 691 | return true; |
| 692 | } |
| 693 | else if (info.m_info == VIDEOPLAYER_ART) |
| 694 | { |
| 695 | value = playlistItem->GetArt(info.GetData3()); |
| 696 | return true; |
| 697 | } |
| 698 | |
| 699 | return GetLabel(value, playlistItem.get(), 0, CGUIInfo(info.m_info), nullptr); |
| 700 | } |
| 701 | |
| 702 | bool CVideoGUIInfo::GetFallbackLabel(std::string& value, |
| 703 | const CFileItem* item, |
| 704 | int contextWindow, |
| 705 | const CGUIInfo& info, |
| 706 | std::string* fallback) |
| 707 | { |
| 708 | // No fallback for videoplayer "offset" and "position" info labels |
| 709 | if (info.GetData1() && ((info.m_info >= VIDEOPLAYER_OFFSET_POSITION_FIRST && |
| 710 | info.m_info <= VIDEOPLAYER_OFFSET_POSITION_LAST) || |
| 711 | (info.m_info >= PLAYER_OFFSET_POSITION_FIRST && info.m_info <= PLAYER_OFFSET_POSITION_LAST))) |
| 712 | return false; |
| 713 | |
| 714 | const CVideoInfoTag* tag = item->GetVideoInfoTag(); |
| 715 | if (tag) |
| 716 | { |
| 717 | switch (info.m_info) |
| 718 | { |
| 719 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 720 | // VIDEOPLAYER_* |
| 721 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 722 | case VIDEOPLAYER_TITLE: |
| 723 | value = item->GetLabel(); |
| 724 | if (value.empty()) |
| 725 | value = CUtil::GetTitleFromPath(item->GetPath()); |
| 726 | return true; |
| 727 | default: |
| 728 | break; |
| 729 | } |
| 730 | } |
| 731 | return false; |
| 732 | } |
| 733 | |
| 734 | bool CVideoGUIInfo::GetInt(int& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const |
| 735 | { |
| 736 | if (!gitem->IsFileItem()) |
| 737 | return false; |
| 738 | |
| 739 | const CFileItem *item = static_cast<const CFileItem*>(gitem); |
| 740 | const CVideoInfoTag* tag = item->GetVideoInfoTag(); |
| 741 | if (tag) |
| 742 | { |
| 743 | switch (info.m_info) |
| 744 | { |
| 745 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 746 | // LISTITEM_* |
| 747 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 748 | case LISTITEM_PERCENT_PLAYED: |
| 749 | value = GetPercentPlayed(tag); |
| 750 | return true; |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | switch (info.m_info) |
| 755 | { |
| 756 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 757 | // VIDEOPLAYER_* |
| 758 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 759 | case VIDEOPLAYER_AUDIOSTREAMCOUNT: |
| 760 | value = m_appPlayer->GetAudioStreamCount(); |
| 761 | return true; |
| 762 | |
| 763 | default: |
| 764 | break; |
| 765 | } |
| 766 | |
| 767 | return false; |
| 768 | } |
| 769 | |
| 770 | bool CVideoGUIInfo::GetBool(bool& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const |
| 771 | { |
| 772 | if (!gitem->IsFileItem()) |
| 773 | return false; |
| 774 | |
| 775 | const CFileItem *item = static_cast<const CFileItem*>(gitem); |
| 776 | const CVideoInfoTag* tag = item->GetVideoInfoTag(); |
| 777 | if (tag) |
| 778 | { |
| 779 | switch (info.m_info) |
| 780 | { |
| 781 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 782 | // VIDEOPLAYER_* |
| 783 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 784 | case VIDEOPLAYER_HAS_INFO: |
| 785 | value = !tag->IsEmpty(); |
| 786 | return true; |
| 787 | case VIDEOPLAYER_HAS_VIDEOVERSIONS: |
| 788 | case LISTITEM_HASVIDEOVERSIONS: |
| 789 | value = tag->HasVideoVersions(); |
| 790 | return true; |
| 791 | |
| 792 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 793 | // LISTITEM_* |
| 794 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 795 | case LISTITEM_IS_COLLECTION: |
| 796 | value = tag->m_type == MediaTypeVideoCollection; |
| 797 | return true; |
| 798 | case LISTITEM_ISVIDEOEXTRA: |
| 799 | value = (tag->GetAssetInfo().GetType() == VideoAssetType::EXTRA); |
| 800 | return true; |
| 801 | case LISTITEM_HASVIDEOEXTRAS: |
| 802 | value = tag->HasVideoExtras(); |
| 803 | return true; |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | switch (info.m_info) |
| 808 | { |
| 809 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 810 | // VIDEOPLAYER_* |
| 811 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 812 | case VIDEOPLAYER_CONTENT: |
| 813 | { |
| 814 | std::string strContent = "files"; |
| 815 | if (tag) |
| 816 | { |
| 817 | if (tag->m_type == MediaTypeMovie) |
| 818 | strContent = "movies"; |
| 819 | else if (tag->m_type == MediaTypeEpisode) |
| 820 | strContent = "episodes"; |
| 821 | else if (tag->m_type == MediaTypeMusicVideo) |
| 822 | strContent = "musicvideos"; |
| 823 | } |
| 824 | value = StringUtils::EqualsNoCase(info.GetData3(), strContent); |
| 825 | return value; // if no match for this provider, other providers shall be asked. |
| 826 | } |
| 827 | case VIDEOPLAYER_USING_OVERLAYS: |
| 828 | value = (CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_VIDEOPLAYER_RENDERMETHOD) == RENDER_OVERLAYS); |
| 829 | return true; |
| 830 | case VIDEOPLAYER_ISFULLSCREEN: |
| 831 | value = CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow() == WINDOW_FULLSCREEN_VIDEO || |
| 832 | CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow() == WINDOW_FULLSCREEN_GAME; |
| 833 | return true; |
| 834 | case VIDEOPLAYER_HASMENU: |
| 835 | value = m_appPlayer->GetSupportedMenuType() != MenuType::NONE; |
| 836 | return true; |
| 837 | case VIDEOPLAYER_HASTELETEXT: |
| 838 | value = m_appPlayer->HasTeletextCache(); |
| 839 | return true; |
| 840 | case VIDEOPLAYER_HASSUBTITLES: |
| 841 | value = m_appPlayer->GetSubtitleCount() > 0; |
| 842 | return true; |
| 843 | case VIDEOPLAYER_SUBTITLESENABLED: |
| 844 | value = m_appPlayer->GetSubtitleVisible(); |
| 845 | return true; |
| 846 | case VIDEOPLAYER_IS_STEREOSCOPIC: |
| 847 | value = !CServiceBroker::GetDataCacheCore().GetVideoStereoMode().empty(); |
| 848 | return true; |
| 849 | |
| 850 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 851 | // LISTITEM_* |
| 852 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 853 | case LISTITEM_IS_RESUMABLE: |
| 854 | value = item->IsResumable(); |
| 855 | return true; |
| 856 | case LISTITEM_IS_STEREOSCOPIC: |
| 857 | { |
| 858 | std::string stereoMode = item->GetProperty("stereomode").asString(); |
| 859 | if (stereoMode.empty() && tag) |
| 860 | stereoMode = CStereoscopicsManager::NormalizeStereoMode(tag->m_streamDetails.GetStereoMode()); |
| 861 | if (!stereoMode.empty() && stereoMode != "mono") |
| 862 | value = true; |
| 863 | return true; |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | return false; |
| 868 | } |