Esempio n. 1
0
        /// <summary>
        /// Refresh output data
        /// </summary>
        void RefreshOutputData()
        {
            try
            {
                //filter records
                string entered = this.txtSearchOutput.Text.Trim();
                mainModel.FilterOutput(entered);

                //set dgv datasource, columns, widths
                this.SetDGVColumnsSourceAndWidth(this.dgvOutputRecords, mainModel.OutputFilteredRecords);

                //change row color based on URLValid status
                for (int i = 0; i < this.dgvOutputRecords.Rows.Count; i++)
                {
                    DataGridViewRow row = this.dgvOutputRecords.Rows[i];
                    M3URecord       rec = (M3URecord)row.DataBoundItem;

                    if (rec != null)
                    {
                        if (rec.URLValid == false)
                        {
                            row.DefaultCellStyle.BackColor = Color.Coral;
                        }
                        else
                        {
                            row.DefaultCellStyle.BackColor = Color.White;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Check output list records URL validity
        /// </summary>
        public void CheckOutputListURLs()
        {
            //go through all output records
            for (int i = 0; i < _outputModel.Records.Count; i++)
            {
                M3URecord rec = _outputModel.Records[i];
                if (rec != null)
                {
                    string url = rec.URL.Trim();

                    //if invalid url
                    if (url == string.Empty)
                    {
                        rec.URLValid = false;
                        continue;
                    }

                    //if regular url
                    //check if url valid
                    bool isActive = URLValidator.IsURLActive(rec.URL);
                    if (isActive == false)
                    {
                        rec.URLValid = false;
                    }
                    else
                    {
                        rec.URLValid = true;
                    }
                }
            }
        }
Esempio n. 3
0
        void btnRemoveRecordsClick(object sender, EventArgs e)
        {
            //get first selected row index
            int firstSelected = -1;

            if (dgvOutputRecords.SelectedRows.Count > 0)
            {
                firstSelected = dgvOutputRecords.SelectedRows[0].Index;
            }

            //for each selected - remove it
            foreach (DataGridViewRow r in dgvOutputRecords.SelectedRows)
            {
                M3URecord rec = (M3URecord)r.DataBoundItem;
                mainModel.RemoveOutputRecord(rec);
            }

            //reorder and refresh
            mainModel.ReorderOutput();
            this.RefreshOutputData();

            //select row in place of deleted
            this.DGVSelectRowAndCenter(dgvOutputRecords, firstSelected);

            //status bar - message
            this.UpdateStatusBar();
        }
Esempio n. 4
0
        void btnAddRecordClick(object sender, EventArgs e)
        {
            //get first selected item index
            int firstSelected = -1;

            if (dgvInputRecords.SelectedCells.Count > 0)
            {
                firstSelected = dgvInputRecords.SelectedRows[0].Index;
            }

            //add all selected records to output
            foreach (DataGridViewRow r in dgvInputRecords.SelectedRows)
            {
                M3URecord rec = ((M3URecord)r.DataBoundItem).Clone();
                mainModel.AddOutputRecord(rec);
            }

            //reorder and refresh
            mainModel.ReorderOutput();
            this.RefreshOutputData();

            //select next row (input)
            this.DGVSelectRowAndCenter(dgvInputRecords, firstSelected + 1);

            //select last row (output)
            this.DGVSelectRowAndCenter(dgvOutputRecords, dgvOutputRecords.Rows.Count - 1);

            //status bar - message
            this.UpdateStatusBar();
        }
Esempio n. 5
0
        /// <summary>
        /// Remove output record
        /// </summary>
        /// <param name="rec"></param>
        public void RemoveOutputRecord(M3URecord rec)
        {
            if (rec == null)
            {
                return;
            }

            _outputModel.Records.Remove(rec);
        }
Esempio n. 6
0
        /// <summary>
        /// Create new output record - prefilled
        /// </summary>
        public void NewOutputRecord()
        {
            //add new record
            M3URecord rec = new M3URecord();

            rec.ID         = "New channel";
            rec.Order      = _outputModel.Records.Count + 1;
            rec.Name       = "New channel";
            rec.GroupTitle = "New group";
            rec.Logo       = "New logo";
            rec.URL        = "http://";

            _outputModel.Records.Add(rec);
        }
Esempio n. 7
0
        public M3URecord Clone()
        {
            M3URecord rec = new M3URecord();

            rec.ID         = this.ID;
            rec.Name       = this.Name;
            rec.GroupTitle = this.GroupTitle;
            rec.Logo       = this.Logo;
            rec.Order      = this.Order;
            rec.URL        = this.URL;
            rec.URLValid   = this.URLValid;

            return(rec);
        }
Esempio n. 8
0
        /// <summary>
        /// Add all input records to output list
        /// </summary>
        public void AddAllInputRecordsToOutput()
        {
            //for each input record add them to output
            foreach (M3URecord r in _inputModel.Records)
            {
                M3URecord rec = r.Clone();
                rec.Order = _outputModel.Records.Count + 1;

                //check if already not exists
                if (_outputModel.Records.Any(x => x.URL == rec.URL) == false)
                {
                    _outputModel.Records.Add(rec);
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Move selected output record down in list - change order
        /// </summary>
        /// <param name="rec">M3URecord object</param>
        /// <param name="index">Current index in list</param>
        /// <returns></returns>
        public bool MoveDownOutputRecord(M3URecord rec, int index)
        {
            bool result = false;

            if (rec == null)
            {
                return(result);
            }

            if (rec.Order < this.TotalOutputRecords)
            {
                //remove from list and add on new place in list
                _outputModel.Records.Remove(rec);
                _outputModel.Records.Insert(index + 1, rec);
                result = true;
            }

            return(result);
        }
Esempio n. 10
0
        /// <summary>
        /// Add output record
        /// </summary>
        /// <param name="rec"></param>
        public void AddOutputRecord(M3URecord rec)
        {
            if (rec == null)
            {
                return;
            }

            //if no output records
            if (_outputModel.Records == null)
            {
                _outputModel.Records = new BindingList <M3URecord>();
            }

            //check if already exists
            if (_outputModel.Records.Any(x => x.URL == rec.URL) == false)
            {
                //add record
                _outputModel.Records.Add(rec);
            }
        }
Esempio n. 11
0
        void btnMoveDownRecordClick(object sender, EventArgs e)
        {
            //if records exists
            if (dgvOutputRecords.SelectedRows.Count > 0 && mainModel.TotalOutputRecords == mainModel.TotalOutputFilteredRecords)
            {
                //get index of first selected record
                int index = dgvOutputRecords.SelectedRows[0].Index;

                DataGridViewRow r   = dgvOutputRecords.SelectedRows[0];
                M3URecord       rec = (M3URecord)r.DataBoundItem;
                if (mainModel.MoveDownOutputRecord(rec, index))
                {
                    //reorder & refresh data
                    mainModel.ReorderOutput();
                    this.RefreshOutputData();

                    //select moved row
                    this.DGVSelectRowAndCenter(dgvOutputRecords, index + 1);
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Process heading and url strings and return M3URecord object
        /// </summary>
        /// <param name="heading">Heading string</param>
        /// <param name="url">URL string</param>
        /// <returns>M3URecord</returns>
        public M3URecord ProcessHeadingAndURL(string heading, string url)
        {
            //extract info
            MatchCollection idMatches         = Regex.Matches(heading, "tvg-ID=\"([^\"]*)\"");
            MatchCollection nameMatches       = Regex.Matches(heading, "tvg-name=\"([^\"]*)\"");
            MatchCollection groupTitleMatches = Regex.Matches(heading, "group-title=\"([^\"]*)\"");
            MatchCollection logoMatches       = Regex.Matches(heading, "tvg-logo=\"([^\"]*)\"");

            //create M3URecord
            M3URecord rec = new M3URecord();

            // parse it as plain
            if (idMatches.Count == 0 && nameMatches.Count == 0 && groupTitleMatches.Count == 0)
            {
                rec.Name = heading.Replace(M3UConstants.LINE_HEADING, "").Replace(",", "").Trim();
            }
            else             //parse it as extended
            {
                if (idMatches.Count >= 1)
                {
                    rec.ID = idMatches[0].Value.ToString().Replace("tvg-ID=", "").Replace("\"", "").Trim();
                }
                if (nameMatches.Count >= 1)
                {
                    rec.Name = nameMatches[0].Value.ToString().Replace("tvg-name=", "").Replace("\"", "").Trim();
                }
                if (groupTitleMatches.Count >= 1)
                {
                    rec.GroupTitle = groupTitleMatches[0].Value.ToString().Replace("group-title=", "").Replace("\"", "").Trim();
                }
                if (logoMatches.Count >= 1)
                {
                    rec.Logo = logoMatches[0].Value.ToString().Replace("tvg-logo=", "").Replace("\"", "").Trim();
                }
            }
            rec.URL = url;

            return(rec);
        }
Esempio n. 13
0
        void dgvOutputRecordsCellClick(object sender, DataGridViewCellEventArgs e)
        {
            //detect VLC button click
            if (e.ColumnIndex == this.dgvOutputRecords.Columns["VLC"].Index)
            {
                DataGridViewRow r   = dgvOutputRecords.Rows[e.RowIndex];
                M3URecord       rec = (M3URecord)r.DataBoundItem;

                if (rec != null)
                {
                    //lunch vlc
                    if (rec.URL != string.Empty)
                    {
                        VLCIntegration vlc     = new VLCIntegration();
                        bool           success = vlc.OpenWebURL(rec.URL);
                        if (success == false)
                        {
                            MessageBox.Show("Unable to lunch VLC player, check your Settings!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Parse M3U file and return List<M3URecord>
        /// </summary>
        /// <param name="filename">File name</param>
        /// <returns>List<M3URecord></returns>
        public List <M3URecord> ParseFile(string filename)
        {
            List <M3URecord> result = new List <M3URecord>();

            //read file into string list
            string        fileContents = File.ReadAllText(filename);
            List <string> rawLines     = fileContents.Split('\n').ToList();

            //remove unneeded characters
            List <string> lines = new List <string>();

            for (int i = 0; i < rawLines.Count; i++)
            {
                string line = rawLines[i].Replace("\r", "").Replace("\n", "");

                if (line != string.Empty)
                {
                    lines.Add(line);
                }
            }

            // check if file contains items
            if (lines.Count < 3)
            {
                throw new M3UException("File doesnt contain items");
            }

            int channelCounter = 1;             // channel counter

            //first line - header
            if (lines[0].StartsWith(M3UConstants.FILE_HEADER, StringComparison.InvariantCultureIgnoreCase))
            {
                // go through each line
                for (int i = 1; i < lines.Count; i++)
                {
                    //if line is heading info
                    if (lines[i].StartsWith(M3UConstants.LINE_HEADING, StringComparison.InvariantCultureIgnoreCase))
                    {
                        //if end of file is not reached
                        if ((i + 1) <= (lines.Count - 1))
                        {
                            //if line heading - skip
                            if (lines[i + 1].StartsWith(M3UConstants.LINE_HEADING, StringComparison.InvariantCultureIgnoreCase))
                            {
                                continue;
                            }
                            //if line is url - process
                            else if (lines[i + 1].StartsWith("http", StringComparison.InvariantCultureIgnoreCase))
                            {
                                string heading = lines[i];
                                string url     = lines[i + 1];

                                //process heading & url
                                M3URecord rec = ProcessHeadingAndURL(heading, url);
                                rec.Order = channelCounter;
                                channelCounter++;
                                result.Add(rec);

                                // Debug.WriteLine(lines[i]);
                                // Debug.WriteLine(lines[i+1]);
                            }
                            else                             //if line is unknown - skip
                            {
                                continue;
                            }
                        }
                    }
                    else                     //if not heading - skip
                    {
                        continue;
                    }
                }
            }
            else             //if invalid header
            {
                throw new M3UException("Invalid Header");
            }

            return(result);
        }