Skip to content

Commit

Permalink
support title m3u
Browse files Browse the repository at this point in the history
  • Loading branch information
dav1977 committed Aug 1, 2021
1 parent 223fd1d commit 12e9774
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 76 deletions.
1 change: 1 addition & 0 deletions IPTVmanager/Model/data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static class data
public static int ping_all = 0;
public static int ping_waiting = 0;
public static bool flag_adding_ok = false;
public static string Title = "";

public static void set_best()
{
Expand Down
15 changes: 8 additions & 7 deletions IPTVmanager/UserClass/FileWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@ public void SAVE(List<IPTVman.Model.ParamCanal> lst, string title)
{
using (StreamWriter sr = new StreamWriter(openFileDialog.FileName))
{
sr.Write(title + '\n');
//TITLE
if (title!="") sr.Write("#EXTM3U "+title + '\n');

string n = "";
foreach (var obj in lst)
{
n = "";
if (title == @"#EXTM3U $BorpasFileFormat=" + '"' + '1' + '"') n += "#EXTINF:-1";
if (title == @"$BorpasFileFormat=" + '"' + '1' + '"') n += "#EXTINF:-1";
else n += "#EXTINF:0";

if (obj.ExtFilter != "") n += " $ExtFilter=" + '"' + obj.ExtFilter + '"';
Expand Down Expand Up @@ -158,9 +159,8 @@ public void SAVE(List<IPTVman.Model.ParamCanal> lst, string title)
/// <param name="_text_title"></param>
/// <param name="_chek1"></param>
/// <param name="_chek2"></param>
public async void LOAD(string path, List<ParamCanal> lst, string _text_title, bool _chek1, bool _chek2)
public async void LOAD(string path, List<ParamCanal> lst, bool _chek1, bool _chek2)
{
Parse.text_title = _text_title;
Parse.chek_update = _chek1;
Parse.chek_hoop = _chek2;

Expand All @@ -174,12 +174,13 @@ public async void LOAD(string path, List<ParamCanal> lst, string _text_title, bo
{
name = openFileDialog.FileName;
}
else { loc.openfile = false; return; }
else { loc.openfile = false; return; }
}
else name = path;

pathM3u = name;
await AsyncOPEN(lst, name);

}

public async void LOAD(List<IPTVman.Model.ParamCanal> lst, string namefile)
Expand All @@ -202,7 +203,7 @@ public async Task<string> AsyncOPEN(List<ParamCanal> lst, string name)
try
{
loc.asyncOPEN = true;
Wait.Create("Идет анализ файла ", true);
Wait.Create("Анализ файла ...", true);

if (name != null)
{
Expand All @@ -219,7 +220,7 @@ public async Task<string> AsyncOPEN(List<ParamCanal> lst, string name)
else loc.openfile = false;

Thread.Sleep(300);

Wait.Close();

Script.ResetMODEApplication();
Expand Down
97 changes: 43 additions & 54 deletions IPTVmanager/UserClass/Parse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,14 @@ public Parse(bool curr, string ex)
current_mode = curr;//работа с режимом поиска скриптов или без
}


string name = "no";
bool current_mode = mode.with_command;
uint ct_dublicat = 0;
uint ct_update = 0;
uint ct_ignore_update = 0;
List<int> list_update_channels = new List<int>();

int ctIFLE = 0;




bool analiz_str(List<ParamCanal> lst, string str, bool OFFscript, int num )
{
Expand All @@ -63,7 +60,7 @@ bool analiz_str(List<ParamCanal> lst, string str, bool OFFscript, int num )
// Debug.WriteLine("БЕЗ СКРИП СТРОКА " + num + " - " + str);

if (num < 3)
if (AnalizTYPElink(str))
if (FindLINKinLine(str))
{
}
}
Expand All @@ -72,7 +69,7 @@ bool analiz_str(List<ParamCanal> lst, string str, bool OFFscript, int num )
// Debug.WriteLine("СТРОКА " + num + " - " + str);

if (num < 3)
if (AnalizTYPElink(str))
if (FindLINKinLine(str))
{
Debug.WriteLine("@@ FIND LINK ");

Expand Down Expand Up @@ -100,41 +97,44 @@ bool analiz_str(List<ParamCanal> lst, string str, bool OFFscript, int num )
return false;
}

bool find_max_str(string file)
/// <summary>
/// //определение макс строк СКАНЕР ФАЙЛА
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
bool Find_max_str(string file)
{
int all_str = 0;
byte null_str = 0;
bool ns = false;

try
{

//определение макс строк СКАНЕР ФАЙЛА
Debug.WriteLine(name + " ===ФАЙЛСКАН=== "+ ctIFLE.ToString() + " " + file);

Regex regex_link = new Regex("http://");
Regex regex_link2 = new Regex("https://");
Regex regex1 = new Regex("#EXTINF");
Regex regex2 = new Regex("#EXTM3U");
Match match = null;

using (StreamReader sr = new StreamReader(file))
{
while (!sr.EndOfStream)
{
string rez = sr.ReadLine();
if (sr.EndOfStream) { break; }
//string rez = ReadFind_script(str, true);

if (rez != "" && rez != null)
if (new Regex("#EXTINF").Match(rez).Success) { all_str++; null_str = 0; }
else null_str++; if (null_str > 100 || all_str > 500000) { ns = true; break; }
match = regex2.Match(rez);
if (match.Success) text_title = rez;

if (new Regex("#EXTM3").Match(rez).Success)
{
var str=rez.Split(' ');
int size = str.Length-2;
data.Title = "";
if (size > 0)
{
str[0] = "";
foreach (var s in str) data.Title += s + ' ';
}
}
}
}

Debug.WriteLine(name + " ===CLOSE СКАНФАЙЛ===");

}
catch (Exception ex) { MessageBox.Show("ошибка сканирования " + ex.Message);ns = true; }

Expand All @@ -155,32 +155,21 @@ bool find_max_str(string file)
/// <param name="OFFscript"></param>
public void PARSING_FILE(List<ParamCanal> lst, string file, bool OFFscript)
{

ctIFLE++;
Debug.WriteLine("-START parsing "+name);
if (lst== null) Debug.WriteLine("-START parsing CRASH lst " + name);

string line = null;
bool skip_mes = false;

try
{
Regex regex_link = new Regex("http://");
Regex regex_link2 = new Regex("https://");
Regex regex1 = new Regex("#EXTINF");
Regex regex2 = new Regex("#EXTM3U");
Match match = null;

Wait.set_ProgressBar(100);

if ( find_max_str(file) ) goto exit_open;
if ( Find_max_str(file) ) goto exit_open;


//=========================================================
//ПОИСК каналов


Debug.WriteLine(name + " ===ФАЙЛ===" );
//ПОИСК каналов
using (StreamReader sr = new StreamReader(file))
{

Expand All @@ -205,8 +194,8 @@ public void PARSING_FILE(List<ParamCanal> lst, string file, bool OFFscript)

if (Script.CLOSE_ALL) { Debug.WriteLine("--EXIT-"); return; }

match = regex1.Match(line);
match = new Regex("#EXTINF").Match(line);

razbor_read_next(match.Success, line, match, sr, lst);


Expand Down Expand Up @@ -509,7 +498,11 @@ string ReadFind_script(string line)
}



/// <summary>
/// выявление исключений в m3u
/// </summary>
/// <param name="line"></param>
/// <returns></returns>
public static bool linkIsBad(string line)
{
if (line == "" || line == " ") return true;
Expand All @@ -525,37 +518,36 @@ public static bool linkIsBad(string line)
}

/// <summary>
///
/// true если в строке ссылка
/// </summary>
/// <param name="line">return true==link; false=file</param>
/// <returns></returns>
bool AnalizTYPElink(string line)
bool FindLINKinLine(string line)
{
Regex regex_link = new Regex("http://");
Regex regex_link2 = new Regex("https://");

if (!(new Regex("EXTM3U", RegexOptions.IgnoreCase).Match(line).Success) &&
!(new Regex("url-tvg", RegexOptions.IgnoreCase).Match(line).Success) &&
!(new Regex("#EXTSIZE:", RegexOptions.IgnoreCase).Match(line).Success) &&
!(new Regex("#EXTBG", RegexOptions.IgnoreCase).Match(line).Success) &&
!(new Regex("#EXTCTRL", RegexOptions.IgnoreCase).Match(line).Success) &&
!(new Regex("#EXTVLCOPT", RegexOptions.IgnoreCase).Match(line).Success) &&
!(new Regex("#EXTGRP", RegexOptions.IgnoreCase).Match(line).Success) &&
(regex_link.Match(line).Success || regex_link2.Match(line).Success)
!(new Regex("#EXTINF", RegexOptions.IgnoreCase).Match(line).Success) &&
!(new Regex("url-tvg", RegexOptions.IgnoreCase).Match(line).Success) &&
!(new Regex("#EXTSIZE:", RegexOptions.IgnoreCase).Match(line).Success) &&
!(new Regex("#EXTBG", RegexOptions.IgnoreCase).Match(line).Success) &&
!(new Regex("#EXTCTRL", RegexOptions.IgnoreCase).Match(line).Success) &&
!(new Regex("#EXTVLCOPT", RegexOptions.IgnoreCase).Match(line).Success) &&
!(new Regex("#EXTGRP", RegexOptions.IgnoreCase).Match(line).Success) &&
(regex_link.Match(line).Success || regex_link2.Match(line).Success)
) return true;
return false;
}

public string ANALIZ_LINE(string line, out bool typelink)
{
string rezult = line;
Regex regex_link = new Regex("http://");
Regex regex_link2 = new Regex("https://");
typelink = true;

if (linkIsBad(line)) return FileWork.Get_m3uPath() + rezult;

if (AnalizTYPElink(line))
if (FindLINKinLine(line))
{
Debug.WriteLine("find link >>>" + line);
rezult = data.temppath;
Expand All @@ -569,7 +561,6 @@ public string ANALIZ_LINE(string line, out bool typelink)


public static bool chek_update = false, chek_hoop = true;
public static string text_title = "";
public static List<ParamCanal> wblst;


Expand All @@ -581,10 +572,8 @@ public string ANALIZ_LINE(string line, out bool typelink)
/// <param name="str"></param>
public void OPEN_FROM_CLIPBOARD(List<ParamCanal> lst, string[] str)
{

if (str == null) { dialog.Show("Буфер пустой"); return; }
Regex regex1 = new Regex("#EXTINF");
Regex regex2 = new Regex("#EXTM3U");


if (str.Length == 1) //web ссылка
{
Expand Down
17 changes: 15 additions & 2 deletions IPTVmanager/View/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@

<!-- </ScrollViewer>-->
<TextBox x:Name="tb1" Text="новый канал" Margin="0,0,111,-42" TextChanged="tb1_TextChanged" Width="102" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Row="3" Height="21" Grid.Column="2" Grid.ColumnSpan="2"/>
<TextBox x:Name="text_title" Text="{Binding text_title}" Margin="244,-100,0,0" Width="519" HorizontalAlignment="Left" VerticalAlignment="Top" Height="20" TextChanged="text_title_TextChanged"/>
<TextBox x:Name="best1" Text="{Binding best1}" Margin="0,-114,-8,0" Width="168" HorizontalAlignment="Right" VerticalAlignment="Top" Height="22" Grid.Column="3" TextChanged="best1_TextChanged"/>
<TextBox x:Name="best2" Text="{Binding best2}" Margin="0,-87,-8,0" Width="168" HorizontalAlignment="Right" VerticalAlignment="Top" Height="22" Grid.Column="3" TextChanged="best2_TextChanged"/>

Expand Down Expand Up @@ -459,6 +458,20 @@
</LinearGradientBrush>
</Button.Foreground>
</Button>
<Label Content="Title" HorizontalAlignment="Left" Margin="224,49,0,0" VerticalAlignment="Top" Height="23"/>

<Button x:Name="button_newTITLE" Content="TITLE задать" HorizontalAlignment="Right"
Margin="0,46,674,0" VerticalAlignment="Top" Width="105" Click="button_Click_5" Height="31"/>

<TextBox x:Name="text_title" Text="{Binding text_title}" Margin="378,51,0,0" Width="457" HorizontalAlignment="Left" VerticalAlignment="Top" Height="20" TextChanged="text_title_TextChanged" RenderTransformOrigin="0.5,0.5">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform AngleY="0.247"/>
<RotateTransform/>
<TranslateTransform Y="1.121"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>

</Grid>
</Window>
6 changes: 1 addition & 5 deletions IPTVmanager/View/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,7 @@ private void Button_Click_4(object sender, RoutedEventArgs e)
bool changefav = false;
private void button_Click_5(object sender, RoutedEventArgs e)
{
changefav = true;
best1.Text = data.favorite1_1;
best2.Text = data.favorite1_2;
data.current_favorites = 1;
changefav = false;
data.Title = text_title.Text;
}

private void button_Copy_Click(object sender, RoutedEventArgs e)
Expand Down
5 changes: 2 additions & 3 deletions IPTVmanager/ViewModel/MOVE/WindowSelection.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ private void Window_Closed(object sender, EventArgs e)
{
}

string title = "selected";
//save
private void button_Click(object sender, RoutedEventArgs e)
{
Expand Down Expand Up @@ -207,13 +206,13 @@ private void button_ADD(object sender, RoutedEventArgs e)

_file = new FileWork();
_file.Task_Completed += _file_Task_Completed;
_file.LOAD("",ViewModelMain.myLISTselect, title, false, false);
_file.LOAD("",ViewModelMain.myLISTselect, false, false);

}

private void _file_Task_Completed()
{
BACK();
title = Parse.text_title;
_file = null;
loc.openfile = false;
}
Expand Down
1 change: 1 addition & 0 deletions IPTVmanager/ViewModel/ViewModelMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ void updateLIST(ParamCanal item)
private object threadLock = new object();
public void Update_collection(typefilter t)
{
text_title = data.Title;
lock (threadLock)
{
_update.UPDATE_FILTER(t, myLISTbase, myLISTfull);
Expand Down
7 changes: 2 additions & 5 deletions IPTVmanager/ViewModel/ViewModelMain_Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,8 @@ void key_OPEN(object parameter)

Script.ResetMODEApplication();
_file = new FileWork();
_file.LOAD("", ViewModelMain.myLISTfull, text_title, chek_upd, chek__hoop);
_file.LOAD("", ViewModelMain.myLISTfull, chek_upd, chek__hoop);

text_title = Parse.text_title;
loc.openfile = false;
}

Expand Down Expand Up @@ -635,9 +634,7 @@ void key_OPENEVENT(string path)
public void EVENT_OPENfinalize(string path)
{
if (_file == null) _file = new FileWork();
_file.LOAD(path, ViewModelMain.myLISTfull, text_title, chek_upd, chek__hoop);
text_title = Parse.text_title;

_file.LOAD(path, ViewModelMain.myLISTfull, chek_upd, chek__hoop);
}

}//class
Expand Down

0 comments on commit 12e9774

Please sign in to comment.