Skip to content

Commit

Permalink
Support m3u8 playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
complexlogic committed Nov 6, 2022
1 parent 1229168 commit fb77fb1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
3 changes: 1 addition & 2 deletions xbmc/music/windows/GUIWindowMusicPlaylist.cpp
Expand Up @@ -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",
Expand Down
12 changes: 8 additions & 4 deletions xbmc/music/windows/GUIWindowMusicPlaylistEditor.cpp
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions xbmc/playlists/PlayListFactory.cpp
Expand Up @@ -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")
Expand Down Expand Up @@ -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");
}

19 changes: 15 additions & 4 deletions xbmc/playlists/PlayListM3U.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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<ssize_t>(strLine.size()))
Expand All @@ -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<ssize_t>(strLine.size()))
return; // error
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/windows/GUIWindowVideoPlaylist.cpp
Expand Up @@ -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",
Expand Down

0 comments on commit fb77fb1

Please sign in to comment.