Skip to content

Commit c986855

Browse files
committed
支持打开千千静听播放列表
1 parent 4523d44 commit c986855

6 files changed

Lines changed: 52 additions & 1 deletion

File tree

MusicPlayer2/FilterHelper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ wstring FilterHelper::GetPlaylistSelectFilter()
4949
filter += theApp.m_str_table.LoadText(L"TXT_FILTER_M3U_FILE") + L"|*.m3u|";
5050
filter += theApp.m_str_table.LoadText(L"TXT_FILTER_M3U8_FILE") + L"|*.m3u8|";
5151
filter += theApp.m_str_table.LoadText(L"TXT_FILTER_WPL_FILE") + L"|*.wpl|";
52+
filter += theApp.m_str_table.LoadText(L"TXT_FILTER_TTPL_FILE") + L"|*.ttpl|";
5253
filter += theApp.m_str_table.LoadText(L"TXT_FILTER_ALL_FILES") + L"|*.*||";
5354
return filter;
5455
}

MusicPlayer2/Playlist.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "SongDataManager.h"
66
#include "TinyXml2Helper.h"
77

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"};
99

1010
/*
1111
播放列表文件格式说明
@@ -48,6 +48,10 @@ void CPlaylistFile::LoadFromFile(const wstring & file_path)
4848
{
4949
ParseWplFile(file_content);
5050
}
51+
else if (file_extension == L"ttpl")
52+
{
53+
ParseTtplFile(file_content);
54+
}
5155
else
5256
{
5357
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)
327331
}
328332
}
329333
}
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+
}

MusicPlayer2/Playlist.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ class CPlaylistFile
3131
const static vector<wstring> m_surpported_playlist; //支持的播放列表文件的扩展名列表
3232

3333
protected:
34+
//解析MusicPlayer2播放列表
3435
void ParsePlaylistFile(const std::wstring& file_contents);
36+
//解析m3u/m3u8格式播放列表
3537
void ParseM3uFile(const std::wstring& file_contents);
38+
//解析Windows Media Player播放列表
3639
void ParseWplFile(const std::string& file_contents);
40+
//解析千千静听播放列表
41+
void ParseTtplFile(const std::string& file_contents);
3742

3843
private:
3944
vector<SongInfo> m_playlist;

MusicPlayer2/language/English.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ TXT_FILTER_PLAYLIST_FILE = "MusicPlayer2 playlist files"
362362
TXT_FILTER_M3U_FILE = "m3u playlist files"
363363
TXT_FILTER_M3U8_FILE = "m3u8 playlist files"
364364
TXT_FILTER_WPL_FILE = "Windows Media Player playlist files"
365+
TXT_FILTER_TTPL_FILE = "TTPlayer playlist files"
365366
TXT_FILTER_IMAGE_FILE = "Image files"
366367

367368
# CSearchEditCtrl

MusicPlayer2/language/Simplified_Chinese.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ TXT_FILTER_PLAYLIST_FILE = "MusicPlayer2播放列表文件"
363363
TXT_FILTER_M3U_FILE = "m3u播放列表文件"
364364
TXT_FILTER_M3U8_FILE = "m3u8播放列表文件"
365365
TXT_FILTER_WPL_FILE = "Windows Media Player 播放列表文件"
366+
TXT_FILTER_TTPL_FILE = "千千静听播放列表文件"
366367
TXT_FILTER_IMAGE_FILE = "图片文件"
367368

368369
# CSearchEditCtrl

MusicPlayer2/language/Traditional_Chinese.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ TXT_FILTER_PLAYLIST_FILE = "MusicPlayer2播放清單檔案"
362362
TXT_FILTER_M3U_FILE = "m3u播放清單檔案"
363363
TXT_FILTER_M3U8_FILE = "m3u8播放清單檔案"
364364
TXT_FILTER_WPL_FILE = "Windows Media Player 播放清單檔案"
365+
TXT_FILTER_TTPL_FILE = "千千靜聽播放清單檔案"
365366
TXT_FILTER_IMAGE_FILE = "圖片檔案"
366367

367368
# CSearchEditCtrl

0 commit comments

Comments
 (0)