Merge pull request #4857 from t-nelson/Gotham_13.2_backports
[vuplus_xbmc] / xbmc / playlists / PlayListURL.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
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)
8  *  any later version.
9  *
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.
14  *
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/>.
18  *
19  */
20
21 #include "PlayListURL.h"
22 #include "filesystem/File.h"
23 #include "utils/URIUtils.h"
24 #include "utils/StringUtils.h"
25
26 using namespace PLAYLIST;
27 using namespace XFILE;
28
29 // example url file
30 //[DEFAULT]
31 //BASEURL=http://msdn2.microsoft.com/en-us/library/ms812698.aspx
32 //[InternetShortcut]
33 //URL=http://msdn2.microsoft.com/en-us/library/ms812698.aspx
34
35 CPlayListURL::CPlayListURL(void)
36 {}
37
38 CPlayListURL::~CPlayListURL(void)
39 {}
40
41 bool CPlayListURL::Load(const CStdString& strFileName)
42 {
43   char szLine[4096];
44   CStdString strLine;
45
46   Clear();
47
48   m_strPlayListName = URIUtils::GetFileName(strFileName);
49   URIUtils::GetParentPath(strFileName, m_strBasePath);
50
51   CFile file;
52   if (!file.Open(strFileName) )
53   {
54     file.Close();
55     return false;
56   }
57
58   while (file.ReadString(szLine, 1024))
59   {
60     strLine = szLine;
61     StringUtils::RemoveCRLF(strLine);
62
63     if (StringUtils::StartsWith(strLine, "[InternetShortcut]"))
64     {
65       if (file.ReadString(szLine,1024))
66       {
67         strLine  = szLine;
68         StringUtils::RemoveCRLF(strLine);
69         if (StringUtils::StartsWith(strLine, "URL="))
70         {
71           CFileItemPtr newItem(new CFileItem(strLine.substr(4), false));
72           Add(newItem);
73         }
74       }
75     }
76   }
77
78   file.Close();
79   return true;
80 }
81