[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / filesystem / CDDADirectory.cpp
blob9b6beaaeea957683dfa1a193ac42f63fb47b6d9c
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "CDDADirectory.h"
11 #include "File.h"
12 #include "FileItem.h"
13 #include "ServiceBroker.h"
14 #include "music/MusicDatabase.h"
15 #include "storage/MediaManager.h"
16 #include "utils/StringUtils.h"
18 using namespace XFILE;
19 using namespace MEDIA_DETECT;
21 CCDDADirectory::CCDDADirectory(void) = default;
23 CCDDADirectory::~CCDDADirectory(void) = default;
26 bool CCDDADirectory::GetDirectory(const CURL& url, CFileItemList &items)
28 // Reads the tracks from an audio cd
29 std::string strPath = url.Get();
31 if (!CServiceBroker::GetMediaManager().IsDiscInDrive(strPath))
32 return false;
34 // Get information for the inserted disc
35 CCdInfo* pCdInfo = CServiceBroker::GetMediaManager().GetCdInfo(strPath);
36 if (pCdInfo == NULL)
37 return false;
39 // Preload CDDB info
40 CMusicDatabase musicdatabase;
41 musicdatabase.LookupCDDBInfo();
43 // If the disc has no tracks, we are finished here.
44 int nTracks = pCdInfo->GetTrackCount();
45 if (nTracks <= 0)
46 return false;
48 // Generate fileitems
49 for (int i = 1;i <= nTracks;++i)
51 // Skip Datatracks for display,
52 // but needed to query cddb
53 if (!pCdInfo->IsAudio(i))
54 continue;
56 // Format standard cdda item label
57 std::string strLabel = StringUtils::Format("Track {:02}", i);
59 CFileItemPtr pItem(new CFileItem(strLabel));
60 pItem->m_bIsFolder = false;
61 std::string path = StringUtils::Format("cdda://local/{:02}.cdda", i);
62 pItem->SetPath(path);
64 struct __stat64 s64;
65 if (CFile::Stat(pItem->GetPath(), &s64) == 0)
66 pItem->m_dwSize = s64.st_size;
68 items.Add(pItem);
70 return true;