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 "PlayListURL.h"
10 
11 #include "filesystem/File.h"
12 #include "utils/StringUtils.h"
13 #include "utils/URIUtils.h"
14 
15 using namespace PLAYLIST;
16 using namespace XFILE;
17 
18 // example url file
19 //[DEFAULT]
20 //BASEURL=http://msdn2.microsoft.com/en-us/library/ms812698.aspx
21 //[InternetShortcut]
22 //URL=http://msdn2.microsoft.com/en-us/library/ms812698.aspx
23 
24 CPlayListURL::CPlayListURL(void) = default;
25 
26 CPlayListURL::~CPlayListURL(void) = default;
27 
Load(const std::string & strFileName)28 bool CPlayListURL::Load(const std::string& strFileName)
29 {
30   char szLine[4096];
31   std::string strLine;
32 
33   Clear();
34 
35   m_strPlayListName = URIUtils::GetFileName(strFileName);
36   URIUtils::GetParentPath(strFileName, m_strBasePath);
37 
38   CFile file;
39   if (!file.Open(strFileName) )
40   {
41     file.Close();
42     return false;
43   }
44 
45   while (file.ReadString(szLine, 1024))
46   {
47     strLine = szLine;
48     StringUtils::RemoveCRLF(strLine);
49 
50     if (StringUtils::StartsWith(strLine, "[InternetShortcut]"))
51     {
52       if (file.ReadString(szLine,1024))
53       {
54         strLine  = szLine;
55         StringUtils::RemoveCRLF(strLine);
56         if (StringUtils::StartsWith(strLine, "URL="))
57         {
58           CFileItemPtr newItem(new CFileItem(strLine.substr(4), false));
59           Add(newItem);
60         }
61       }
62     }
63   }
64 
65   file.Close();
66   return true;
67 }
68 
69