From ef11fb0e696efd1c4f3f243be89ddfa97786fa4a Mon Sep 17 00:00:00 2001 From: doskabouter Date: Sun, 16 Feb 2025 16:11:37 +0100 Subject: [PATCH] Fixed MP1-5236: Add support for m3u8 files --- .../SetupTv/PlaylistSupport/PlayListFactory.cs | 4 ++-- .../SetupTv/PlaylistSupport/PlayListM3uIO.cs | 13 +++++-------- TvEngine3/TVLibrary/SetupTv/Sections/CardDvbIP.cs | 8 ++++---- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/TvEngine3/TVLibrary/SetupTv/PlaylistSupport/PlayListFactory.cs b/TvEngine3/TVLibrary/SetupTv/PlaylistSupport/PlayListFactory.cs index 03836de6658..b3cad805e6d 100644 --- a/TvEngine3/TVLibrary/SetupTv/PlaylistSupport/PlayListFactory.cs +++ b/TvEngine3/TVLibrary/SetupTv/PlaylistSupport/PlayListFactory.cs @@ -30,7 +30,7 @@ public class PlayListFactory public static IPlayListIO CreateIO(string fileName) { string extension = GetLowerCaseExtension(fileName); - if (extension == ".m3u") + if (extension == ".m3u" || extension == ".m3u8") { return new PlayListM3uIO(); } @@ -58,7 +58,7 @@ private static string GetLowerCaseExtension(string fileName) public static bool IsPlayList(string fileName) { string extension = GetLowerCaseExtension(fileName); - if (extension == ".m3u") + if (extension == ".m3u" || extension == ".m3u8") return true; if (extension == ".pls") return true; diff --git a/TvEngine3/TVLibrary/SetupTv/PlaylistSupport/PlayListM3uIO.cs b/TvEngine3/TVLibrary/SetupTv/PlaylistSupport/PlayListM3uIO.cs index 9f64ee3f038..1778e4c2333 100644 --- a/TvEngine3/TVLibrary/SetupTv/PlaylistSupport/PlayListM3uIO.cs +++ b/TvEngine3/TVLibrary/SetupTv/PlaylistSupport/PlayListM3uIO.cs @@ -22,6 +22,7 @@ using System.IO; using SetupTv; using System.Text; +using System.Text.RegularExpressions; namespace MediaPortal.Playlists { @@ -102,15 +103,11 @@ public bool Load(PlayList incomingPlaylist, string playlistFileName) private static bool ExtractM3uInfo(string trimmedLine, ref string songName, ref int lDuration) { //bool successfull; - int iColon = trimmedLine.IndexOf(":"); - int iComma = trimmedLine.IndexOf(","); - if (iColon >= 0 && iComma >= 0 && iComma > iColon) + var match = Regex.Match(trimmedLine, @"#EXTINF:(?-?\d+)(?.*),(?.+)"); + if (match.Success) { - iColon++; - string duration = trimmedLine.Substring(iColon, iComma - iColon); - iComma++; - songName = trimmedLine.Substring(iComma); - lDuration = Int32.Parse(duration); + lDuration = Int32.Parse(match.Groups["duration"].Value); + songName = match.Groups["title"].Value.Trim(); return true; } return false; diff --git a/TvEngine3/TVLibrary/SetupTv/Sections/CardDvbIP.cs b/TvEngine3/TVLibrary/SetupTv/Sections/CardDvbIP.cs index 63d109af730..bd98af3a8a4 100644 --- a/TvEngine3/TVLibrary/SetupTv/Sections/CardDvbIP.cs +++ b/TvEngine3/TVLibrary/SetupTv/Sections/CardDvbIP.cs @@ -64,10 +64,10 @@ private void Init() String tuningFolder = String.Format(@"{0}\TuningParameters\dvbip", PathManager.GetDataPath); if (Directory.Exists(tuningFolder)) { - string[] files = Directory.GetFiles(tuningFolder, "*.m3u"); + string[] files = Directory.GetFiles(tuningFolder, "*.m3u*"); foreach (string f in files) { - mpComboBoxService.Items.Add(Path.GetFileNameWithoutExtension(f)); + mpComboBoxService.Items.Add(Path.GetFileName(f)); } } mpComboBoxService.SelectedIndex = 0; @@ -169,10 +169,10 @@ private void DoScan() else { IPlayListIO playlistIO = - PlayListFactory.CreateIO(String.Format(@"{0}\TuningParameters\dvbip\{1}.m3u", PathManager.GetDataPath, + PlayListFactory.CreateIO(String.Format(@"{0}\TuningParameters\dvbip\{1}", PathManager.GetDataPath, mpComboBoxService.SelectedItem)); playlistIO.Load(playlist, - String.Format(@"{0}\TuningParameters\dvbip\{1}.m3u", PathManager.GetDataPath, + String.Format(@"{0}\TuningParameters\dvbip\{1}", PathManager.GetDataPath, mpComboBoxService.SelectedItem)); } if (playlist.Count == 0) return;