| 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/MusicGUIInfo.h" |
| 10 | |
| 11 | #include "FileItem.h" |
| 12 | #include "PartyModeManager.h" |
| 13 | #include "PlayListPlayer.h" |
| 14 | #include "ServiceBroker.h" |
| 15 | #include "URL.h" |
| 16 | #include "Util.h" |
| 17 | #include "application/Application.h" |
| 18 | #include "application/ApplicationComponents.h" |
| 19 | #include "application/ApplicationPlayer.h" |
| 20 | #include "guilib/LocalizeStrings.h" |
| 21 | #include "guilib/guiinfo/GUIInfo.h" |
| 22 | #include "guilib/guiinfo/GUIInfoHelper.h" |
| 23 | #include "guilib/guiinfo/GUIInfoLabels.h" |
| 24 | #include "music/MusicInfoLoader.h" |
| 25 | #include "music/MusicThumbLoader.h" |
| 26 | #include "music/tags/MusicInfoTag.h" |
| 27 | #include "playlists/PlayList.h" |
| 28 | #include "settings/AdvancedSettings.h" |
| 29 | #include "settings/SettingsComponent.h" |
| 30 | #include "utils/URIUtils.h" |
| 31 | #include "utils/log.h" |
| 32 | |
| 33 | using namespace KODI::GUILIB; |
| 34 | using namespace KODI::GUILIB::GUIINFO; |
| 35 | using namespace MUSIC_INFO; |
| 36 | |
| 37 | bool CMusicGUIInfo::InitCurrentItem(CFileItem *item) |
| 38 | { |
| 39 | const auto& components = CServiceBroker::GetAppComponents(); |
| 40 | const auto appPlayer = components.GetComponent<CApplicationPlayer>(); |
| 41 | if (item && (item->IsAudio() || (item->IsInternetStream() && appPlayer->IsPlayingAudio()))) |
| 42 | { |
| 43 | CLog::Log(LOGDEBUG, "CMusicGUIInfo::InitCurrentItem({})", item->GetPath()); |
| 44 | |
| 45 | item->LoadMusicTag(); |
| 46 | |
| 47 | CMusicInfoTag* tag = item->GetMusicInfoTag(); // creates item if not yet set, so no nullptr checks needed |
| 48 | tag->SetLoaded(true); |
| 49 | |
| 50 | // find a thumb for this file. |
| 51 | if (item->IsInternetStream() && !item->IsMusicDb()) |
| 52 | { |
| 53 | if (!g_application.m_strPlayListFile.empty()) |
| 54 | { |
| 55 | CLog::Log(LOGDEBUG, "Streaming media detected... using {} to find a thumb", |
| 56 | g_application.m_strPlayListFile); |
| 57 | CFileItem streamingItem(g_application.m_strPlayListFile,false); |
| 58 | |
| 59 | CMusicThumbLoader loader; |
| 60 | loader.FillThumb(streamingItem); |
| 61 | if (streamingItem.HasArt("thumb")) |
| 62 | item->SetArt("thumb", streamingItem.GetArt("thumb")); |
| 63 | } |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | CMusicThumbLoader loader; |
| 68 | loader.LoadItem(item); |
| 69 | } |
| 70 | |
| 71 | CMusicInfoLoader::LoadAdditionalTagInfo(item); |
| 72 | return true; |
| 73 | } |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | bool CMusicGUIInfo::GetLabel(std::string& value, const CFileItem *item, int contextWindow, const CGUIInfo &info, std::string *fallback) const |
| 78 | { |
| 79 | // For musicplayer "offset" and "position" info labels check playlist |
| 80 | if (info.GetData1() && ((info.m_info >= MUSICPLAYER_OFFSET_POSITION_FIRST && |
| 81 | info.m_info <= MUSICPLAYER_OFFSET_POSITION_LAST) || |
| 82 | (info.m_info >= PLAYER_OFFSET_POSITION_FIRST && info.m_info <= PLAYER_OFFSET_POSITION_LAST))) |
| 83 | return GetPlaylistInfo(value, info); |
| 84 | |
| 85 | const CMusicInfoTag* tag = item->GetMusicInfoTag(); |
| 86 | if (tag) |
| 87 | { |
| 88 | switch (info.m_info) |
| 89 | { |
| 90 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 91 | // PLAYER_* / MUSICPLAYER_* / LISTITEM_* |
| 92 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 93 | case PLAYER_PATH: |
| 94 | case PLAYER_FILENAME: |
| 95 | case PLAYER_FILEPATH: |
| 96 | value = tag->GetURL(); |
| 97 | if (value.empty()) |
| 98 | value = item->GetPath(); |
| 99 | value = GUIINFO::GetFileInfoLabelValueFromPath(info.m_info, value); |
| 100 | return true; |
| 101 | case PLAYER_TITLE: |
| 102 | value = tag->GetTitle(); |
| 103 | return !value.empty(); |
| 104 | case MUSICPLAYER_TITLE: |
| 105 | value = tag->GetTitle(); |
| 106 | return !value.empty(); |
| 107 | case LISTITEM_TITLE: |
| 108 | value = tag->GetTitle(); |
| 109 | return true; |
| 110 | case MUSICPLAYER_PLAYCOUNT: |
| 111 | case LISTITEM_PLAYCOUNT: |
| 112 | if (tag->GetPlayCount() > 0) |
| 113 | { |
| 114 | value = std::to_string(tag->GetPlayCount()); |
| 115 | return true; |
| 116 | } |
| 117 | break; |
| 118 | case MUSICPLAYER_LASTPLAYED: |
| 119 | case LISTITEM_LASTPLAYED: |
| 120 | { |
| 121 | const CDateTime& dateTime = tag->GetLastPlayed(); |
| 122 | if (dateTime.IsValid()) |
| 123 | { |
| 124 | value = dateTime.GetAsLocalizedDate(); |
| 125 | return true; |
| 126 | } |
| 127 | break; |
| 128 | } |
| 129 | case MUSICPLAYER_TRACK_NUMBER: |
| 130 | case LISTITEM_TRACKNUMBER: |
| 131 | if (tag->Loaded() && tag->GetTrackNumber() > 0) |
| 132 | { |
| 133 | value = StringUtils::Format("{:02}", tag->GetTrackNumber()); |
| 134 | return true; |
| 135 | } |
| 136 | break; |
| 137 | case MUSICPLAYER_DISC_NUMBER: |
| 138 | case LISTITEM_DISC_NUMBER: |
| 139 | if (tag->GetDiscNumber() > 0) |
| 140 | { |
| 141 | value = std::to_string(tag->GetDiscNumber()); |
| 142 | return true; |
| 143 | } |
| 144 | break; |
| 145 | case MUSICPLAYER_TOTALDISCS: |
| 146 | case LISTITEM_TOTALDISCS: |
| 147 | value = std::to_string(tag->GetTotalDiscs()); |
| 148 | return true; |
| 149 | case MUSICPLAYER_DISC_TITLE: |
| 150 | case LISTITEM_DISC_TITLE: |
| 151 | value = tag->GetDiscSubtitle(); |
| 152 | return true; |
| 153 | case MUSICPLAYER_ARTIST: |
| 154 | case LISTITEM_ARTIST: |
| 155 | value = tag->GetArtistString(); |
| 156 | return true; |
| 157 | case MUSICPLAYER_ALBUM_ARTIST: |
| 158 | case LISTITEM_ALBUM_ARTIST: |
| 159 | value = tag->GetAlbumArtistString(); |
| 160 | return true; |
| 161 | case MUSICPLAYER_CONTRIBUTORS: |
| 162 | case LISTITEM_CONTRIBUTORS: |
| 163 | if (tag->HasContributors()) |
| 164 | { |
| 165 | value = tag->GetContributorsText(); |
| 166 | return true; |
| 167 | } |
| 168 | break; |
| 169 | case MUSICPLAYER_CONTRIBUTOR_AND_ROLE: |
| 170 | case LISTITEM_CONTRIBUTOR_AND_ROLE: |
| 171 | if (tag->HasContributors()) |
| 172 | { |
| 173 | value = tag->GetContributorsAndRolesText(); |
| 174 | return true; |
| 175 | } |
| 176 | break; |
| 177 | case MUSICPLAYER_ALBUM: |
| 178 | case LISTITEM_ALBUM: |
| 179 | value = tag->GetAlbum(); |
| 180 | return true; |
| 181 | case MUSICPLAYER_YEAR: |
| 182 | case LISTITEM_YEAR: |
| 183 | value = tag->GetYearString(); |
| 184 | return true; |
| 185 | case MUSICPLAYER_GENRE: |
| 186 | case LISTITEM_GENRE: |
| 187 | value = StringUtils::Join(tag->GetGenre(), CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_musicItemSeparator); |
| 188 | return true; |
| 189 | case MUSICPLAYER_LYRICS: |
| 190 | value = tag->GetLyrics(); |
| 191 | return true; |
| 192 | case MUSICPLAYER_RATING: |
| 193 | case LISTITEM_RATING: |
| 194 | { |
| 195 | float rating = tag->GetRating(); |
| 196 | if (rating > 0.f) |
| 197 | { |
| 198 | value = StringUtils::FormatNumber(rating); |
| 199 | return true; |
| 200 | } |
| 201 | break; |
| 202 | } |
| 203 | case MUSICPLAYER_RATING_AND_VOTES: |
| 204 | case LISTITEM_RATING_AND_VOTES: |
| 205 | { |
| 206 | float rating = tag->GetRating(); |
| 207 | if (rating > 0.f) |
| 208 | { |
| 209 | int votes = tag->GetVotes(); |
| 210 | if (votes <= 0) |
| 211 | value = StringUtils::FormatNumber(rating); |
| 212 | else |
| 213 | value = |
| 214 | StringUtils::Format(g_localizeStrings.Get(20350), StringUtils::FormatNumber(rating), |
| 215 | StringUtils::FormatNumber(votes)); |
| 216 | return true; |
| 217 | } |
| 218 | break; |
| 219 | } |
| 220 | case MUSICPLAYER_USER_RATING: |
| 221 | case LISTITEM_USER_RATING: |
| 222 | if (tag->GetUserrating() > 0) |
| 223 | { |
| 224 | value = std::to_string(tag->GetUserrating()); |
| 225 | return true; |
| 226 | } |
| 227 | break; |
| 228 | case MUSICPLAYER_COMMENT: |
| 229 | case LISTITEM_COMMENT: |
| 230 | value = tag->GetComment(); |
| 231 | return true; |
| 232 | case MUSICPLAYER_MOOD: |
| 233 | case LISTITEM_MOOD: |
| 234 | value = tag->GetMood(); |
| 235 | return true; |
| 236 | case LISTITEM_DBTYPE: |
| 237 | value = tag->GetType(); |
| 238 | return true; |
| 239 | case MUSICPLAYER_DBID: |
| 240 | case LISTITEM_DBID: |
| 241 | { |
| 242 | int dbId = tag->GetDatabaseId(); |
| 243 | if (dbId > -1) |
| 244 | { |
| 245 | value = std::to_string(dbId); |
| 246 | return true; |
| 247 | } |
| 248 | break; |
| 249 | } |
| 250 | case PLAYER_DURATION: |
| 251 | { |
| 252 | const auto& components = CServiceBroker::GetAppComponents(); |
| 253 | const auto appPlayer = components.GetComponent<CApplicationPlayer>(); |
| 254 | if (!appPlayer->IsPlayingAudio()) |
| 255 | break; |
| 256 | } |
| 257 | [[fallthrough]]; |
| 258 | case MUSICPLAYER_DURATION: |
| 259 | case LISTITEM_DURATION: |
| 260 | { |
| 261 | int iDuration = tag->GetDuration(); |
| 262 | if (iDuration > 0) |
| 263 | { |
| 264 | value = StringUtils::SecondsToTimeString(iDuration, |
| 265 | static_cast<TIME_FORMAT>(info.m_info == LISTITEM_DURATION |
| 266 | ? info.GetData4() |
| 267 | : info.GetData1())); |
| 268 | return true; |
| 269 | } |
| 270 | break; |
| 271 | } |
| 272 | case MUSICPLAYER_BPM: |
| 273 | case LISTITEM_BPM: |
| 274 | if (tag->GetBPM() > 0) |
| 275 | { |
| 276 | value = std::to_string(tag->GetBPM()); |
| 277 | return true; |
| 278 | } |
| 279 | break; |
| 280 | case MUSICPLAYER_STATIONNAME: |
| 281 | // This property can be used for example by addons to enforce/override the station name. |
| 282 | value = item->GetProperty("StationName").asString(); |
| 283 | if (value.empty()) |
| 284 | value = tag->GetStationName(); |
| 285 | return true; |
| 286 | |
| 287 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 288 | // LISTITEM_* |
| 289 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 290 | case LISTITEM_PROPERTY: |
| 291 | if (StringUtils::StartsWithNoCase(info.GetData3(), "Role.")) |
| 292 | { |
| 293 | // "Role.xxxx" properties are held in music tag |
| 294 | std::string property = info.GetData3(); |
| 295 | property.erase(0, 5); //Remove Role. |
| 296 | value = tag->GetArtistStringForRole(property); |
| 297 | return true; |
| 298 | } |
| 299 | break; |
| 300 | case LISTITEM_VOTES: |
| 301 | value = StringUtils::FormatNumber(tag->GetVotes()); |
| 302 | return true; |
| 303 | case MUSICPLAYER_ORIGINALDATE: |
| 304 | case LISTITEM_ORIGINALDATE: |
| 305 | { |
| 306 | value = tag->GetOriginalDate(); |
| 307 | if (!CServiceBroker::GetSettingsComponent() |
| 308 | ->GetAdvancedSettings() |
| 309 | ->m_bMusicLibraryUseISODates) |
| 310 | value = StringUtils::ISODateToLocalizedDate(value); |
| 311 | return true; |
| 312 | } |
| 313 | case MUSICPLAYER_RELEASEDATE: |
| 314 | case LISTITEM_RELEASEDATE: |
| 315 | { |
| 316 | value = tag->GetReleaseDate(); |
| 317 | if (!CServiceBroker::GetSettingsComponent() |
| 318 | ->GetAdvancedSettings() |
| 319 | ->m_bMusicLibraryUseISODates) |
| 320 | value = StringUtils::ISODateToLocalizedDate(value); |
| 321 | return true; |
| 322 | } |
| 323 | break; |
| 324 | case LISTITEM_BITRATE: |
| 325 | { |
| 326 | int BitRate = tag->GetBitRate(); |
| 327 | if (BitRate > 0) |
| 328 | { |
| 329 | value = std::to_string(BitRate); |
| 330 | return true; |
| 331 | } |
| 332 | break; |
| 333 | } |
| 334 | case LISTITEM_SAMPLERATE: |
| 335 | { |
| 336 | int sampleRate = tag->GetSampleRate(); |
| 337 | if (sampleRate > 0) |
| 338 | { |
| 339 | value = StringUtils::Format("{:.5}", static_cast<double>(sampleRate) / 1000.0); |
| 340 | return true; |
| 341 | } |
| 342 | break; |
| 343 | } |
| 344 | case LISTITEM_MUSICCHANNELS: |
| 345 | { |
| 346 | int channels = tag->GetNoOfChannels(); |
| 347 | if (channels > 0) |
| 348 | { |
| 349 | value = std::to_string(channels); |
| 350 | return true; |
| 351 | } |
| 352 | break; |
| 353 | } |
| 354 | case LISTITEM_ALBUMSTATUS: |
| 355 | value = tag->GetAlbumReleaseStatus(); |
| 356 | return true; |
| 357 | case LISTITEM_FILENAME: |
| 358 | case LISTITEM_FILE_EXTENSION: |
| 359 | if (item->IsMusicDb()) |
| 360 | value = URIUtils::GetFileName(tag->GetURL()); |
| 361 | else if (item->HasVideoInfoTag()) // special handling for music videos, which have both a videotag and a musictag |
| 362 | break; |
| 363 | else |
| 364 | value = URIUtils::GetFileName(item->GetPath()); |
| 365 | |
| 366 | if (info.m_info == LISTITEM_FILE_EXTENSION) |
| 367 | { |
| 368 | std::string strExtension = URIUtils::GetExtension(value); |
| 369 | value = StringUtils::TrimLeft(strExtension, "."); |
| 370 | } |
| 371 | return true; |
| 372 | case LISTITEM_FOLDERNAME: |
| 373 | case LISTITEM_PATH: |
| 374 | if (item->IsMusicDb()) |
| 375 | value = URIUtils::GetDirectory(tag->GetURL()); |
| 376 | else if (item->HasVideoInfoTag()) // special handling for music videos, which have both a videotag and a musictag |
| 377 | break; |
| 378 | else |
| 379 | URIUtils::GetParentPath(item->GetPath(), value); |
| 380 | |
| 381 | value = CURL(value).GetWithoutUserDetails(); |
| 382 | |
| 383 | if (info.m_info == LISTITEM_FOLDERNAME) |
| 384 | { |
| 385 | URIUtils::RemoveSlashAtEnd(value); |
| 386 | value = URIUtils::GetFileName(value); |
| 387 | } |
| 388 | return true; |
| 389 | case LISTITEM_FILENAME_AND_PATH: |
| 390 | if (item->IsMusicDb()) |
| 391 | value = tag->GetURL(); |
| 392 | else if (item->HasVideoInfoTag()) // special handling for music videos, which have both a videotag and a musictag |
| 393 | break; |
| 394 | else |
| 395 | value = item->GetPath(); |
| 396 | |
| 397 | value = CURL(value).GetWithoutUserDetails(); |
| 398 | return true; |
| 399 | case LISTITEM_DATE_ADDED: |
| 400 | if (tag->GetDateAdded().IsValid()) |
| 401 | { |
| 402 | value = tag->GetDateAdded().GetAsLocalizedDate(); |
| 403 | return true; |
| 404 | } |
| 405 | break; |
| 406 | case LISTITEM_SONG_VIDEO_URL: |
| 407 | value = tag->GetSongVideoURL(); |
| 408 | return true; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | switch (info.m_info) |
| 413 | { |
| 414 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 415 | // MUSICPLAYER_* |
| 416 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 417 | case MUSICPLAYER_PROPERTY: |
| 418 | if (StringUtils::StartsWithNoCase(info.GetData3(), "Role.") && item->HasMusicInfoTag()) |
| 419 | { |
| 420 | // "Role.xxxx" properties are held in music tag |
| 421 | std::string property = info.GetData3(); |
| 422 | property.erase(0, 5); //Remove Role. |
| 423 | value = item->GetMusicInfoTag()->GetArtistStringForRole(property); |
| 424 | return true; |
| 425 | } |
| 426 | value = item->GetProperty(info.GetData3()).asString(); |
| 427 | return true; |
| 428 | case MUSICPLAYER_PLAYLISTLEN: |
| 429 | if (CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() == PLAYLIST::TYPE_MUSIC) |
| 430 | { |
| 431 | value = GUIINFO::GetPlaylistLabel(PLAYLIST_LENGTH); |
| 432 | return true; |
| 433 | } |
| 434 | break; |
| 435 | case MUSICPLAYER_PLAYLISTPOS: |
| 436 | if (CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() == PLAYLIST::TYPE_MUSIC) |
| 437 | { |
| 438 | value = GUIINFO::GetPlaylistLabel(PLAYLIST_POSITION); |
| 439 | return true; |
| 440 | } |
| 441 | break; |
| 442 | case MUSICPLAYER_COVER: |
| 443 | { |
| 444 | const auto& components = CServiceBroker::GetAppComponents(); |
| 445 | const auto appPlayer = components.GetComponent<CApplicationPlayer>(); |
| 446 | if (appPlayer->IsPlayingAudio()) |
| 447 | { |
| 448 | if (fallback) |
| 449 | *fallback = "DefaultAlbumCover.png"; |
| 450 | value = item->HasArt("thumb") ? item->GetArt("thumb") : "DefaultAlbumCover.png"; |
| 451 | return true; |
| 452 | } |
| 453 | break; |
| 454 | } |
| 455 | case MUSICPLAYER_BITRATE: |
| 456 | { |
| 457 | int iBitrate = m_audioInfo.bitrate; |
| 458 | if (iBitrate > 0) |
| 459 | { |
| 460 | value = std::to_string(std::lrint(static_cast<double>(iBitrate) / 1000.0)); |
| 461 | return true; |
| 462 | } |
| 463 | break; |
| 464 | } |
| 465 | case MUSICPLAYER_CHANNELS: |
| 466 | { |
| 467 | int iChannels = m_audioInfo.channels; |
| 468 | if (iChannels > 0) |
| 469 | { |
| 470 | value = std::to_string(iChannels); |
| 471 | return true; |
| 472 | } |
| 473 | break; |
| 474 | } |
| 475 | case MUSICPLAYER_BITSPERSAMPLE: |
| 476 | { |
| 477 | int iBPS = m_audioInfo.bitspersample; |
| 478 | if (iBPS > 0) |
| 479 | { |
| 480 | value = std::to_string(iBPS); |
| 481 | return true; |
| 482 | } |
| 483 | break; |
| 484 | } |
| 485 | case MUSICPLAYER_SAMPLERATE: |
| 486 | { |
| 487 | int iSamplerate = m_audioInfo.samplerate; |
| 488 | if (iSamplerate > 0) |
| 489 | { |
| 490 | value = StringUtils::Format("{:.5}", static_cast<double>(iSamplerate) / 1000.0); |
| 491 | return true; |
| 492 | } |
| 493 | break; |
| 494 | } |
| 495 | case MUSICPLAYER_CODEC: |
| 496 | value = m_audioInfo.codecName; |
| 497 | return true; |
| 498 | } |
| 499 | |
| 500 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 501 | // MUSICPM_* |
| 502 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 503 | if (GetPartyModeLabel(value, info)) |
| 504 | return true; |
| 505 | |
| 506 | return false; |
| 507 | } |
| 508 | |
| 509 | bool CMusicGUIInfo::GetPartyModeLabel(std::string& value, const CGUIInfo &info) const |
| 510 | { |
| 511 | int iSongs = -1; |
| 512 | |
| 513 | switch (info.m_info) |
| 514 | { |
| 515 | case MUSICPM_SONGSPLAYED: |
| 516 | iSongs = g_partyModeManager.GetSongsPlayed(); |
| 517 | break; |
| 518 | case MUSICPM_MATCHINGSONGS: |
| 519 | iSongs = g_partyModeManager.GetMatchingSongs(); |
| 520 | break; |
| 521 | case MUSICPM_MATCHINGSONGSPICKED: |
| 522 | iSongs = g_partyModeManager.GetMatchingSongsPicked(); |
| 523 | break; |
| 524 | case MUSICPM_MATCHINGSONGSLEFT: |
| 525 | iSongs = g_partyModeManager.GetMatchingSongsLeft(); |
| 526 | break; |
| 527 | case MUSICPM_RELAXEDSONGSPICKED: |
| 528 | iSongs = g_partyModeManager.GetRelaxedSongs(); |
| 529 | break; |
| 530 | case MUSICPM_RANDOMSONGSPICKED: |
| 531 | iSongs = g_partyModeManager.GetRandomSongs(); |
| 532 | break; |
| 533 | } |
| 534 | |
| 535 | if (iSongs >= 0) |
| 536 | { |
| 537 | value = std::to_string(iSongs); |
| 538 | return true; |
| 539 | } |
| 540 | |
| 541 | return false; |
| 542 | } |
| 543 | |
| 544 | bool CMusicGUIInfo::GetPlaylistInfo(std::string& value, const CGUIInfo &info) const |
| 545 | { |
| 546 | const PLAYLIST::CPlayList& playlist = |
| 547 | CServiceBroker::GetPlaylistPlayer().GetPlaylist(PLAYLIST::TYPE_MUSIC); |
| 548 | if (playlist.size() < 1) |
| 549 | return false; |
| 550 | |
| 551 | int index = info.GetData2(); |
| 552 | if (info.GetData1() == 1) |
| 553 | { // relative index (requires current playlist is TYPE_MUSIC) |
| 554 | if (CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() != PLAYLIST::TYPE_MUSIC) |
| 555 | return false; |
| 556 | |
| 557 | index = CServiceBroker::GetPlaylistPlayer().GetNextItemIdx(index); |
| 558 | } |
| 559 | |
| 560 | if (index < 0 || index >= playlist.size()) |
| 561 | return false; |
| 562 | |
| 563 | const CFileItemPtr playlistItem = playlist[index]; |
| 564 | if (playlistItem->HasMusicInfoTag() && !playlistItem->GetMusicInfoTag()->Loaded()) |
| 565 | { |
| 566 | playlistItem->LoadMusicTag(); |
| 567 | playlistItem->GetMusicInfoTag()->SetLoaded(); |
| 568 | } |
| 569 | // try to set a thumbnail |
| 570 | if (!playlistItem->HasArt("thumb")) |
| 571 | { |
| 572 | CMusicThumbLoader loader; |
| 573 | loader.LoadItem(playlistItem.get()); |
| 574 | // still no thumb? then just the set the default cover |
| 575 | if (!playlistItem->HasArt("thumb")) |
| 576 | playlistItem->SetArt("thumb", "DefaultAlbumCover.png"); |
| 577 | } |
| 578 | if (info.m_info == MUSICPLAYER_PLAYLISTPOS) |
| 579 | { |
| 580 | value = std::to_string(index + 1); |
| 581 | return true; |
| 582 | } |
| 583 | else if (info.m_info == MUSICPLAYER_COVER) |
| 584 | { |
| 585 | value = playlistItem->GetArt("thumb"); |
| 586 | return true; |
| 587 | } |
| 588 | |
| 589 | return GetLabel(value, playlistItem.get(), 0, CGUIInfo(info.m_info), nullptr); |
| 590 | } |
| 591 | |
| 592 | bool CMusicGUIInfo::GetFallbackLabel(std::string& value, |
| 593 | const CFileItem* item, |
| 594 | int contextWindow, |
| 595 | const CGUIInfo& info, |
| 596 | std::string* fallback) |
| 597 | { |
| 598 | // No fallback for musicplayer "offset" and "position" info labels |
| 599 | if (info.GetData1() && ((info.m_info >= MUSICPLAYER_OFFSET_POSITION_FIRST && |
| 600 | info.m_info <= MUSICPLAYER_OFFSET_POSITION_LAST) || |
| 601 | (info.m_info >= PLAYER_OFFSET_POSITION_FIRST && info.m_info <= PLAYER_OFFSET_POSITION_LAST))) |
| 602 | return false; |
| 603 | |
| 604 | const CMusicInfoTag* tag = item->GetMusicInfoTag(); |
| 605 | if (tag) |
| 606 | { |
| 607 | switch (info.m_info) |
| 608 | { |
| 609 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 610 | // MUSICPLAYER_* |
| 611 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 612 | case MUSICPLAYER_TITLE: |
| 613 | value = item->GetLabel(); |
| 614 | if (value.empty()) |
| 615 | value = CUtil::GetTitleFromPath(item->GetPath()); |
| 616 | return true; |
| 617 | default: |
| 618 | break; |
| 619 | } |
| 620 | } |
| 621 | return false; |
| 622 | } |
| 623 | |
| 624 | bool CMusicGUIInfo::GetInt(int& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const |
| 625 | { |
| 626 | return false; |
| 627 | } |
| 628 | |
| 629 | bool CMusicGUIInfo::GetBool(bool& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const |
| 630 | { |
| 631 | const CFileItem* item = static_cast<const CFileItem*>(gitem); |
| 632 | const CMusicInfoTag* tag = item->GetMusicInfoTag(); |
| 633 | |
| 634 | switch (info.m_info) |
| 635 | { |
| 636 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 637 | // MUSICPLAYER_* |
| 638 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 639 | case MUSICPLAYER_CONTENT: |
| 640 | value = StringUtils::EqualsNoCase(info.GetData3(), "files"); |
| 641 | return value; // if no match for this provider, other providers shall be asked. |
| 642 | case MUSICPLAYER_HASPREVIOUS: |
| 643 | // requires current playlist be TYPE_MUSIC |
| 644 | if (CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() == PLAYLIST::TYPE_MUSIC) |
| 645 | { |
| 646 | value = (CServiceBroker::GetPlaylistPlayer().GetCurrentItemIdx() > 0); // not first song |
| 647 | return true; |
| 648 | } |
| 649 | break; |
| 650 | case MUSICPLAYER_HASNEXT: |
| 651 | // requires current playlist be TYPE_MUSIC |
| 652 | if (CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() == PLAYLIST::TYPE_MUSIC) |
| 653 | { |
| 654 | value = (CServiceBroker::GetPlaylistPlayer().GetCurrentItemIdx() < |
| 655 | (CServiceBroker::GetPlaylistPlayer().GetPlaylist(PLAYLIST::TYPE_MUSIC).size() - |
| 656 | 1)); // not last song |
| 657 | return true; |
| 658 | } |
| 659 | break; |
| 660 | case MUSICPLAYER_PLAYLISTPLAYING: |
| 661 | { |
| 662 | const auto& components = CServiceBroker::GetAppComponents(); |
| 663 | const auto appPlayer = components.GetComponent<CApplicationPlayer>(); |
| 664 | if (appPlayer->IsPlayingAudio() && |
| 665 | CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() == PLAYLIST::TYPE_MUSIC) |
| 666 | { |
| 667 | value = true; |
| 668 | return true; |
| 669 | } |
| 670 | break; |
| 671 | } |
| 672 | case MUSICPLAYER_EXISTS: |
| 673 | { |
| 674 | int index = info.GetData2(); |
| 675 | if (info.GetData1() == 1) |
| 676 | { // relative index |
| 677 | if (CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() != PLAYLIST::TYPE_MUSIC) |
| 678 | { |
| 679 | value = false; |
| 680 | return true; |
| 681 | } |
| 682 | index += CServiceBroker::GetPlaylistPlayer().GetCurrentItemIdx(); |
| 683 | } |
| 684 | value = |
| 685 | (index >= 0 && |
| 686 | index < CServiceBroker::GetPlaylistPlayer().GetPlaylist(PLAYLIST::TYPE_MUSIC).size()); |
| 687 | return true; |
| 688 | } |
| 689 | case MUSICPLAYER_ISMULTIDISC: |
| 690 | if (tag) |
| 691 | { |
| 692 | value = (item->GetMusicInfoTag()->GetTotalDiscs() > 1); |
| 693 | return true; |
| 694 | } |
| 695 | break; |
| 696 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 697 | // MUSICPM_* |
| 698 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 699 | case MUSICPM_ENABLED: |
| 700 | value = g_partyModeManager.IsEnabled(); |
| 701 | return true; |
| 702 | |
| 703 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 704 | // LISTITEM_* |
| 705 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 706 | case LISTITEM_IS_BOXSET: |
| 707 | if (tag) |
| 708 | { |
| 709 | value = tag->GetBoxset() == true; |
| 710 | return true; |
| 711 | } |
| 712 | break; |
| 713 | } |
| 714 | |
| 715 | return false; |
| 716 | } |