Madwin74

M3u validator

Mar 26th, 2024 (edited)
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | Source Code | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using Vlc.DotNet.Forms;
  6.  
  7. namespace IPTVValidator
  8. {
  9.     public class IPTVValidatorForm : Form
  10.     {
  11.         private VlcControl vlcControl;
  12.  
  13.         public IPTVValidatorForm()
  14.         {
  15.             InitializeComponents();
  16.         }
  17.  
  18.         private void InitializeComponents()
  19.         {
  20.             // Initialize VLC control
  21.             vlcControl = new VlcControl();
  22.             Controls.Add(vlcControl);
  23.         }
  24.  
  25.         public List<string> GetValidURLs(string filePath)
  26.         {
  27.             if (!File.Exists(filePath))
  28.             {
  29.                 throw new FileNotFoundException("M3U file not found.", filePath);
  30.             }
  31.  
  32.             List<string> validURLs = new List<string>();
  33.             string[] lines = File.ReadAllLines(filePath);
  34.  
  35.             foreach (string line in lines)
  36.             {
  37.                 if (line.StartsWith("#EXTINF:"))
  38.                 {
  39.                     string url = lines.FirstOrDefault(l => !l.StartsWith("#") && !string.IsNullOrWhiteSpace(l));
  40.                     if (!string.IsNullOrEmpty(url))
  41.                     {
  42.                         if (ValidateURL(url))
  43.                         {
  44.                             validURLs.Add(line);
  45.                             validURLs.Add(url);
  46.                         }
  47.                     }
  48.                 }
  49.             }
  50.  
  51.             return validURLs;
  52.         }
  53.  
  54.         private bool ValidateURL(string url)
  55.         {
  56.             // Use VLC DotNet Forms to check if the URL is valid
  57.             try
  58.             {
  59.                 vlcControl.SetMedia(new Uri(url));
  60.                 return true;
  61.             }
  62.             catch
  63.             {
  64.                 return false;
  65.             }
Add Comment
Please, Sign In to add comment