public WatcherItem(PathPair file, WatcherItemType type) { m_type = type; m_sFullPathFileName = file.m_sFull_FileName; m_sParsedFileName = file.m_sMatch_FileName; if (type == WatcherItemType.Added) { fileInfo = new FileInfo(file.m_sFull_FileName); } MPTVSeriesLog.Write("File monitor: " + m_sParsedFileName + " " + m_type); }
public FilenameParser(PathPair aPathPair) { try { //////////////////////////////////////////////////////////////////////////////////////////// // Parsing filename for all recognized naming formats to extract episode information //////////////////////////////////////////////////////////////////////////////////////////// m_Filename = aPathPair.m_sMatch_FileName; if (sExpressions.Count == 0) { reLoadExpressions(); } int index = 0; // run Before replacements m_FileNameAfterReplacement = RunReplacements(replacementRegexBefore, m_Filename); foreach (Regex regularExpression in regularExpressions) { Match matchResults; matchResults = regularExpression.Match(m_FileNameAfterReplacement); if (matchResults.Success) { for (int i = 1; i < matchResults.Groups.Count; i++) { string GroupName = regularExpression.GroupNameFromNumber(i); string GroupValue = matchResults.Groups[i].Value; if (GroupValue.Length > 0 && GroupName != "unknown") { // run after replacements on captures GroupValue = RunReplacements(replacementRegexAfter, GroupValue); GroupValue = GroupValue.Trim(); m_Matches.Add(GroupName, GroupValue); } } // try get the series name from the folder if (DBOption.GetOptions(DBOption.cParsedNameFromFolder)) { // get directory of file string lDirectory = Path.GetDirectoryName(aPathPair.m_sFull_FileName); // now get the name basis the last part of the directory string lLastFolderName = Path.GetFileName(lDirectory); // check if the directory structure has seasons if ((lLastFolderName.ToLowerInvariant().Contains("season") && lLastFolderName.Any(Char.IsDigit)) || (lLastFolderName.ToLowerInvariant().Contains(Translation.Season) && lLastFolderName.Any(Char.IsDigit)) || lLastFolderName.ToLowerInvariant().Equals("specials") || lLastFolderName.ToLowerInvariant().Equals(Translation.specials)) { lDirectory = Directory.GetParent(lDirectory).ToString(); lLastFolderName = Path.GetFileName(lDirectory); } // check if our parsing rule has already captured the series name // and if so, update the existing value string lValue = string.Empty; if (m_Matches.ContainsKey(DBSeries.cParsedName)) { lValue = RunReplacements(replacementRegexAfter, lLastFolderName).Trim(); m_Matches[DBSeries.cParsedName] = lValue; } else // if not add it { lValue = RunReplacements(replacementRegexAfter, lLastFolderName).Trim(); m_Matches.Add(DBSeries.cParsedName, lValue); } MPTVSeriesLog.Write($"Setting series name as '{lValue}' basis the last folder in file '{aPathPair.m_sFull_FileName}'", MPTVSeriesLog.LogLevel.DebugSQL); } // stop on the first successful match m_RegexpMatched = sExpressions[index]; m_RegexpMatchedIdx = index; return; } index++; } } catch (Exception ex) { MPTVSeriesLog.Write("An error occured in the 'FilenameParser' function (" + ex.ToString() + ")"); } }