Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using Vlc.DotNet.Forms;
- namespace IPTVValidator
- {
- public class IPTVValidatorForm : Form
- {
- private VlcControl vlcControl;
- public IPTVValidatorForm()
- {
- InitializeComponents();
- }
- private void InitializeComponents()
- {
- // Initialize VLC control
- vlcControl = new VlcControl();
- Controls.Add(vlcControl);
- }
- public List<string> GetValidURLs(string filePath)
- {
- if (!File.Exists(filePath))
- {
- throw new FileNotFoundException("M3U file not found.", filePath);
- }
- List<string> validURLs = new List<string>();
- string[] lines = File.ReadAllLines(filePath);
- foreach (string line in lines)
- {
- if (line.StartsWith("#EXTINF:"))
- {
- string url = lines.FirstOrDefault(l => !l.StartsWith("#") && !string.IsNullOrWhiteSpace(l));
- if (!string.IsNullOrEmpty(url))
- {
- if (ValidateURL(url))
- {
- validURLs.Add(line);
- validURLs.Add(url);
- }
- }
- }
- }
- return validURLs;
- }
- private bool ValidateURL(string url)
- {
- // Use VLC DotNet Forms to check if the URL is valid
- try
- {
- vlcControl.SetMedia(new Uri(url));
- return true;
- }
- catch
- {
- return false;
- }
Add Comment
Please, Sign In to add comment