Skip to content

Commit

Permalink
Added Playlist data pulling and fixed stream opening in vlc.
Browse files Browse the repository at this point in the history
  • Loading branch information
primetime43 committed Aug 29, 2021
1 parent 02c9226 commit 9b449ea
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 15 deletions.
41 changes: 39 additions & 2 deletions X-IPTV/ChannelList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,46 @@ private void ChannelLst_SelectionChanged(object sender, SelectionChangedEventArg

ChannelEntry entry = e.AddedItems[0] as ChannelEntry;

ProcessStartInfo processStartInfo = new ProcessStartInfo(@"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe", $"http://iptv-pure.com:8000/live/sabihi/ek5jkfngrf/{entry.stream_id}.m3u8");

Process.Start(processStartInfo);
Console.WriteLine(Instance.playlistDataMap[entry.stream_id.ToString()].stream_url);

/*Console.WriteLine("Channel Info:");
Console.WriteLine(entry.name);
Console.WriteLine(entry.stream_id);
Console.WriteLine(UnixTimeStampToDateTime(Convert.ToDouble(entry.added)));*/

//ProcessStartInfo processStartInfo = new ProcessStartInfo(@"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe", $"https://iptv-pure.com:8000/live/sabihi/ek5jkfngrf/{entry.stream_id}.m3u8");

ProcessStartInfo processStartInfo = new ProcessStartInfo(@"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe", Instance.playlistDataMap[entry.stream_id.ToString()].stream_url);

string urlTest = Instance.playlistDataMap[entry.stream_id.ToString()].stream_url;


ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.Arguments = $"/C \"C:/Program Files (x86)/VideoLAN/VLC/vlc.exe\" {urlTest}";
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;

Process processTemp = new Process();
processTemp.StartInfo = startInfo;
processTemp.EnableRaisingEvents = true;
processTemp.Start();

//works
//string command = $"/C \"C:/Program Files (x86)/VideoLAN/VLC/vlc.exe\" {urlTest}";
//Process.Start("cmd.exe", command);

}

private static DateTime UnixTimeStampToDateTime(double unixTimeStamp)
{
// Unix timestamp is seconds past epoch
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dateTime = dateTime.AddSeconds(unixTimeStamp).ToLocalTime();
return dateTime;
}
}

Expand Down
8 changes: 8 additions & 0 deletions X-IPTV/ChannelsArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ public class ChannelEntry
public object tv_archive_duration { get; set; }
}

public class PlaylistData
{
public string xui_id { get; set; }
public string stream_url { get; set; }
/*public string tvg_name { get; set; }
public string tvg_logo { get; set; }
public string group_title { get; set; }*/
}
}
4 changes: 4 additions & 0 deletions X-IPTV/Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ public static class Instance
public static PlayerInfo PlayerInfo = null;

public static ChannelEntry[] ChannelsArray = null;

//public static PlaylistData[] PlaylistArray = null;

public static Dictionary<string, PlaylistData> playlistDataMap = null;
}
}
4 changes: 2 additions & 2 deletions X-IPTV/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
[assembly: AssemblyTitle("X-IPTV")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP Inc.")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("X-IPTV")]
[assembly: AssemblyCopyright("Copyright © HP Inc. 2019")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
8 changes: 4 additions & 4 deletions X-IPTV/UserLogin.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ xmlns:xctw="clr-namespace:Xceed.Wpf.Toolkit.Themes.Windows10;assembly=Xceed.Wpf.
<Label Content="Password:" HorizontalAlignment="Left" Margin="267,146,0,0" VerticalAlignment="Top"/>
<Label Content="Server:" HorizontalAlignment="Left" Margin="267,176,0,0" VerticalAlignment="Top"/>
<Label Content="Port:" HorizontalAlignment="Left" Margin="267,207,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="usrTxt" HorizontalAlignment="Left" Height="23" Margin="363,119,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="passTxt" HorizontalAlignment="Left" Height="23" Margin="363,150,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="serverTxt" HorizontalAlignment="Left" Height="23" Margin="363,180,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="portTxt" HorizontalAlignment="Left" Height="23" Margin="363,211,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="usrTxt" HorizontalAlignment="Left" Height="23" Margin="363,119,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="passTxt" HorizontalAlignment="Left" Height="23" Margin="363,150,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="serverTxt" HorizontalAlignment="Left" Height="23" Margin="363,180,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="portTxt" HorizontalAlignment="Left" Height="23" Margin="363,211,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<Button x:Name="con_btn" Content="Connect" HorizontalAlignment="Left" Margin="301,270,0,0" VerticalAlignment="Top" Width="143" Height="25" Click="Con_btn_Click"/>
<xc:BusyIndicator x:Name="busy_ind" IsBusy="False" BusyContent="Authenticating...">
<CheckBox x:Name="protocolCheckBox" Content="HTTPS" HorizontalAlignment="Left" Height="20" Margin="495,185,0,0" VerticalAlignment="Top" Width="90" ToolTip="HTTP will be used by default if not checked"/>
Expand Down
54 changes: 47 additions & 7 deletions X-IPTV/UserLogin.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
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.Shapes;

namespace X_IPTV
{
Expand All @@ -39,6 +34,11 @@ private async void Con_btn_Click(object sender, RoutedEventArgs e)

var channelWindow = new ChannelList();

//load epg. Eventually make it optional
busy_ind.BusyContent = "Loading playlist data...";

await LoadPlaylistData(usrTxt.Text, passTxt.Text, serverTxt.Text, portTxt.Text);

channelWindow.Show();

this.Close();
Expand Down Expand Up @@ -109,5 +109,45 @@ private async Task LoadChannels(string user, string pass, string server, string
dataStream.Close();
response.Close();
}

private static readonly HttpClient client = new HttpClient();
private async Task LoadPlaylistData(string user, string pass, string server, string port)
{
//retrieve playlist data from client
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36");

var stringTask = client.GetStringAsync($"https://{server}:{port}/get.php?username={user}&password={pass}");

var msg = await stringTask;
//Console.Write(msg);

//parse the m3u playlist and split into an array
string[] playlist = msg.Split(new string[] { "#EXTINF:" }, StringSplitOptions.None);

//needs cleaned up
PlaylistData[] info = new PlaylistData[Instance.ChannelsArray.Length];
int index = -1;
Instance.playlistDataMap = new Dictionary<string, PlaylistData>();
foreach (var channel in playlist)
{
//Console.WriteLine($"#EXTINF:{channel}");
if (index > -1)
{
//eventually fix this, make the split better and use all of the data in the PlaylistData class
string[] splitArr = channel.Split(' ');
string xui_id = "";
foreach (Match match in Regex.Matches(splitArr[1], "\"([^\"]*)\""))
xui_id = match.ToString().Replace("\"", "");
info[index] = new PlaylistData {
xui_id = xui_id,
stream_url = channel.Substring(channel.LastIndexOf("https"))
};
Instance.playlistDataMap.Add(info[index].xui_id, info[index]);
}
index++;
}
Console.WriteLine("Done.");
}
}
}
27 changes: 27 additions & 0 deletions X-IPTV/X-IPTV.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -152,5 +167,17 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.7.2 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

0 comments on commit 9b449ea

Please sign in to comment.