Esempio n. 1
0
        public int Compare(object x, object y)
        {
            ListViewItem xItem = x as ListViewItem;
            ListViewItem yItem = y as ListViewItem;

            if (xItem == null || yItem == null)
            {
                throw new ArgumentException();
            }

            parseResult xResult = xItem.Tag as parseResult;
            parseResult yResult = yItem.Tag as parseResult;

            if (xResult == null || yResult == null)
            {
                throw new ArgumentException();
            }

            //sort the parsing failures to the top of the list so they don't get lost in the middle of a big list
            if (xResult.success && !yResult.success)
            {
                return(1);
            }
            else if (!xResult.success && yResult.success)
            {
                return(-1);
            }

            return(xResult.full_filename.CompareTo(yResult.full_filename));
        }
Esempio n. 2
0
        public static List <parseResult> Parse(List <PathPair> files, bool includeFailed)
        {
            MPTVSeriesLog.Write(string.Format("Starting Local Filename Parsing, processing {0} files", files.Count.ToString()));
            List <parseResult> results = new List <parseResult>();
            parseResult        progressReporter;
            int            nFailed = 0;
            FilenameParser parser  = null;
            ListViewItem   item    = null;

            paths = null;
            foreach (PathPair file in files)
            {
                parser = new FilenameParser(file);

                // title case the seriesname
                if (parser.Matches.ContainsKey(DBSeries.cParsedName) && !DBOption.GetOptions(DBOption.cParsedNameFromFolder))
                {
                    parser.Matches[DBSeries.cParsedName] = parser.Matches[DBSeries.cParsedName].ToString().ToTitleCase();
                }

                // set volumelabel for drive so can be prompted to insert CD/DVD disk or removable harddrive
                // populate with import path name if can not get volume label
                string volumeLabel = DeviceManager.GetVolumeLabel(file.m_sFull_FileName);

                if (string.IsNullOrEmpty(volumeLabel))
                {
                    volumeLabel = LocalParse.getImportPath(file.m_sFull_FileName);
                }

                parser.Matches.Add(DBEpisode.cVolumeLabel, volumeLabel);

                item = new ListViewItem(file.m_sMatch_FileName);
                item.UseItemStyleForSubItems = true;

                progressReporter = new parseResult();

                // make sure we have all the necessary data for a full match
                if (!parser.Matches.ContainsKey(DBEpisode.cSeasonIndex) ||
                    !parser.Matches.ContainsKey(DBEpisode.cEpisodeIndex))
                {
                    if (parser.Matches.ContainsKey(DBSeries.cParsedName) &&
                        parser.Matches.ContainsKey(DBOnlineEpisode.cFirstAired))
                    {
                        try{ System.DateTime.Parse(parser.Matches[DBOnlineEpisode.cFirstAired]); }
                        catch (System.FormatException)
                        {
                            nFailed++;
                            progressReporter.failedAirDate = true;
                            progressReporter.success       = false;
                            progressReporter.exception     = "Air Date is not valid";
                        }
                    }
                    else
                    {
                        progressReporter.success   = false;
                        progressReporter.exception = "Parsing failed for: " + file;

                        nFailed++;
                    }
                }
                else
                {
                    // make sure episode & season are properly matched (numerical values)
                    try { Convert.ToInt32(parser.Matches[DBEpisode.cSeasonIndex]); }
                    catch (System.FormatException)
                    {
                        nFailed++;
                        progressReporter.failedSeason = true;
                        progressReporter.success      = false;
                        progressReporter.exception   += "Season is not numerical ";
                    }
                    try { Convert.ToInt32(parser.Matches[DBEpisode.cEpisodeIndex]); }
                    catch (System.FormatException)
                    {
                        nFailed++;
                        progressReporter.failedEpisode = true;
                        progressReporter.success       = false;
                        progressReporter.exception    += "Episode is not numerical ";
                    }
                }

                progressReporter.match_filename = file.m_sMatch_FileName;
                progressReporter.full_filename  = file.m_sFull_FileName;
                progressReporter.parser         = parser;
                progressReporter.PathPair       = file;
                if (includeFailed || progressReporter.success)
                {
                    results.Add(progressReporter);
                }
            }
            MPTVSeriesLog.Write("Finished Local Filename Parsing");
            return(results);
        }