Debian Codegraph @

xbmc/playlists/PlayListFactory.cpp

raw
1 /*
2 * Copyright (C) 2005-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 "PlayListFactory.h"
10
11 #include "FileItem.h"
12 #include "URL.h"
13 #include "playlists/PlayListB4S.h"
14 #include "playlists/PlayListM3U.h"
15 #include "playlists/PlayListPLS.h"
16 #include "playlists/PlayListURL.h"
17 #include "playlists/PlayListWPL.h"
18 #include "playlists/PlayListXML.h"
19 #include "playlists/PlayListXSPF.h"
20 #include "utils/StringUtils.h"
21 #include "utils/URIUtils.h"
22
23 using namespace PLAYLIST;
24
25 CPlayList* CPlayListFactory::Create(const CURL& url)
26 {
27 CFileItem item{url.Get(), false};
28
29 if (url.HasOption("mimetype"))
30 {
31 item.SetContentLookup(false);
32 item.SetMimeType(url.GetOption("mimetype"));
33 }
34
35 return Create(item);
36 }
37
38 CPlayList* CPlayListFactory::Create(const std::string& filename)
39 {
40 CFileItem item(filename,false);
41 return Create(item);
42 }
43
44 CPlayList* CPlayListFactory::Create(const CFileItem& item)
45 {
46 if (item.IsInternetStream())
47 {
48 // Ensure the MIME type has been retrieved for http:// and shout:// streams
49 if (item.GetMimeType().empty())
50 const_cast<CFileItem&>(item).FillInMimeType();
51
52 std::string strMimeType = item.GetMimeType();
53 StringUtils::ToLower(strMimeType);
54
55 if (strMimeType == "video/x-ms-asf"
56 || strMimeType == "video/x-ms-asx"
57 || strMimeType == "video/x-ms-wmv"
58 || strMimeType == "video/x-ms-wma"
59 || strMimeType == "video/x-ms-wfs"
60 || strMimeType == "video/x-ms-wvx"
61 || strMimeType == "video/x-ms-wax")
62 return new CPlayListASX();
63
64 if (strMimeType == "audio/x-pn-realaudio")
65 return new CPlayListRAM();
66
67 if (strMimeType == "audio/x-scpls"
68 || strMimeType == "playlist"
69 || strMimeType == "text/html")
70 return new CPlayListPLS();
71
72 // online m3u8 files are for hls streaming -- do not treat as playlist
73 if (strMimeType == "audio/x-mpegurl" && !item.IsType(".m3u8"))
74 return new CPlayListM3U();
75
76 if (strMimeType == "application/vnd.ms-wpl")
77 return new CPlayListWPL();
78
79 if (strMimeType == "application/xspf+xml")
80 return new CPlayListXSPF();
81 }
82
83 std::string path = item.GetDynPath();
84
85 std::string extension = URIUtils::GetExtension(path);
86 StringUtils::ToLower(extension);
87
88 if (extension == ".m3u" || (extension == ".m3u8" && !item.IsInternetStream()) || extension == ".strm")
89 return new CPlayListM3U();
90
91 if (extension == ".pls")
92 return new CPlayListPLS();
93
94 if (extension == ".b4s")
95 return new CPlayListB4S();
96
97 if (extension == ".wpl")
98 return new CPlayListWPL();
99
100 if (extension == ".asx")
101 return new CPlayListASX();
102
103 if (extension == ".ram")
104 return new CPlayListRAM();
105
106 if (extension == ".url")
107 return new CPlayListURL();
108
109 if (extension == ".pxml")
110 return new CPlayListXML();
111
112 if (extension == ".xspf")
113 return new CPlayListXSPF();
114
115 return NULL;
116
117 }
118
119 bool CPlayListFactory::IsPlaylist(const CFileItem& item)
120 {
121 std::string strMimeType = item.GetMimeType();
122 StringUtils::ToLower(strMimeType);
123
124 /* These are a bit uncertain
125 if(strMimeType == "video/x-ms-asf"
126 || strMimeType == "video/x-ms-asx"
127 || strMimeType == "video/x-ms-wmv"
128 || strMimeType == "video/x-ms-wma"
129 || strMimeType == "video/x-ms-wfs"
130 || strMimeType == "video/x-ms-wvx"
131 || strMimeType == "video/x-ms-wax"
132 || strMimeType == "video/x-ms-asf")
133 return true;
134 */
135
136 // online m3u8 files are hls:// -- do not treat as playlist
137 if (item.IsInternetStream() && item.IsType(".m3u8"))
138 return false;
139
140 if(strMimeType == "audio/x-pn-realaudio"
141 || strMimeType == "playlist"
142 || strMimeType == "audio/x-mpegurl")
143 return true;
144
145 return IsPlaylist(item.GetDynPath());
146 }
147
148 bool CPlayListFactory::IsPlaylist(const CURL& url)
149 {
150 return URIUtils::HasExtension(url,
151 ".m3u|.m3u8|.b4s|.pls|.strm|.wpl|.asx|.ram|.url|.pxml|.xspf");
152 }
153
154 bool CPlayListFactory::IsPlaylist(const std::string& filename)
155 {
156 return URIUtils::HasExtension(filename,
157 ".m3u|.m3u8|.b4s|.pls|.strm|.wpl|.asx|.ram|.url|.pxml|.xspf");
158 }
159