MainForm.cs
author StephaneLenclud
Sat, 06 Oct 2018 14:07:31 +0200
changeset 9 b77b09f680e7
parent 7 bf908f6c7758
permissions -rw-r--r--
SatIndex grabber now working.
     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.Linq;
     7 using System.Text;
     8 using System.Threading.Tasks;
     9 using System.Windows.Forms;
    10 using CsQuery;
    11 using System.Diagnostics;
    12 using System.Net;
    13 
    14 
    15 
    16 namespace SatChanGen
    17 {
    18     public struct ProgressReport
    19     {
    20         public int Max { get; set; }
    21         public int Value { get; set; }
    22     }
    23 
    24     public partial class MainForm : Form, IProgress<ProgressReport>
    25     {
    26         public MainForm()
    27         {
    28             InitializeComponent();
    29         }
    30 
    31         private void buttonGenerate_Click(object sender, EventArgs e)
    32         {
    33             List<Channel> channels = new List<Channel>();
    34             channels.AddRange(KingOfSat.Parse(channels, "http://en.kingofsat.net/pack-skygermany.php", "19.2°E", true));
    35             channels.AddRange(KingOfSat.Parse(channels, "http://en.kingofsat.net/pack-hdplus.php", "19.2°E", true));
    36             channels.AddRange(KingOfSat.Parse(channels, "http://en.kingofsat.net/pack-arddigital.php", "19.2°E", true));
    37             channels.AddRange(KingOfSat.Parse(channels, "http://en.kingofsat.net/pack-zdfvision.php", "19.2°E", true));
    38             channels.AddRange(KingOfSat.Parse(channels, "http://en.kingofsat.net/pack-tntsat.php", "19.2°E", true, "TNTSAT"));
    39         
    40             //Discard non HD channels we don't need
    41             channels = KingOfSat.CleanChannelList(channels);
    42 
    43             //Declare tuner cards so that we don't need to create mapping manually after import
    44             List<string> tuners = new List<string>(){"3","4"};
    45 
    46             //Export to XML for MediaPortal to import
    47             MediaPortal.Export(channels, tuners, "channels.xml", false);
    48         }
    49 
    50         /// <summary>
    51         /// 
    52         /// </summary>
    53         /// <param name="sender"></param>
    54         /// <param name="e"></param>
    55         private async void iButtonSatIndex_Click(object sender, EventArgs e)
    56         {
    57             await Task.Run(() => FetchSatIndexChannels());
    58         }
    59 
    60         /// <summary>
    61         /// 
    62         /// </summary>
    63         private void FetchSatIndexChannels()
    64         {
    65             List<Channel> channels = new List<Channel>();
    66 
    67             channels.AddRange(SatIndex.Parse(this, channels, "http://www.satindex.de/tv/1/1/", "19.2°E", true));
    68             //channels.AddRange(KingOfSat.Parse(channels, "http://en.kingofsat.net/pack-hdplus.php", "19.2°E", true));
    69             //channels.AddRange(KingOfSat.Parse(channels, "http://en.kingofsat.net/pack-arddigital.php", "19.2°E", true));
    70             //channels.AddRange(KingOfSat.Parse(channels, "http://en.kingofsat.net/pack-zdfvision.php", "19.2°E", true));
    71             //channels.AddRange(KingOfSat.Parse(channels, "http://en.kingofsat.net/pack-tntsat.php", "19.2°E", true, "TNTSAT"));
    72 
    73             //Discard non HD channels we don't need
    74             channels = SatIndex.CleanChannelList(channels);
    75 
    76             //Declare tuner cards so that we don't need to create mapping manually after import
    77             List<string> tuners = new List<string>() { "3", "4" };
    78 
    79             //Export to XML for MediaPortal to import
    80             MediaPortal.Export(channels, tuners, "channels.xml", false);
    81 
    82         }
    83 
    84         /// <summary>
    85         /// 
    86         /// </summary>
    87         /// <param name="aProgress"></param>
    88         public void Report(ProgressReport aProgress)
    89         {
    90             MethodInvoker methodInvokerDelegate = delegate ()
    91                 {
    92                     toolStripProgressBar.Maximum = aProgress.Max;
    93                     toolStripProgressBar.Value = aProgress.Value;
    94                     toolStripStatusLabel.Text = aProgress.Value + " / " + aProgress.Max;
    95                 };
    96 
    97             //This will be true if Current thread is not UI thread.
    98             if (InvokeRequired)
    99             {
   100                 Invoke(methodInvokerDelegate);
   101             }
   102             else
   103             {
   104                 methodInvokerDelegate();
   105             } 
   106                     
   107         }
   108 
   109 
   110 
   111     }
   112 }