aboutsummaryrefslogtreecommitdiff
path: root/xbmc/filesystem/MusicFileDirectory.cpp
blob: 51340b54ebb6dd7f820dd20621dbf6bfdd2de575 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 *  Copyright (C) 2005-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "MusicFileDirectory.h"

#include "FileItem.h"
#include "FileItemList.h"
#include "URL.h"
#include "guilib/LocalizeStrings.h"
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"

using namespace MUSIC_INFO;
using namespace XFILE;

CMusicFileDirectory::CMusicFileDirectory(void) = default;

CMusicFileDirectory::~CMusicFileDirectory(void) = default;

bool CMusicFileDirectory::GetDirectory(const CURL& url, CFileItemList &items)
{
  std::string strPath=url.Get();

  std::string strFileName;
  strFileName = URIUtils::GetFileName(strPath);
  URIUtils::RemoveExtension(strFileName);

  int iStreams = GetTrackCount(strPath);

  URIUtils::AddSlashAtEnd(strPath);

  for (int i=0; i<iStreams; ++i)
  {
    std::string strLabel =
        StringUtils::Format("{} - {} {:02}", strFileName, g_localizeStrings.Get(554), i + 1);
    CFileItemPtr pItem(new CFileItem(strLabel));
    strLabel = StringUtils::Format("{}{}-{}.{}", strPath, strFileName, i + 1, m_strExt);
    pItem->SetPath(strLabel);

    /*
     * Try fist to load tag about related stream track. If them fails or not
     * available, take base tag for all streams (in this case the item names
     * are all the same).
     */
    MUSIC_INFO::CMusicInfoTag tag;
    if (Load(strLabel, tag, nullptr))
      *pItem->GetMusicInfoTag() = tag;
    else if (m_tag.Loaded())
      *pItem->GetMusicInfoTag() = m_tag;

    /*
     * Check track number not set and take stream entry number about.
     * NOTE: Audio decoder addons can also give a own track number.
     */
    if (pItem->GetMusicInfoTag()->GetTrackNumber() == 0)
      pItem->GetMusicInfoTag()->SetTrackNumber(i+1);
    items.Add(pItem);
  }

  return true;
}

bool CMusicFileDirectory::Exists(const CURL& url)
{
  return true;
}

bool CMusicFileDirectory::ContainsFiles(const CURL &url)
{
  const std::string pathToUrl(url.Get());
  if (GetTrackCount(pathToUrl) > 1)
    return true;

  return false;
}