2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "PlayListWPL.h"
23 #include "utils/XBMCTinyXML.h"
24 #include "settings/AdvancedSettings.h"
25 #include "filesystem/File.h"
26 #include "utils/log.h"
27 #include "utils/URIUtils.h"
29 using namespace XFILE;
30 using namespace PLAYLIST;
33 /* ------------------------ example wpl playlist file ---------------------------------
37 <meta name="Generator" content="Microsoft Windows Media Player -- 10.0.0.3646"/>
39 <title>Playlist</title>
43 <media src="E:\MP3\Track1.mp3"/>
44 <media src="E:\MP3\Track2.mp3"/>
45 <media src="E:\MP3\track3.mp3"/>
49 ------------------------ end of example wpl playlist file ---------------------------------*/
50 //Note: File is utf-8 encoded by default
52 CPlayListWPL::CPlayListWPL(void)
55 CPlayListWPL::~CPlayListWPL(void)
59 bool CPlayListWPL::LoadData(istream& stream)
66 CLog::Log(LOGERROR, "Unable to parse B4S info Error: %s", xmlDoc.ErrorDesc());
70 TiXmlElement* pRootElement = xmlDoc.RootElement();
71 if (!pRootElement ) return false;
73 TiXmlElement* pHeadElement = pRootElement->FirstChildElement("head");
76 TiXmlElement* pTitelElement = pHeadElement->FirstChildElement("title");
78 m_strPlayListName = pTitelElement->Value();
81 TiXmlElement* pBodyElement = pRootElement->FirstChildElement("body");
82 if (!pBodyElement ) return false;
84 TiXmlElement* pSeqElement = pBodyElement->FirstChildElement("seq");
85 if (!pSeqElement ) return false;
87 TiXmlElement* pMediaElement = pSeqElement->FirstChildElement("media");
89 if (!pMediaElement) return false;
92 CStdString strFileName = pMediaElement->Attribute("src");
93 if (strFileName.size())
95 strFileName = URIUtils::SubstitutePath(strFileName);
96 CUtil::GetQualifiedFilename(m_strBasePath, strFileName);
97 CStdString strDescription = URIUtils::GetFileName(strFileName);
98 CFileItemPtr newItem(new CFileItem(strDescription));
99 newItem->SetPath(strFileName);
102 pMediaElement = pMediaElement->NextSiblingElement();
107 void CPlayListWPL::Save(const CStdString& strFileName) const
109 if (!m_vecItems.size()) return ;
110 CStdString strPlaylist = CUtil::MakeLegalPath(strFileName);
112 if (!file.OpenForWrite(strPlaylist, true))
114 CLog::Log(LOGERROR, "Could not save WPL playlist: [%s]", strPlaylist.c_str());
118 write += StringUtils::Format("<?wpl version=%c1.0%c>\n", 34, 34);
119 write += StringUtils::Format("<smil>\n");
120 write += StringUtils::Format(" <head>\n");
121 write += StringUtils::Format(" <meta name=%cGenerator%c content=%cMicrosoft Windows Media Player -- 10.0.0.3646%c/>\n", 34, 34, 34, 34);
122 write += StringUtils::Format(" <author/>\n");
123 write += StringUtils::Format(" <title>%s</title>\n", m_strPlayListName.c_str());
124 write += StringUtils::Format(" </head>\n");
125 write += StringUtils::Format(" <body>\n");
126 write += StringUtils::Format(" <seq>\n");
127 for (int i = 0; i < (int)m_vecItems.size(); ++i)
129 CFileItemPtr item = m_vecItems[i];
130 write += StringUtils::Format(" <media src=%c%s%c/>", 34, item->GetPath().c_str(), 34);
132 write += StringUtils::Format(" </seq>\n");
133 write += StringUtils::Format(" </body>\n");
134 write += StringUtils::Format("</smil>\n");
135 file.Write(write.c_str(), write.size());