Merge pull request #25808 from CastagnaIT/fix_url_parse
[xbmc.git] / xbmc / playlists / PlayListFactory.cpp
blob63b9bd401d471d862835868f99ea6b2cb549e35d
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 "PlayListFactory.h"
11 #include "FileItem.h"
12 #include "URL.h"
13 #include "network/NetworkFileItemClassify.h"
14 #include "playlists/PlayListASX.h"
15 #include "playlists/PlayListB4S.h"
16 #include "playlists/PlayListM3U.h"
17 #include "playlists/PlayListPLS.h"
18 #include "playlists/PlayListRAM.h"
19 #include "playlists/PlayListURL.h"
20 #include "playlists/PlayListWPL.h"
21 #include "playlists/PlayListXML.h"
22 #include "playlists/PlayListXSPF.h"
23 #include "utils/StringUtils.h"
24 #include "utils/URIUtils.h"
26 namespace KODI::PLAYLIST
29 CPlayList* CPlayListFactory::Create(const CURL& url)
31 CFileItem item{url.Get(), false};
33 if (url.HasOption("mimetype"))
35 item.SetContentLookup(false);
36 item.SetMimeType(url.GetOption("mimetype"));
39 return Create(item);
42 CPlayList* CPlayListFactory::Create(const std::string& filename)
44 CFileItem item(filename,false);
45 return Create(item);
48 CPlayList* CPlayListFactory::Create(const CFileItem& item)
50 if (NETWORK::IsInternetStream(item))
52 // Ensure the MIME type has been retrieved for http:// and shout:// streams
53 if (item.GetMimeType().empty())
54 const_cast<CFileItem&>(item).FillInMimeType();
56 std::string strMimeType = item.GetMimeType();
57 StringUtils::ToLower(strMimeType);
59 if (strMimeType == "video/x-ms-asf"
60 || strMimeType == "video/x-ms-asx"
61 || strMimeType == "video/x-ms-wmv"
62 || strMimeType == "video/x-ms-wma"
63 || strMimeType == "video/x-ms-wfs"
64 || strMimeType == "video/x-ms-wvx"
65 || strMimeType == "video/x-ms-wax")
66 return new CPlayListASX();
68 if (strMimeType == "audio/x-pn-realaudio")
69 return new CPlayListRAM();
71 if (strMimeType == "audio/x-scpls"
72 || strMimeType == "playlist"
73 || strMimeType == "text/html")
74 return new CPlayListPLS();
76 // online m3u8 files are for hls streaming -- do not treat as playlist
77 if (strMimeType == "audio/x-mpegurl" && !item.IsType(".m3u8"))
78 return new CPlayListM3U();
80 if (strMimeType == "application/vnd.ms-wpl")
81 return new CPlayListWPL();
83 if (strMimeType == "application/xspf+xml")
84 return new CPlayListXSPF();
87 std::string path = item.GetDynPath();
89 std::string extension = URIUtils::GetExtension(path);
90 StringUtils::ToLower(extension);
92 if (extension == ".m3u" || (extension == ".m3u8" && !NETWORK::IsInternetStream(item)) ||
93 extension == ".strm")
94 return new CPlayListM3U();
96 if (extension == ".pls")
97 return new CPlayListPLS();
99 if (extension == ".b4s")
100 return new CPlayListB4S();
102 if (extension == ".wpl")
103 return new CPlayListWPL();
105 if (extension == ".asx")
106 return new CPlayListASX();
108 if (extension == ".ram")
109 return new CPlayListRAM();
111 if (extension == ".url")
112 return new CPlayListURL();
114 if (extension == ".pxml")
115 return new CPlayListXML();
117 if (extension == ".xspf")
118 return new CPlayListXSPF();
120 return NULL;
124 bool CPlayListFactory::IsPlaylist(const CFileItem& item)
126 std::string strMimeType = item.GetMimeType();
127 StringUtils::ToLower(strMimeType);
129 /* These are a bit uncertain
130 if(strMimeType == "video/x-ms-asf"
131 || strMimeType == "video/x-ms-asx"
132 || strMimeType == "video/x-ms-wmv"
133 || strMimeType == "video/x-ms-wma"
134 || strMimeType == "video/x-ms-wfs"
135 || strMimeType == "video/x-ms-wvx"
136 || strMimeType == "video/x-ms-wax"
137 || strMimeType == "video/x-ms-asf")
138 return true;
141 // online m3u8 files are hls:// -- do not treat as playlist
142 if (NETWORK::IsInternetStream(item) && item.IsType(".m3u8"))
143 return false;
145 if(strMimeType == "audio/x-pn-realaudio"
146 || strMimeType == "playlist"
147 || strMimeType == "audio/x-mpegurl")
148 return true;
150 return IsPlaylist(item.GetDynPath());
153 bool CPlayListFactory::IsPlaylist(const CURL& url)
155 return URIUtils::HasExtension(url,
156 ".m3u|.m3u8|.b4s|.pls|.strm|.wpl|.asx|.ram|.url|.pxml|.xspf");
159 bool CPlayListFactory::IsPlaylist(const std::string& filename)
161 return URIUtils::HasExtension(filename,
162 ".m3u|.m3u8|.b4s|.pls|.strm|.wpl|.asx|.ram|.url|.pxml|.xspf");
165 } // namespace KODI::PLAYLIST