From fb77fb14845f053929e5adcddd81c584d13a7d73 Mon Sep 17 00:00:00 2001 From: complexlogic Date: Sat, 5 Nov 2022 22:32:12 -0700 Subject: [PATCH] Support m3u8 playlists --- xbmc/music/windows/GUIWindowMusicPlaylist.cpp | 3 +-- .../windows/GUIWindowMusicPlaylistEditor.cpp | 12 ++++++++---- xbmc/playlists/PlayListFactory.cpp | 6 +++--- xbmc/playlists/PlayListM3U.cpp | 19 +++++++++++++++---- xbmc/video/windows/GUIWindowVideoPlaylist.cpp | 2 +- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/xbmc/music/windows/GUIWindowMusicPlaylist.cpp b/xbmc/music/windows/GUIWindowMusicPlaylist.cpp index acc46f6b82046..87afafa240011 100644 --- a/xbmc/music/windows/GUIWindowMusicPlaylist.cpp +++ b/xbmc/music/windows/GUIWindowMusicPlaylist.cpp @@ -305,9 +305,8 @@ void CGUIWindowMusicPlayList::SavePlayList() std::string strNewFileName; if (CGUIKeyboardFactory::ShowAndGetInput(strNewFileName, CVariant{g_localizeStrings.Get(16012)}, false)) { - // need 2 rename it strNewFileName = CUtil::MakeLegalFileName(strNewFileName); - strNewFileName += ".m3u"; + strNewFileName += ".m3u8"; std::string strPath = URIUtils::AddFileToFolder( CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_SYSTEM_PLAYLISTSPATH), "music", diff --git a/xbmc/music/windows/GUIWindowMusicPlaylistEditor.cpp b/xbmc/music/windows/GUIWindowMusicPlaylistEditor.cpp index 393923d32611e..e4b69aa7252c6 100644 --- a/xbmc/music/windows/GUIWindowMusicPlaylistEditor.cpp +++ b/xbmc/music/windows/GUIWindowMusicPlaylistEditor.cpp @@ -342,7 +342,7 @@ void CGUIWindowMusicPlaylistEditor::OnLoadPlaylist() // Prompt user for file to load from music playlists folder std::string playlist; if (CGUIDialogFileBrowser::ShowAndGetFile("special://musicplaylists/", - ".m3u|.pls|.b4s|.wpl|.xspf", g_localizeStrings.Get(656), + ".m3u|.m3u8|.pls|.b4s|.wpl|.xspf", g_localizeStrings.Get(656), playlist)) LoadPlaylist(playlist); } @@ -371,16 +371,20 @@ void CGUIWindowMusicPlaylistEditor::OnSavePlaylist() { // saves playlist to the playlist folder std::string name = URIUtils::GetFileName(m_strLoadedPlaylist); - URIUtils::RemoveExtension(name); + std::string extension = URIUtils::GetExtension(m_strLoadedPlaylist); + if (extension.empty()) + extension = ".m3u8"; + else + URIUtils::RemoveExtension(name); if (CGUIKeyboardFactory::ShowAndGetInput(name, CVariant{g_localizeStrings.Get(16012)}, false)) - { // save playlist as an .m3u + { PLAYLIST::CPlayListM3U playlist; playlist.Add(*m_playlist); std::string path = URIUtils::AddFileToFolder( CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_SYSTEM_PLAYLISTSPATH), "music", - name + ".m3u"); + name + extension); playlist.Save(path); m_strLoadedPlaylist = name; diff --git a/xbmc/playlists/PlayListFactory.cpp b/xbmc/playlists/PlayListFactory.cpp index 8abb1bae9254a..dc45bcce2d8dd 100644 --- a/xbmc/playlists/PlayListFactory.cpp +++ b/xbmc/playlists/PlayListFactory.cpp @@ -71,7 +71,7 @@ CPlayList* CPlayListFactory::Create(const CFileItem& item) std::string extension = URIUtils::GetExtension(path); StringUtils::ToLower(extension); - if (extension == ".m3u" || extension == ".strm") + if (extension == ".m3u" || (extension == ".m3u8" && !item.IsInternetStream()) || extension == ".strm") return new CPlayListM3U(); if (extension == ".pls") @@ -134,12 +134,12 @@ bool CPlayListFactory::IsPlaylist(const CFileItem& item) bool CPlayListFactory::IsPlaylist(const CURL& url) { return URIUtils::HasExtension(url, - ".m3u|.b4s|.pls|.strm|.wpl|.asx|.ram|.url|.pxml|.xspf"); + ".m3u|.m3u8|.b4s|.pls|.strm|.wpl|.asx|.ram|.url|.pxml|.xspf"); } bool CPlayListFactory::IsPlaylist(const std::string& filename) { return URIUtils::HasExtension(filename, - ".m3u|.b4s|.pls|.strm|.wpl|.asx|.ram|.url|.pxml|.xspf"); + ".m3u|.m3u8|.b4s|.pls|.strm|.wpl|.asx|.ram|.url|.pxml|.xspf"); } diff --git a/xbmc/playlists/PlayListM3U.cpp b/xbmc/playlists/PlayListM3U.cpp index d39cdce086057..8853a31275d84 100644 --- a/xbmc/playlists/PlayListM3U.cpp +++ b/xbmc/playlists/PlayListM3U.cpp @@ -69,6 +69,10 @@ bool CPlayListM3U::Load(const std::string& strFileName) int iStartOffset = 0; int iEndOffset = 0; + bool utf8 = false; + if (URIUtils::GetExtension(strFileName) == ".m3u8") + utf8 = true; + Clear(); m_strPlayListName = URIUtils::GetFileName(strFileName); @@ -101,7 +105,8 @@ bool CPlayListM3U::Load(const std::string& strFileName) lDuration = atoi(strLength.c_str()); iComma++; strInfo = strLine.substr(iComma); - g_charsetConverter.unknownToUTF8(strInfo); + if (!utf8) + g_charsetConverter.unknownToUTF8(strInfo); } } else if (StringUtils::StartsWith(strLine, OffsetMarker)) @@ -150,7 +155,8 @@ bool CPlayListM3U::Load(const std::string& strFileName) if (strFileName.length() > 0) { - g_charsetConverter.unknownToUTF8(strFileName); + if (!utf8) + g_charsetConverter.unknownToUTF8(strFileName); // If no info was read from from the extended tag information, use the file name if (strInfo.length() == 0) @@ -211,6 +217,9 @@ void CPlayListM3U::Save(const std::string& strFileName) const { if (!m_vecItems.size()) return; + bool utf8 = false; + if (URIUtils::GetExtension(strFileName) == ".m3u8") + utf8 = true; std::string strPlaylist = CUtil::MakeLegalPath(strFileName); CFile file; if (!file.OpenForWrite(strPlaylist,true)) @@ -226,7 +235,8 @@ void CPlayListM3U::Save(const std::string& strFileName) const { CFileItemPtr item = m_vecItems[i]; std::string strDescription=item->GetLabel(); - g_charsetConverter.utf8ToStringCharset(strDescription); + if (!utf8) + g_charsetConverter.utf8ToStringCharset(strDescription); strLine = StringUtils::Format("{}:{},{}\n", InfoMarker, item->GetMusicInfoTag()->GetDuration(), strDescription); if (file.Write(strLine.c_str(), strLine.size()) != static_cast(strLine.size())) @@ -238,7 +248,8 @@ void CPlayListM3U::Save(const std::string& strFileName) const file.Write(strLine.c_str(),strLine.size()); } std::string strFileName = ResolveURL(item); - g_charsetConverter.utf8ToStringCharset(strFileName); + if (!utf8) + g_charsetConverter.utf8ToStringCharset(strFileName); strLine = StringUtils::Format("{}\n", strFileName); if (file.Write(strLine.c_str(), strLine.size()) != static_cast(strLine.size())) return; // error diff --git a/xbmc/video/windows/GUIWindowVideoPlaylist.cpp b/xbmc/video/windows/GUIWindowVideoPlaylist.cpp index 197ca3015ccfd..36539ee463d37 100644 --- a/xbmc/video/windows/GUIWindowVideoPlaylist.cpp +++ b/xbmc/video/windows/GUIWindowVideoPlaylist.cpp @@ -399,7 +399,7 @@ void CGUIWindowVideoPlaylist::SavePlayList() { // need 2 rename it strNewFileName = CUtil::MakeLegalFileName(strNewFileName); - strNewFileName += ".m3u"; + strNewFileName += ".m3u8"; std::string strPath = URIUtils::AddFileToFolder( CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_SYSTEM_PLAYLISTSPATH), "video",