|
5 | 5 | #include "SongDataManager.h" |
6 | 6 | #include "TinyXml2Helper.h" |
7 | 7 |
|
8 | | -const vector<wstring> CPlaylistFile::m_surpported_playlist{ PLAYLIST_EXTENSION_2, L"m3u", L"m3u8", L"wpl"}; |
| 8 | +const vector<wstring> CPlaylistFile::m_surpported_playlist{ PLAYLIST_EXTENSION_2, L"m3u", L"m3u8", L"wpl", L"ttpl"}; |
9 | 9 |
|
10 | 10 | /* |
11 | 11 | 播放列表文件格式说明 |
@@ -48,6 +48,10 @@ void CPlaylistFile::LoadFromFile(const wstring & file_path) |
48 | 48 | { |
49 | 49 | ParseWplFile(file_content); |
50 | 50 | } |
| 51 | + else if (file_extension == L"ttpl") |
| 52 | + { |
| 53 | + ParseTtplFile(file_content); |
| 54 | + } |
51 | 55 | else |
52 | 56 | { |
53 | 57 | std::wstring file_content_wcs = CCommon::StrToUnicode(file_content, utf8 ? CodeType::UTF8 : CodeType::ANSI); |
@@ -327,3 +331,41 @@ void CPlaylistFile::ParseWplFile(const std::string& file_contents) |
327 | 331 | } |
328 | 332 | } |
329 | 333 | } |
| 334 | + |
| 335 | +void CPlaylistFile::ParseTtplFile(const std::string& file_contents) |
| 336 | +{ |
| 337 | + tinyxml2::XMLDocument doc; |
| 338 | + doc.Parse(file_contents.c_str(), file_contents.size()); |
| 339 | + auto* root = doc.RootElement(); |
| 340 | + if (root != nullptr) |
| 341 | + { |
| 342 | + for (tinyxml2::XMLElement* child = root->FirstChildElement(); child != nullptr; child = child->NextSiblingElement()) |
| 343 | + { |
| 344 | + std::string name = CTinyXml2Helper::ElementName(child); |
| 345 | + if (name == "items") |
| 346 | + { |
| 347 | + for (tinyxml2::XMLElement* item_element = child->FirstChildElement(); item_element != nullptr; item_element = item_element->NextSiblingElement()) |
| 348 | + { |
| 349 | + name = CTinyXml2Helper::ElementName(item_element); |
| 350 | + if (name == "item") |
| 351 | + { |
| 352 | + std::wstring file_path = CCommon::StrToUnicode(CTinyXml2Helper::ElementAttribute(item_element, "file"), CodeType::UTF8); |
| 353 | + std::wstring title = CCommon::StrToUnicode(CTinyXml2Helper::ElementAttribute(item_element, "title"), CodeType::UTF8); |
| 354 | + bool is_url = CCommon::IsURL(file_path); |
| 355 | + //如果是相对路径,则转换成绝对路径 |
| 356 | + if (!is_url) |
| 357 | + file_path = CCommon::RelativePathToAbsolutePath(file_path, CFilePathHelper(m_path).GetDir()); |
| 358 | + //绝对路径的语法检查 |
| 359 | + if (is_url || CCommon::IsPath(file_path)) |
| 360 | + { |
| 361 | + SongInfo item; |
| 362 | + item.file_path = file_path; |
| 363 | + item.title = title; |
| 364 | + m_playlist.push_back(item); |
| 365 | + } |
| 366 | + } |
| 367 | + } |
| 368 | + } |
| 369 | + } |
| 370 | + } |
| 371 | +} |
0 commit comments