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