Support local file paths for M3U playlists; UI tweaks

Added support for loading M3U playlists from both web URLs and local file paths, with logic to resolve relative paths. Improved exception handling in M3UParser. Enabled toggling of window border style in fullscreen mode, with data binding for WindowStyle. Removed IsValidUrl check to allow local file sources in settings. Cleaned up usings and formatting. Removed .NET SDK version from global.json.
This commit is contained in:
2026-04-10 12:48:12 +03:00
parent a42ada7f96
commit 24ca481b64
7 changed files with 57 additions and 18 deletions
+6
View File
@@ -221,6 +221,7 @@ namespace TV_Player
{
try
{
using var client = new HttpClient();
using var request = new HttpRequestMessage();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/text"));
@@ -240,6 +241,11 @@ namespace TV_Player
System.Diagnostics.Debug.WriteLine($"Invalid URL: {url} - {ex.Message}");
throw;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Error reading file from {url}: {ex.Message}");
throw;
}
}
public static async Task<(List<M3UInfo> programList, string programGuide)> DownloadM3UFromWebAsync(string url)
+33 -2
View File
@@ -1,5 +1,10 @@
using System.Reactive;
using System;
using System.IO;
using System.Linq;
using System.Reactive;
using System.Reactive.Subjects;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace TV_Player
{
@@ -25,7 +30,33 @@ namespace TV_Player
//string m3uLink = "http://pl.da-tv.vip/a71e77fa/835b3216/tv.m3u";
try
{
var result = await M3UParser.DownloadM3UFromWebAsync(m3uLink);
// if link is a well-formed absolute URI load from web, otherwise treat as a local file path
// for relative paths try resolving against the application's base directory
var result = (programList: new List<M3UInfo>(), programGuide: string.Empty);
if (Uri.IsWellFormedUriString(m3uLink, UriKind.Absolute))
{
System.Diagnostics.Debug.WriteLine("[ProgramsData] Detected URL, downloading from web");
result = await M3UParser.DownloadM3UFromWebAsync(m3uLink);
}
else
{
// try as provided path first
var candidate = m3uLink;
if (!Path.IsPathRooted(candidate))
{
candidate = Path.Combine(AppContext.BaseDirectory ?? string.Empty, candidate);
}
if (File.Exists(candidate))
{
System.Diagnostics.Debug.WriteLine($"[ProgramsData] Detected local file, loading from disk: {candidate}");
result = await M3UParser.DownloadM3UFromWebAsync(candidate);
}
else
{
throw new FileNotFoundException($"M3U file not found: {m3uLink}");
}
}
System.Diagnostics.Debug.WriteLine($"[ProgramsData] Downloaded {result.programList.Count} programs");
programsSubject.OnNext(result.programList);