Add project files.

This commit is contained in:
Vova
2024-01-15 07:49:55 +02:00
parent 0f23024c49
commit df51ee3ad6
56 changed files with 1766 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
<Application x:Class="TV_Player.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TV_Player"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
+14
View File
@@ -0,0 +1,14 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace TV_Player
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
+10
View File
@@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

+22
View File
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace TV_Player
{
public class EnumToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value.Equals(parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value.Equals(true) ? parameter : Binding.DoNothing;
}
}
}
+27
View File
@@ -0,0 +1,27 @@
<UserControl x:Class="TV_Player.GroupButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TV_Player"
mc:Ignorable="d"
d:DesignHeight="100" d:DesignWidth="200">
<Viewbox Grid.Row="1">
<Grid x:Name="ButtonBorder" Height="70" Width="150" >
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="0.4*"/>
</Grid.RowDefinitions>
<Rectangle RadiusX="15" RadiusY="15" x:Name="Border" StrokeThickness="3" Stroke="Yellow" Stretch="Fill" Grid.RowSpan="2" Fill="#FF1F1E1E"/>
<TextBlock x:Name="groupName" Text="Group name" FontSize="15" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="1" FontSize="10" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" LineStackingStrategy="BlockLineHeight" LineHeight="10">
<Run x:Name="programsFound"/>
<Run>Programs</Run>
</TextBlock>
</Grid>
</Grid>
</Viewbox>
</UserControl>
+17
View File
@@ -0,0 +1,17 @@
using System.Windows.Controls;
namespace TV_Player
{
/// <summary>
/// Interaction logic for GroupButton.xaml
/// </summary>
public partial class GroupButton : UserControl
{
public GroupButton(string groupName,int programsFound)
{
InitializeComponent();
this.groupName.Text = groupName;
this.programsFound.Text = programsFound.ToString();
}
}
}
+14
View File
@@ -0,0 +1,14 @@
namespace TV_Player
{
public class M3UInfo
{
public string CUID { get; set; }
public string Number { get; set; }
public string TvgID { get; set; }
public string TvgName { get; set; }
public string GroupTitle { get; set; }
public string Logo { get; set; }
public string Name{ get; set; }
public string Url { get; set; }
}
}
+101
View File
@@ -0,0 +1,101 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.RegularExpressions;
namespace TV_Player
{
public static class M3UParser
{
public static async Task<List<M3UInfo>> DownloadM3UFromWebAsync(string url)
{
List<M3UInfo> playlistItems = new List<M3UInfo>();
using (var client = new HttpClient())
using (var request = new HttpRequestMessage())
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/text"));
request.Method = HttpMethod.Get;
request.RequestUri = new Uri(url);
var response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
// Parse M3U content
playlistItems = ParseM3UFromString(responseBody);
}
return playlistItems;
}
static string[] SplitStringBeforeSeparator(string input, string separator)
{
string[] parts = input.Split(separator);
// Reconstruct the string until the separator is reached
int separatorIndex = input.IndexOf(separator);
if (separatorIndex != -1)
{
parts[0] = input.Substring(0, separatorIndex + 1);
for (int i = 1; i < parts.Length; i++)
{
parts[i] = separator + parts[i];
}
}
return parts;
}
static List<M3UInfo> ParseM3UFromString(string content)
{
List<M3UInfo> playlistItems = new List<M3UInfo>();
try
{
var m3u = SplitStringBeforeSeparator(content, "#EXT");
foreach (var line in m3u)
{
if (line.StartsWith("#EXTINF:"))
{
if (TryParseM3ULine(line, out var m3uInfo))
{
playlistItems.Add(m3uInfo);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error reading M3U file: " + ex.Message);
}
return playlistItems;
}
static bool TryParseM3ULine(string m3uLine, out M3UInfo? info)
{
info = null;
string pattern = @"#EXTINF:\d+ CUID=""(?<CUID>.*?)"" number=""(?<Number>.*?)"" tvg-id=""(?<TvgID>.*?)"" tvg-name=""(?<TvgName>.*?)"".*?tvg-logo=""(?<Logo>.*?)"" group-title=""(?<GroupTitle>.*?)""[^,]*,(?<Name>.*)[^\r](?<URL>.*)$";
Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
Match match = regex.Match(m3uLine);
if (match.Success)
{
info = new M3UInfo
{
CUID = match.Groups["CUID"].Value,
Number = match.Groups["Number"].Value,
TvgID = match.Groups["TvgID"].Value,
TvgName = match.Groups["TvgName"].Value,
GroupTitle = match.Groups["GroupTitle"].Value,
Logo = match.Groups["Logo"].Value,
Name = match.Groups["Name"].Value,
Url = match.Groups["Url"].Value
};
return true;
}
return false;
}
}
}
+18
View File
@@ -0,0 +1,18 @@
<Window x:Class="TV_Player.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TV_Player"
mc:Ignorable="d"
Title="TV" Height="450" Width="800">
<Window.Resources>
<local:EnumToBooleanConverter x:Key="EnumToBooleanConverter" />
</Window.Resources>
<Grid>
<Grid.Background>
<ImageBrush ImageSource="Assets/bkground.jpg" />
</Grid.Background>
<ContentControl Name="ControlContainer" />
</Grid>
</Window>
+102
View File
@@ -0,0 +1,102 @@
using System.ComponentModel;
using System.Data.Common;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using Vlc.DotNet.Wpf;
namespace TV_Player
{
public partial class MainWindow : Window
{
private readonly DirectoryInfo vlcLibDirectory;
private VlcControl control;
public MainWindow()
{
InitializeComponent();
var currentAssembly = Assembly.GetEntryAssembly();
var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
// Default installation path of VideoLAN.LibVLC.Windows
vlcLibDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));
this.control = new VlcControl();
this.control.SourceProvider.CreatePlayer(vlcLibDirectory/* pass your player parameters here */);
Initialize();
}
protected override void OnClosing(CancelEventArgs e)
{
this.control?.Dispose();
base.OnClosing(e);
}
private void OnPlayButtonClick(object sender, RoutedEventArgs e)
{
//this.control?.Dispose();
//this.control = new VlcControl();
//this.ControlContainer.Content = this.control;
//this.control.SourceProvider.CreatePlayer(this.vlcLibDirectory);
// This can also be called before EndInit
this.control.SourceProvider.MediaPlayer.Log += (_, args) =>
{
string message = $"libVlc : {args.Level} {args.Message} @ {args.Module}";
System.Diagnostics.Debug.WriteLine(message);
};
control.SourceProvider.MediaPlayer.Play(new Uri("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi"));
}
private void OnStopButtonClick(object sender, RoutedEventArgs e)
{
this.control?.Dispose();
this.control = null;
}
private void OnForwardButtonClick(object sender, RoutedEventArgs e)
{
if (this.control == null)
{
return;
}
this.control.SourceProvider.MediaPlayer.Rate = 2;
}
private void GetLength_Click(object sender, RoutedEventArgs e)
{
if (this.control == null)
{
return;
}
//GetLength.Content = this.control.SourceProvider.MediaPlayer.Length + " ms";
}
private void GetCurrentTime_Click(object sender, RoutedEventArgs e)
{
if (this.control == null)
{
return;
}
//GetCurrentTime.Content = this.control.SourceProvider.MediaPlayer.Time + " ms";
}
private void SetCurrentTime_Click(object sender, RoutedEventArgs e)
{
if (this.control == null)
{
return;
}
this.control.SourceProvider.MediaPlayer.Time = 5000;
//SetCurrentTime.Content = this.control.SourceProvider.MediaPlayer.Time + " ms";
}
}
}
+43
View File
@@ -0,0 +1,43 @@
using System.Windows.Controls;
namespace TV_Player
{
public class MainWindowViewModel
{
public MainWindowViewModel()
{
}
private async Task Initialize()
{
string m3uLink = "http://pl.da-tv.vip/a71e77fa/835b3216/tv.m3u";
var programs = await M3UParser.DownloadM3UFromWebAsync(m3uLink);
var groupedPrograms = programs.GroupBy(item => item.GroupTitle)
.ToDictionary(
group => group.Key,
group => group.Select(item => item).ToList()
);
var row = 0;
var column = 0;
foreach (var group in groupedPrograms)
{
var button = new GroupButton(group.Key, group.Value.Count());
button.TouchDown += (s, e) =>
{
};
Grid.SetRow(button, row);
Grid.SetColumn(button, column);
groupsGrid.Children.Add(button);
column++;
if (column > 4)
{
row++;
column = 0;
}
}
}
}
}
+23
View File
@@ -0,0 +1,23 @@
<UserControl x:Class="TV_Player.ProgramsGroupGrid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TV_Player"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid x:Name="groupsGrid" Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
</Grid>
</UserControl>
+28
View File
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TV_Player
{
/// <summary>
/// Interaction logic for ProgramsGroupGrid.xaml
/// </summary>
public partial class ProgramsGroupGrid : UserControl
{
public ProgramsGroupGrid()
{
InitializeComponent();
}
}
}
+29
View File
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<RootNamespace>TV_Player</RootNamespace>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<None Remove="Assets\bkGround.jpg" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.20" />
<PackageReference Include="Vlc.DotNet.Wpf" Version="3.1.0" />
<PackageReference Include="WPFMediaKitCore" Version="0.0.3" />
</ItemGroup>
<ItemGroup>
<Resource Include="Assets\bkground.jpg">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Resource>
</ItemGroup>
</Project>