aboutsummaryrefslogtreecommitdiff
path: root/xbmc/playlists/PlayListFactory.cpp
blob: 0fb8ab7ebd244329872193fa5ee3bcee451ce315 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 *  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 "PlayListFactory.h"

#include "FileItem.h"
#include "network/NetworkFileItemClassify.h"
#include "playlists/PlayListB4S.h"
#include "playlists/PlayListM3U.h"
#include "playlists/PlayListPLS.h"
#include "playlists/PlayListURL.h"
#include "playlists/PlayListWPL.h"
#include "playlists/PlayListXML.h"
#include "playlists/PlayListXSPF.h"
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"

namespace KODI::PLAYLIST
{

CPlayList* CPlayListFactory::Create(const std::string& filename)
{
  CFileItem item(filename,false);
  return Create(item);
}

CPlayList* CPlayListFactory::Create(const CFileItem& item)
{
  if (NETWORK::IsInternetStream(item))
  {
    // Ensure the MIME type has been retrieved for http:// and shout:// streams
    if (item.GetMimeType().empty())
      const_cast<CFileItem&>(item).FillInMimeType();

    std::string strMimeType = item.GetMimeType();
    StringUtils::ToLower(strMimeType);

    if (strMimeType == "video/x-ms-asf"
    || strMimeType == "video/x-ms-asx"
    || strMimeType == "video/x-ms-wmv"
    || strMimeType == "video/x-ms-wma"
    || strMimeType == "video/x-ms-wfs"
    || strMimeType == "video/x-ms-wvx"
    || strMimeType == "video/x-ms-wax")
      return new CPlayListASX();

    if (strMimeType == "audio/x-pn-realaudio")
      return new CPlayListRAM();

    if (strMimeType == "audio/x-scpls"
    || strMimeType == "playlist"
    || strMimeType == "text/html")
      return new CPlayListPLS();

    // online m3u8 files are for hls streaming -- do not treat as playlist
    if (strMimeType == "audio/x-mpegurl" && !item.IsType(".m3u8"))
      return new CPlayListM3U();

    if (strMimeType == "application/vnd.ms-wpl")
      return new CPlayListWPL();

    if (strMimeType == "application/xspf+xml")
      return new CPlayListXSPF();
  }

  std::string path = item.GetDynPath();

  std::string extension = URIUtils::GetExtension(path);
  StringUtils::ToLower(extension);

  if (extension == ".m3u" || (extension == ".m3u8" && !NETWORK::IsInternetStream(item)) ||
      extension == ".strm")
    return new CPlayListM3U();

  if (extension == ".pls")
    return new CPlayListPLS();

  if (extension == ".b4s")
    return new CPlayListB4S();

  if (extension == ".wpl")
    return new CPlayListWPL();

  if (extension == ".asx")
    return new CPlayListASX();

  if (extension == ".ram")
    return new CPlayListRAM();

  if (extension == ".url")
    return new CPlayListURL();

  if (extension == ".pxml")
    return new CPlayListXML();

  if (extension == ".xspf")
    return new CPlayListXSPF();

  return NULL;

}

bool CPlayListFactory::IsPlaylist(const CFileItem& item)
{
  std::string strMimeType = item.GetMimeType();
  StringUtils::ToLower(strMimeType);

/* These are a bit uncertain
  if(strMimeType == "video/x-ms-asf"
  || strMimeType == "video/x-ms-asx"
  || strMimeType == "video/x-ms-wmv"
  || strMimeType == "video/x-ms-wma"
  || strMimeType == "video/x-ms-wfs"
  || strMimeType == "video/x-ms-wvx"
  || strMimeType == "video/x-ms-wax"
  || strMimeType == "video/x-ms-asf")
    return true;
*/

  // online m3u8 files are hls:// -- do not treat as playlist
  if (NETWORK::IsInternetStream(item) && item.IsType(".m3u8"))
    return false;

  if(strMimeType == "audio/x-pn-realaudio"
  || strMimeType == "playlist"
  || strMimeType == "audio/x-mpegurl")
    return true;

  return IsPlaylist(item.GetDynPath());
}

bool CPlayListFactory::IsPlaylist(const CURL& url)
{
  return URIUtils::HasExtension(url,
                                ".m3u|.m3u8|.b4s|.pls|.strm|.wpl|.asx|.ram|.url|.pxml|.xspf");
}

bool CPlayListFactory::IsPlaylist(const std::string& filename)
{
  return URIUtils::HasExtension(filename,
                     ".m3u|.m3u8|.b4s|.pls|.strm|.wpl|.asx|.ram|.url|.pxml|.xspf");
}

} // namespace KODI::PLAYLIST