Beispiel #1
0
        private int MatchEpisodes(ref List <string> files, ref List <Episode> episodes, Series series, ref int filenum, ref List <Episode> matchedEpisodes, List <FileInfo> orphanedEpisodes, bool matchwithseriesname)
        {
            int matched = 0;
            ListBoxRenameItem item;

            foreach (string file in files)
            {
                if (Configuration.IsValidVideo(file))
                {
                    filenum++;

                    FileInfo  info = new FileInfo(file);
                    Episode[] ep   = VideoInformation.MatchEpisode(info.FullName, episodes, series, matchwithseriesname);

                    if (ep != null && ep.Length > 0)
                    {
                        foreach (Episode e in ep)
                        {
                            matchedEpisodes.Add(e);
                            episodes.Remove(e);
                            matched++;
                        }
                    }
                    else
                    {
                        ep = VideoInformation.MatchEpisode(info.FullName, matchedEpisodes, series, matchwithseriesname);

                        if (ep != null && ep.Length > 0)
                        {
                            item = new ListBoxRenameItem(info.Directory.FullName, info.Name, "Duplicate!", series.SeriesName, "", "", "", series.FirstAired.Year.ToString(), "", "");
                            Add(item);
                        }
                        else
                        {
                            orphanedEpisodes.Add(info);
                        }
                        continue;
                    }

                    string newName = VideoInformation.GetEpisodeName(info.Name, series, ep, cboFormat.Text, filenum, Configuration.InvalidCharReplacement, Configuration.EpisodeDateFormat, Configuration.SeriesDateFormat);
                    if (ep.Length == 1)
                    {
                        item = new ListBoxRenameItem(info.Directory.FullName, info.Name, newName, series.SeriesName, ep[0].AiredSeason.ToString(), ep[0].EpisodeName, ep[0].AiredEpisodeNumber.ToString(), series.FirstAired.Year.ToString(), "", "");//"res", "thumb"
                    }
                    else
                    {
                        item = new ListBoxRenameItem(info.Directory.FullName, info.Name, newName, series.SeriesName, ep[0].AiredSeason.ToString(), ep[0].EpisodeName + " & " + ep[1].EpisodeName, ep[0].AiredEpisodeNumber.ToString() + "-" + ep[1].AiredEpisodeNumber.ToString(), series.FirstAired.Year.ToString(), "", "");//"res", "thumb"
                    }
                    Add(item);
                }
                else if (Configuration.IsUnwantedExtension(file))
                {
                    FileInfo info = new FileInfo(file);
                    item = new ListBoxRenameItem(info.Directory.FullName, info.Name, "Unwanted!", "", "", "", "", "", "", "");//"res", "thumb"

                    Add(item);
                }
            }
            return(matched);
        }
Beispiel #2
0
        private void btnDown_Click(object sender, EventArgs e)
        {
            int repeat;

            if (!int.TryParse(txtRepeat.Text, out repeat))
            {
                repeat = 1;
            }

            for (int i = 0; i < repeat; i++)
            {
                if (grdRenameData.SelectedCells[0].RowIndex == grdRenameData.RowCount - 1)
                {
                    return;
                }

                if (grdRenameData.SelectedCells.Count > 0)
                {
                    DataGridViewRow   below       = grdRenameData.Rows[grdRenameData.SelectedCells[0].RowIndex + 1];
                    DataGridViewRow   current     = grdRenameData.Rows[grdRenameData.SelectedCells[0].RowIndex];
                    ListBoxRenameItem itemBelow   = (ListBoxRenameItem)below.DataBoundItem;
                    ListBoxRenameItem itemCurrent = (ListBoxRenameItem)current.DataBoundItem;

                    //grdRenameData.SelectedRows[0]
                    if (grdRenameData.SelectedCells[0].OwningColumn.DataPropertyName == "OrigFileName" || grdRenameData.SelectedCells[0].OwningColumn.DataPropertyName == "Selected")
                    {
                        string tmpFilename = itemBelow.OrigFileName;
                        string tmpPath     = itemBelow.Path;
                        itemBelow.OrigFileName   = itemCurrent.OrigFileName;
                        itemBelow.Path           = itemCurrent.Path;
                        itemCurrent.OrigFileName = tmpFilename;
                        itemCurrent.Path         = tmpPath;
                    }
                    else
                    {
                        ListBoxRenameItem tmpItem = itemBelow.Copy();
                        itemBelow.EpisodeNumber = itemCurrent.EpisodeNumber;
                        itemBelow.EpisodeTitle  = itemCurrent.EpisodeTitle;
                        itemBelow.NewFileName   = itemCurrent.NewFileName;
                        //itemAbove.OrigFileName = itemCurrent.OrigFileName;
                        //itemBelow.Path = itemCurrent.Path;
                        itemBelow.Resolution = itemCurrent.Resolution;
                        itemBelow.Season     = itemCurrent.Season;
                        itemBelow.Selected   = itemCurrent.Selected;
                        itemBelow.Series     = itemCurrent.Series;
                        itemBelow.Thumb      = itemCurrent.Thumb;
                        itemBelow.Year       = itemCurrent.Year;

                        itemCurrent.EpisodeNumber = tmpItem.EpisodeNumber;
                        itemCurrent.EpisodeTitle  = tmpItem.EpisodeTitle;
                        itemCurrent.NewFileName   = tmpItem.NewFileName;
                        //itemCurrent.OrigFileName = tmpItem.OrigFileName;
                        //itemCurrent.Path = tmpItem.Path;
                        itemCurrent.Resolution = tmpItem.Resolution;
                        itemCurrent.Season     = tmpItem.Season;
                        itemCurrent.Selected   = tmpItem.Selected;
                        itemCurrent.Series     = tmpItem.Series;
                        itemCurrent.Thumb      = tmpItem.Thumb;
                        itemCurrent.Year       = tmpItem.Year;
                    }

                    grdRenameData.CurrentCell = grdRenameData.Rows[grdRenameData.SelectedCells[0].RowIndex + 1].Cells[grdRenameData.SelectedCells[0].OwningColumn.Name];

                    grdRenameData.Invalidate();
                    //grdRenameData.CommitEdit(DataGridViewDataErrorContexts.Commit);
                }
            }
        }
Beispiel #3
0
 void Add(ListBoxRenameItem item)
 {
     this.lstFileRenamer.AddObject(item);
     bindingSource1.Add(item);
 }
Beispiel #4
0
        private async Task <bool> InitLstFileRenamerAsync(List <string> paths)
        {
            btnLookup.Enabled = false;
            ListBoxRenameItem item;
            //string newName;
            int filenum = 0;

            this.lstFileRenamer.Items.Clear();

            Series series = await VideoInformation.ThetvDB.GetSeries(SelectedSeries);

            List <Episode> episodes = new List <Episode>(Task.Run(async() => { return(await VideoInformation.ThetvDB.GetAllEpisodes(SelectedSeries)); }).Result);

            episodes = HelperFunctions.DistinctBy(episodes, c => c.Id).ToList();
            List <Episode>  matchedEpisodes  = new List <Episode>();
            List <FileInfo> orphanedEpisodes = new List <FileInfo>();

            List <string> files = new List <string>();

            //Check each path and if it's a dir then get all files in that dir.
            foreach (string path in paths)
            {
                FileInfo fi = new FileInfo(path);
                if ((fi.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    foreach (string file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories))
                    {
                        files.Add(file);
                    }
                }
                else
                {
                    files.Add(path);
                }
            }

            files = files.Distinct().ToList();
            files.Sort();

            if (MatchEpisodes(ref files, ref episodes, series, ref filenum, ref matchedEpisodes, orphanedEpisodes, true) == 0)
            {
                //If the match totally failed then try matching again without the series name.
                filenum          = 0;
                matchedEpisodes  = new List <Episode>();
                orphanedEpisodes = new List <FileInfo>();

                MatchEpisodes(ref files, ref episodes, series, ref filenum, ref matchedEpisodes, orphanedEpisodes, false);
            }
            foreach (FileInfo info in orphanedEpisodes)
            {
                filenum++;

                //if (episodes.Count > 0)
                //{
                //    Episode ep = episodes[0];
                //    episodes.RemoveAt(0);

                //    //newName = VideoInformation.GetEpisodeName(info.Name, series, new Episode[] { ep }, cboFormat.Text, filenum, Configuration.InvalidCharReplacement, Configuration.EpisodeDateFormat, Configuration.SeriesDateFormat);
                //    item = new ListBoxRenameItem(info.FullName, info.Name, newName, series.SeriesName, ep.AiredSeason.ToString(), ep.EpisodeName, ep.AiredEpisodeNumber.ToString(), series.FirstAired.Year.ToString(), "", "" );//"res", "thumb"
                //}
                //else
                {
                    item = new ListBoxRenameItem(info.Directory.FullName, info.Name, "Missing!", series.SeriesName, "", "", "", series.FirstAired.Year.ToString(), "", "");
                }

                Add(item);
            }

            foreach (Episode ep in episodes)
            {
                string newName = VideoInformation.GetEpisodeName("", series, new Episode[] { ep }, cboFormat.Text, filenum, Configuration.InvalidCharReplacement, Configuration.EpisodeDateFormat, Configuration.SeriesDateFormat);
                item = new ListBoxRenameItem("", "Missing!", newName, series.SeriesName, ep.AiredSeason.ToString(), ep.EpisodeName, ep.AiredEpisodeNumber.ToString(), series.FirstAired.Year.ToString(), "", "");  //"res", "thumb"
                Add(item);
            }

            checkBox1.Checked = true;
            btnLookup.Enabled = true;
            return(true);
        }
Beispiel #5
0
        internal ListBoxRenameItem Copy()
        {
            ListBoxRenameItem theCopy = new ListBoxRenameItem(String.Copy(Path), String.Copy(OrigFileName), String.Copy(NewFileName), String.Copy(Series), String.Copy(Season), String.Copy(EpisodeTitle), String.Copy(EpisodeNumber), String.Copy(Year), String.Copy(Resolution), null);

            return(theCopy);
        }