public static string IdentifyFilmByFilmTitleMatchingEngines
            (IMLItem item, string imdbid, IMDbOperations imdbOp, 
             string year, ConnectionResult connectionresult)
        {


            #region Return Cases
            if (!Settings.FilmTitleMatchingEnginesAreEnabled)
            {
                Debugger.LogMessageToFile("[IMDb Film Title Matcher] IMDb Title matching is disabled. Returning...");
                return imdbid;
            }

            if (!String.IsNullOrEmpty(imdbid))
            {
                Debugger.LogMessageToFile("[IMDb Film Title Matcher] This item is already identified. Returning...");
                return imdbid;
            }
            #endregion

            if (Settings.PrimaryFilmTitleMatchingEngine == "TMDb")
            {


                imdbid = Code.Media_Identifiers.
                    Film_Identifiers.Title_Matching_Engines
                    .TMDb.TMDbTitleMatchingEngine.
                    IdentifyFilmByTMDbFilmTitleMatchingEngine(item);

                imdbid = IdentifyFilmByIMDbFilmTitleMatchingEngines
                    (item, imdbid, imdbOp, connectionresult);
            
            
            }
            else
            {


                imdbid = IdentifyFilmByIMDbFilmTitleMatchingEngines
                    (item, imdbid, imdbOp, connectionresult);


                imdbid = Code.Media_Identifiers.
                    Film_Identifiers.Title_Matching_Engines
                    .TMDb.TMDbTitleMatchingEngine.
                    IdentifyFilmByTMDbFilmTitleMatchingEngine(item);


            }



            return imdbid;
        }
        internal static string IMDbDetailer
            (IMLSection moviesSection, 
             IMDbOperations imdbOp,
             IMLItem item,
             string itemTitle,
             string imdbid)
        {


            if (!MeediFier.Settings.FilmIMDbDetailsDownloaderIsEnabled)
                return imdbid;

            Debugger.LogMessageToFile
                ("IMDb film details downloader is enabled");


            if (String.IsNullOrEmpty(imdbid))
                return imdbid;


            if (!imdbid.StartsWith("tt"))
                imdbid = "tt" + imdbid;


            MainImportingEngine.ThisProgress.Progress
                (MainImportingEngine.CurrentProgress,
                 "Downloading details from IMDb for '"
                 + itemTitle + "'...");


            Debugger.LogMessageToFile
                ("[IMDb film details downloader] " +
                 "Proceeding to phase 1");





            IIMDbMovie movie = IMDbMovieDetailsDownloader.DownloadMovieDetailsFromIMDb
                (imdbid, true);
           


            if (movie == null)
                return imdbid;


            imdbOp.SaveIMDbMovieDetails
                (item, moviesSection, movie);


            return imdbid;
        }
        private static void TitleMatchingEngineChooseFromResults(IMDbOperations imdbOp, IMLItem item, string year)
        {

            Debugger.LogMessageToFile("[IMDb film Title matching engine] Starting to perform selection from available film results according to user's preferences...");

            if (imdbOp._assistType == IMDbOperations.AssistType.Always)
                TitleMatchingEngineUserSelectsResult(imdbOp, true);
            else
            {
                var exactMatchFound = TitleMatchingEngineTryToFindExactMatch(imdbOp, item, year);

                #region Actions when no exact match was found

                if (!exactMatchFound)
                    TitleMatchingEngineDecideActionWhenNoPerfectMatch(imdbOp);

                #endregion
            }
        }
        public static bool TitleMatchingEngineTakeAction(IMLItem item, string year, IMDbOperations imdbOp)
        {
            bool resultsFound = imdbOp.ImdbList != null && imdbOp.ImdbList.Count > 0;

            if (resultsFound)
            {
                TitleMatchingEngineChooseFromResults(imdbOp, item, year);
            }
            else
            {
                //TODO: In the dialog shown, instruct the user to make a search for the Title.

                if (imdbOp._assistType == IMDbOperations.AssistType.Always | imdbOp._assistType == IMDbOperations.AssistType.NoPerfectMatch)
                    TitleMatchingEngineUserSelectsResult(imdbOp, false);
                else return false;
                //TODO: Add a "When no results found" option to "when to ask for film matching assistance".
            }


            return true;
        }
        internal static bool UpdateFilmItem
            (int itemID, IMLSection moviesSection,
             IMLItemList allFilmItems, 
             ref bool fileServerChecked,
             ref bool fileServerIsOnline, 
             ConnectionResult connectionresult,
             IMDbOperations imdbOp, string pluginpath,
             ref int currentItem, int totalItems,
             string mdfSettingsa, IBaseSystem ibs,
             IEnumerable<string> combinedSceneTags) 
        {


            MainImportingEngine.CurrentProgress 
                = ImportingEngineHelpers
                .ComputeProgress
                (currentItem, totalItems);




            #region Pre-updaters

            IMLItem item
                = moviesSection
                .FindItemByID(itemID);

            if (item == null)
                return true;

            MainImportingEngine.SpecialStatus
                = "Updating " + item.Name + "...";

            Debugger.LogMessageToFile
                (Environment.NewLine +
                "Starting to work with library item:" +
                 " " + item.Name +" with ID: " + itemID);


            Debugger.LogMessageToFile
                ("Initializing item variables...");


            string imdbid = Helpers.GetTagValueFromItem(item, "ImdbID");
            string tmdbID = Helpers.GetTagValueFromItem(item, "TMDbID");

            string filmYear = Helpers.GetTagValueFromItem(item, "Year");
            string itemTitle = Helpers.GetTagValueFromItem(item, "Title");
            string sortTitle = Helpers.GetTagValueFromItem(item, "SortTitle");


            bool isMultipart = false;
            string location = item.Location;
            string[] multipart = null;
            bool isUNC = false;

            DirectoryInfo parent;
            DirectoryInfo root;
            string videoFilename;


            MultipartFilmLibraryItemDetector
                .DetectMultipartItemRetrieveFirstItemLocation
                (ref location, ref isMultipart, ref multipart);


            if (!FilmItemUpdaterHelpers
                .RetrievePathLocations
                (location, out videoFilename,
                out parent, out root))
                return false;


            bool updateFilmItem;
            if (FilmItemUpdaterHelpers
                .PerformPreupdatingDiagnostics
                (moviesSection, ref fileServerChecked, 
                ref fileServerIsOnline, root, location, 
                item, ref isUNC, out updateFilmItem))
                return updateFilmItem;

            #endregion




            #region Primary Updating

            Debugger.LogMessageToFile
                ("Identification of film '"
                + itemTitle + "' is complete." +
                 " Continuing to download online data.");


            if (Helpers.GetTagValueFromItem
                (item, "MediaFairy-processed") != "--processed--")
            {

                #region Identifiers

                bool b;
                if (FilmItemUpdaterHelpers.ExtractLocalMetadataForFilmItem
                    (fileServerIsOnline, ref imdbOp,
                    pluginpath, combinedSceneTags,
                    parent, isUNC, item,
                    ref imdbid, out b))
                    return b;


                imdbOp.ImdbMovie = null;
                imdbOp.ImdbId = imdbid;


                //#region Set IsExactMatched flag for the video fingerprint uploader

                //try
                //{
                //    Year = Helpers.GetTagValueFromItem(Item, "Year");
                //}
                //catch
                //{
                //}

                //if (!String.IsNullOrEmpty(Year))
                //    isExactMatched = true;

                //if (!String.IsNullOrEmpty(imdbid))
                //    isExactMatched = true;

                //#endregion

                if (Helpers.UserCancels
                    (MainImportingEngine
                    .SpecialStatus, item))
                    return false;


                if (
                    !VideoFingerprintIdentifier
                    .VideoFingerprintIdentifier
                    .IdentifyVideo(ref imdbid, 
                    ref tmdbID, ref imdbOp,
                    item, fileServerIsOnline,
                    isUNC, location, parent.FullName,
                    filmYear, connectionresult, moviesSection)
                    )
                {

                    Debugger.LogMessageToFile
                        ("Unable to identify this video. Continuing to next item.");
                    return true;

                }
                Debugger.LogMessageToFile
                    ("Video identification was succesfull!");


                if (Helpers.UserCancels
                    (MainImportingEngine.SpecialStatus, item))
                    return false;


                

                #endregion


                #region Set Updating Flags




                #endregion


                #region extract important fields for online searches

                string imdbidTmp = Helpers.GetTagValueFromItem(item, "ImdbID");

                #region Get IMDbID

                if (!String.IsNullOrEmpty(imdbidTmp))
                {
                    imdbid = Helpers.GetTagValueFromItem(item, "ImdbID");
                    imdbOp.ImdbId = Helpers.GetTagValueFromItem(item, "ImdbID");
                }
                else
                {
                    if (!String.IsNullOrEmpty(imdbOp.ImdbId))
                        imdbid = imdbOp.ImdbId;
                    else imdbOp.ImdbId = imdbid;

                    item.Tags["ImdbID"] = imdbOp.ImdbId;
                }

                //MessageBox.Show("Item tag imdbid: " + Helpers.GetTagValueFromItem(Item,"ImdbID"]);

                #endregion

                #region Get ItemTitle

                itemTitle = Helpers.GetTagValueFromItem(item, "Title");

                if (String.IsNullOrEmpty(itemTitle))
                {
                    if (!String.IsNullOrEmpty(item.Name))
                    {
                        itemTitle = item.Name;
                    }
                    else return true;
                }

                #endregion

                #endregion

                #region Metadata Downloaders

                //MessageBox.Show("Can work online:" + connectionresult.CanWorkOnline);

                if (connectionresult.InternetConnectionAvailable
                    || !Settings.ConnectionDiagnosticsEnabled)
                {



                        #region download details


                       imdbid = FilmItemUpdaterHelpers.IMDbDetailer
                           (moviesSection, imdbOp,
                           item, itemTitle, imdbid);
                        


                    OSoperations.GetDetailsFromOSdb
                        (imdbid, item, connectionresult.OSDbIsOnline,
                        !imdbOp.NotListed);
    

                    #endregion


                        if (Helpers.UserCancels
                            (MainImportingEngine
                            .SpecialStatus, item))
                            return false;


                        #region Get ItemTitle

                        if (!String.IsNullOrEmpty(Helpers.GetTagValueFromItem(item, "Title")))
                        {
                            itemTitle = Helpers.GetTagValueFromItem(item, "Title");
                        }
                        else if (!String.IsNullOrEmpty(item.Name))
                        {
                            itemTitle = item.Name;
                        }
                        else return true;

                        #endregion

                        #region Set SortTitle

                        if (!String.IsNullOrEmpty
                            (itemTitle) 
                            && String.IsNullOrEmpty
                            (sortTitle))
                        {
                            if (itemTitle.StartsWith("The"))
                            {
                                sortTitle = itemTitle.Remove(0, 4) + ", The ";
                                Debugger.LogMessageToFile
                                    ("Set item's SortTitle to: '" + sortTitle + "'.");
                            }
                            else sortTitle = itemTitle;

                            item.Tags["SortTitle"] = sortTitle;
                            item.SaveTags();
                        }

                        #endregion



                    if (!FilmItemUpdaterHelpers
                            .DownloadFilmDetailsExtra(item))
                            return false;


                    location = FilmItemUpdaterHelpers
                            .PerformFilmOrganizing
                            (fileServerChecked, fileServerIsOnline,
                            connectionresult, currentItem, itemTitle,
                            multipart, location, isMultipart, item);


                    if (Helpers.UserCancels
                            (MainImportingEngine
                            .SpecialStatus, item))
                            return false;


                        //MovieDescriptorWriter
                        //    .WriteMovieDescriptor
                        //    (item, itemTitle, imdbid, 
                        //    parent.FullName,
                        //    fileServerIsOnline, isUNC);



                        if (Helpers.UserCancels
                            (MainImportingEngine
                            .SpecialStatus, item))
                            return false;



                        if (!DownloadFilmCoverAndBakdropArt
                            (fileServerIsOnline, mdfSettingsa, 
                            ibs, item, isUNC, itemTitle, location,
                            parent, videoFilename))
                            return false;


                }

                #endregion
            }

            #endregion




            if (!FilmItemSecondaryUpdater
                .PerformSecondaryFilmItemUpdating
                (moviesSection, allFilmItems, item))
                return false;



            item.SaveTags();
            currentItem++;

            return true;

        }
        private static void SetIMDbInternalTitleMatchingEngineProperties(IMDbOperations imdbOp)
        {

            if (Settings.AssistType == "When no exact match found")
                imdbOp._assistType = IMDbOperations.AssistType.NoPerfectMatch;

            if (Settings.AssistType == "Never")
                imdbOp._assistType = IMDbOperations.AssistType.Never;

            if (Settings.AssistType == "Skip identifying unknown films")
                imdbOp._assistType = IMDbOperations.AssistType.SkipUnknownItems;

            if (Settings.AssistType == "Always")
                imdbOp._assistType = IMDbOperations.AssistType.Always;

            imdbOp.UseFirst = Settings.UseFirst;
            imdbOp.UseLatest = Settings.UseLatest;
            imdbOp.UseMostPopular = Settings.UseMostPopular;


        }
        internal static void IdentifyFilmByIMDbInternalTitleMatchingEngine
            (IMLItem item, ConnectionResult connectionresult)
        {



            #region Return cases


            string imdbid = Helpers.GetTagValueFromItem(item, "ImdbID");

            if (CheckIfFilmIsAlreadyIdentified(imdbid)) return;

            if (CheckIfItemIsNotListed(item)) return;

            if (CheckIfInternetConnectionIsAvailable
                (item, connectionresult)) return;


            Debugger.LogMessageToFile
                ("[IMDb internal film Title matching engine] " +
                 "Starting identification by film's Title...");


            string filmTitle;
            string filmReleaseYear;


            filmTitle = ExtractKeyFieldsFromLibrary
                (item, out filmReleaseYear);



            if (CheckIfFilmTitleIsAvailable(item, filmTitle)) return;

            #endregion



            #region perform search

            Debugger.LogMessageToFile
                ("[IMDb internal film Title matching engine] " +
                 "Searching for films with Title '" + filmTitle + "'...");
            
            Helpers.UpdateProgress
                ("Updating Movies Section...", 
                "Searching IMDb for films with Title '" 
                + filmTitle + "'...", item);

            IMDbOperations imdbOp = new IMDbOperations();

            //TODO: Fix this recursive mess, here should be IMDbConventionalFilmSearchEngine SearchForTitleReturnResults()
            if (!imdbOp.SearchIMDbMovies())
                return;
            

            #endregion



            if ( !IMDbTitleMatchingEngine
                .TitleMatchingEngineTakeAction
                (item, filmReleaseYear, imdbOp))
                return;
            


            if (CheckIfItemIsNotListedAndIgnoreOrDeleteIt(item, imdbOp)) 
                return;


            #region Save IMDbID to library
            imdbid = imdbOp.ImdbId;
            item.Tags["ImdbID"] = imdbid;
            item.SaveTags();
            Debugger.LogMessageToFile("[IMDb video identifier] IMDb ID after matching by Title: " + imdbid);
            #endregion
        
        
        }
        internal static bool ExtractLocalMetadataForFilmItem
            (bool fileServerIsOnline, ref IMDbOperations imdbOp,
             string pluginpath, IEnumerable<string> combinedSceneTags,
             DirectoryInfo parent, bool isUNC, IMLItem item,
             ref string imdbid, out bool b)
        {


            if (MovieFileMetadataExtractor.ExtractMetadataFromMovieFilename
                (item, ref imdbid,
                 ref imdbOp, combinedSceneTags))
            {
                b = true;
                return true;
            }


            if (Helpers.UserCancels
                (MainImportingEngine.SpecialStatus, item))
            {
                b = false;
                return true;
            }


            CleanNameSetOriginalTitle(item);


            if (Helpers.UserCancels
                (MainImportingEngine.SpecialStatus,
                 item))
            {
                b = false;
                return true;
            }

            imdbid = NfoFileParser.RetrieveImdbidFromNfoFile
                (item, ref imdbid,
                 fileServerIsOnline,
                 isUNC, parent, pluginpath);


            b = false;
            return false;
        }
        internal static bool UpdateMoviesSection
            (string pluginpath, ref bool FileServerChecked,
             ref bool FileServerIsOnline,
             ref ConnectionResult connectionresult,
             IMDbOperations imdbOP, string MDFSettingsa, 
            IBaseSystem IBS, IEnumerable<string> combinedSceneTags)
        {



            if (String.IsNullOrEmpty(Settings.FilmsLibrary))
                Settings.EnableMoviesSectionUpdater = false;




            if (Settings.EnableMoviesSectionUpdater)
            {


                Debugger.LogMessageToFile
                    (Environment.NewLine 
                    + Environment.NewLine 
                    + "Film Updater is enabled.");


                if (MediaSectionsAllocator.MoviesSection.ItemCount != 0)
                {
                    #region Pre-Updating Operations

                    Debugger.LogMessageToFile("Initializing section variables...");

                    #region Movies Section varibales

                    IMLItemList allFilmItems;
                    int TotalItems = MediaSectionsAllocator.MoviesSection.ItemCount;
                    int CurrentItem = 1;
                    MainImportingEngine.CurrentProgress = 0;
                    MainImportingEngine.GeneralStatus = "Updating Movies Section";
                    MainImportingEngine.SpecialStatus = "";


                    if (Settings.SleepValue > 3000) Settings.SleepValue = 3000;

                    #endregion

                    #region Decide selective updating

                    bool SelectiveUpdatingEnabled = false;
                    Debugger.LogMessageToFile("Scanning section for Selective Updating request...");

                    try
                    {
                        foreach (int id in MediaSectionsAllocator.MoviesSection.GetAllItemIDs())
                        {
                            IMLItem Item = MediaSectionsAllocator.MoviesSection.FindItemByID(id);
                            if (Item.Tags["SelectiveUpdating"] != null &&
                                Helpers.GetTagValueFromItem(Item, "SelectiveUpdating") != "")
                                SelectiveUpdatingEnabled = true;
                        }
                    }
                    catch (NullReferenceException)
                    {
                        StatusForm.statusForm.TrayIcon.ShowBalloonTip(10000, "Films section is corrupt.",
                                                                      "MediaFairy was unable to update your Films media section because it's database file is corrupt. Please restore it using an available backup.",
                                                                      ToolTipIcon.Error);
                        Debugger.LogMessageToFile("The media section " + Settings.FilmsLibrary +
                                                  " is corrupt. This section will not be updated.");
                        return false;
                    }

                    #endregion






                    //FilmReleasesDownloader
                    //    .DownloadFilmReleases
                    //    (pluginpath, connectionresult,
                    //    combinedSceneTags,
                    //    SelectiveUpdatingEnabled);






                    #region Cache films section for the chain linking

                    if (!SelectiveUpdatingEnabled && Settings.FilmItemChainLinkerIsEnabled)
                    {
                        allFilmItems = MediaSectionsAllocator.MoviesSection.SearchAll("*");
                    }
                    else allFilmItems = null;

                    #endregion

                    #region Connect to OSdb

                    //connectionresult = Helpers.CheckInternetConnectionAndConnectToOSDb();

                    #endregion

                    #endregion

                    #region Main Updating Loop

                    Debugger.LogMessageToFile("Beginning to update Films section...");
                    MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress, "Preparing to update Movies section...");
                    Thread.Sleep(1000);
                    MediaSectionsAllocator.MoviesSection.BeginUpdate();



                    foreach (int id in MediaSectionsAllocator.MoviesSection.GetAllItemIDs())
                    {
                        if (
                            !SingleMovieItemUpdater.UpdateFilmItem
                            (id, MediaSectionsAllocator.MoviesSection,
                            allFilmItems, ref FileServerChecked,
                            ref FileServerIsOnline, connectionresult, imdbOP,
                            pluginpath, ref CurrentItem, TotalItems,
                            MDFSettingsa, IBS, combinedSceneTags))
                            return false;
                    }



                    MediaSectionsAllocator.MoviesSection.EndUpdate();
                    Debugger.LogMessageToFile("Completing updating of Films section...");

                    #endregion

                    #region Post-Updating Operations

                    if (Helpers.UserCancels
                        (MainImportingEngine
                        .SpecialStatus, null))
                        return false;

                    LibraryCleaners.CleanupSection
                        (Settings.CleanEmptyFields,
                         Settings.CleanSelectedFields,
                         Settings.SelectedFieldsToClean,
                         MediaSectionsAllocator.MoviesSection);


                    if (Helpers.UserCancels
                        (MainImportingEngine
                        .SpecialStatus, null))
                        return false;


                    MeePopupProvider
                        .ImportMeePopupProviderField
                        (MediaSectionsAllocator.MoviesSection);


                    //if (Settings.EnableXmlBackupFilms)
                    //    MediaLibrarySynchronizerBackup
                    //        .LibrarySynchronizerBackupMediaSection
                    //        (MediaSectionsAllocator.MoviesSection,
                    //        Settings.XmlBackupsDirectory);

                    #endregion
                }




            }



            return true;
        }
        private static bool CheckIfItemIsNotListedAndIgnoreOrDeleteIt(IMLItem item, IMDbOperations imdbOp)
        {

            if (!imdbOp.NotListed) return false;
            
            Debugger.LogMessageToFile
                ("[IMDb video identifier] The Item "
                 + item.Name + "was set as 'Not Listed'.");

            item.Tags["NotListed"] = "true";

            item.SaveTags();

            if (!imdbOp.DeleteItem) return true;
            Debugger.LogMessageToFile
                ("[IMDb video identifier] " +
                 "The Item " + item.Name + "was marked for removal from section.");

            item.Tags["ToDelete"] = "true";

            item.SaveTags();

            return true;
        
        }
        private static string IdentifyFilmByFingerprintOrTitle
            (IMLItem Item, string imdbid,
             ConnectionResult connectionresult,
             bool fileServerIsOnline,
             bool IsUNC, string location, 
             string parent, IMDbOperations imdbOP, 
             string year)
        {

            if (Settings.PrimaryFilmIdentificationMethod == "by video fingerprint")
            {


                imdbid = IdentifyMovieByVideoFingerprint
                    (Item, connectionresult, fileServerIsOnline,
                     IsUNC, location, parent);
             
                imdbid = FilmTitleMatchingEngine.IdentifyFilmByFilmTitleMatchingEngines
                    (Item,imdbid,imdbOP,
                     year,connectionresult);
          
           
            }
            else
            {

                FilmTitleMatchingEngine.IdentifyFilmByFilmTitleMatchingEngines
                    (Item,imdbid,imdbOP,year,connectionresult);
                
                imdbid = IdentifyMovieByVideoFingerprint
                    (Item, connectionresult, fileServerIsOnline, 
                    IsUNC, location, parent);         
            
            }


            return imdbid;
        }
        //TODO: Test if the overloads for this function are working correctly.
        //Used fy the Film Updater
        public static bool ExtractMetadataFromMovieFilename( IMLItem Item, ref string imdbid,
            ref IMDbOperations imdbOP, IEnumerable<string> combinedSceneTags)
        {

            //TODO: Make seperate options for filename filtering and metadata extraction.
            if (!Settings.ExtractMetadataFromFilenames)
                return false;

            if (String.IsNullOrEmpty(Item.Name))
                return false;

            try
            {

                //Importer.thisProgress.Progress(Importer.CurrentProgress, "Performing meta-information extraction...");
                Helpers.UpdateProgress("Performing diagnostic operations", "Performing meta-information extraction...", Item);
                Debugger.LogMessageToFile("Performing meta-information extraction...");


                imdbid = ExtractImdbIdFromFilename
                    (Item, imdbid, imdbOP, combinedSceneTags);


                #region filter name from release Tags

                Debugger.LogMessageToFile
                    ("[Video filename cleaner] " +
                     "Cleaning filename from common tags...");


                string itemName = Item.Name;

                itemName = VideoFilenameCleaner.CleanVideoFilename
                    (itemName, combinedSceneTags).Trim();

                itemName = VideoFilenameCleaner.CleanVideoFilename
                    (itemName, combinedSceneTags).Trim();

                itemName = VideoFilenameCleaner.CleanVideoFilename
                    (itemName, combinedSceneTags).Trim();

                Item.Name = itemName;
                Item.SaveTags();

                #endregion


                ExtractYearFromFilename(Item);


                //if ( !String.IsNullOrEmpty(location) )
                //Helpers.RecognizeSeries(TvEpisodesSection, Section, RanFromTvSection, Item, location);
                //TODO: This function should not be used!



            }
            catch (Exception e)
            {
                StatusForm.statusForm.TrayIcon.ShowBalloonTip(5000, "Error parsing filename", "An unexpected error ocurred in the filename parser. " + Environment.NewLine + 
                                                                                              "Please see the Debug.log file for details.", ToolTipIcon.Warning);
                Debugger.LogMessageToFile("An unexpected error occured in the filename parsing method. The error was: " + e.ToString() );
            }

            return false;
        }
        public static bool UpdateMediaSections
            (UpdateMediaSectionsParams updateMediaSectionsParams, 
            ref ConnectionResult connectionresult)
        {

            string pluginpath = Debugger.GetPluginPath();

            var imdbOp = new IMDbOperations();
            SetIMDbInternalTitleMatchingEngineProperties(imdbOp);

            bool fileServerIsOnline = true;
            bool fileServerChecked = false;

            MainImportingEngine.CurrentProgress = 0;
            MainImportingEngine.GeneralStatus = "Starting media updating process...";
            MainImportingEngine.SpecialStatus = "";


            try
            {
  



                if (
                    !MoviesSectionUpdater.UpdateMoviesSection
                    (pluginpath, ref fileServerChecked, ref fileServerIsOnline,
                    ref connectionresult, imdbOp,
                    updateMediaSectionsParams.MdfSettingsa,
                    updateMediaSectionsParams.Ibs,
                    updateMediaSectionsParams.CombinedSceneTags))
                    return true;

                if (
                    !TvSectionUpdater.UpdateTvSections
                    (updateMediaSectionsParams.Section,
                    ref fileServerChecked, ref fileServerIsOnline,
                    connectionresult, updateMediaSectionsParams.MdfSettingsb,
                    updateMediaSectionsParams.Ibs,
                    updateMediaSectionsParams.CombinedSceneTags))
                    return true;


                if (
                    !MusicSectionUpdater.UpdateMusicSection
                    (ref fileServerChecked, ref fileServerIsOnline,
                    connectionresult, updateMediaSectionsParams.MdfSettingsc,
                    updateMediaSectionsParams.Ibs))
                    return true;


            }
            catch (Exception e)
            {

                StatusForm.statusForm.TrayIcon.ShowBalloonTip(10000,
                        "Error updating Media Sections",
                        "The main Media Updating process returned an unexpected error." +
                        Environment.NewLine +
                        "Please refer to debug.log file (in the plugin's directory)" +
                        " for debugging information.",
                        ToolTipIcon.Error);


                Debugger.LogMessageToFile(Environment.NewLine +
                        "An unexpected error occured in DoImport() method. The error was: " +
                        Environment.NewLine + e + Environment.NewLine);


                MainImportingEngine.CurrentProgress = 100;

                MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress,
                        "The import process terminated unexpectidly due to an error.");


            }


            return true;
            
            
       
        }
        private static void TitleMatchingEngineUserSelectsResult(IMDbOperations imdbOp, bool resultsFound)
        {


            #region show film selection dialog

            imdbOp.NotListed = false;
            Debugger.LogMessageToFile("[IMDb video identifier] Showing video match selection dialog...");

            FrmSelect tmpFrmSelect;

// ReSharper disable ConvertIfStatementToConditionalTernaryExpression
            if (resultsFound)
// ReSharper restore ConvertIfStatementToConditionalTernaryExpression
                tmpFrmSelect = new FrmSelect(imdbOp.Title, IMDbOperations.Country, imdbOp.ImdbList);
            else tmpFrmSelect = new FrmSelect(imdbOp.Title, IMDbOperations.Country, FrmSelect.SearchType.IMDb);

            var dlResult = tmpFrmSelect.ShowDialog();


            if (dlResult == DialogResult.OK)
            {
                //MessageBox.Show("User pressed Submit");

                imdbOp.ImdbResult = (IIMDbSearchResult)tmpFrmSelect.SelectedResult;
                imdbOp.ImdbId = imdbOp.ImdbResult.IMDb_ID;
                imdbOp.Title = imdbOp.ImdbResult.Title;
                imdbOp.IsCustom = tmpFrmSelect.IsCustom;
            }
            if (dlResult == DialogResult.Cancel)
            {
                //MessageBox.Show("passed in the Just Ignore case");
                imdbOp.NotListed = true;
                tmpFrmSelect.Close();
                tmpFrmSelect.Dispose();
                //tmpFrmSelect = null;
            }
            if (dlResult == DialogResult.Abort)
            {
                //MessageBox.Show("passed in the Delete Item case");
                imdbOp.NotListed = true;
                imdbOp.DeleteItem = true;
                tmpFrmSelect.Close();
                tmpFrmSelect.Dispose();
                //tmpFrmSelect = null;
            }

            #endregion




        }
        private static void TitleMatchingEngineAutoDecideBestMatch(IMDbOperations imdbOp)
        {

            #region Return if Assist Mode is set to 'Skip unknown items'
            if (imdbOp._assistType == IMDbOperations.AssistType.SkipUnknownItems)
            {
                imdbOp.ImdbId = String.Empty;
                imdbOp.Title = String.Empty;
                return;

            }
            #endregion


            #region give automated IMDb result

            if (imdbOp.UseFirst)
            {
                #region Use First match Found
                //MessageBox.Show("Will use First Found");
                imdbOp.ImdbResult = TitleMatchingEngineHelpers.GetFirstMovie(imdbOp.ImdbList);
                if (imdbOp.ImdbResult == null) return;
                imdbOp.ImdbId = imdbOp.ImdbResult.IMDb_ID;
                imdbOp.Title = imdbOp.ImdbResult.Title;

                #endregion

            }
            else if (imdbOp.UseLatest)
            {
                #region Use Latest match
                ////MessageBox.Show("Will Use Latest");
                imdbOp.ImdbResult = TitleMatchingEngineHelpers.GetLatestMovie(imdbOp.ImdbList, imdbOp.Title);
                if (imdbOp.ImdbResult == null) return;

                imdbOp.ImdbId = imdbOp.ImdbResult.IMDb_ID;
                imdbOp.Title = imdbOp.ImdbResult.Title;

                #endregion
            }
            else if (imdbOp.UseMostPopular)
            {
                #region Use Most Popular match
                //MessageBox.Show("Will use Most Popular");
                
                //TODO: Why is this the same with the "Use First Found" setting?
                imdbOp.ImdbResult = TitleMatchingEngineHelpers.GetFirstMovie(imdbOp.ImdbList);

                if (imdbOp.ImdbResult == null) return;

                imdbOp.ImdbId = imdbOp.ImdbResult.IMDb_ID;
                imdbOp.Title = imdbOp.ImdbResult.Title;

                #endregion
            }

            #endregion




        }
        private static void TitleMatchingEngineDecideActionWhenNoPerfectMatch(IMDbOperations imdbOp)
        {


            Debugger.LogMessageToFile("[IMDb film Title matching engine] An exact match was not found.");

            if (imdbOp._assistType == IMDbOperations.AssistType.NoPerfectMatch)
            {
                #region If there is only one result found use it, else ask from user to select a result.
                Debugger.LogMessageToFile("[IMDb video identifier] Video matching assistance is enabled.");

                switch (imdbOp.ImdbList.Count)
                {
                    case 1:
                        Debugger.LogMessageToFile("[IMDb video identifier] Singular result detected. Will automatically select this match.");
                        imdbOp.ImdbResult = TitleMatchingEngineHelpers.GetFirstMovie(imdbOp.ImdbList);
                        if (imdbOp.ImdbResult == null) return;
                        imdbOp.ImdbId = imdbOp.ImdbResult.IMDb_ID;
                        imdbOp.Title = imdbOp.ImdbResult.Title;
                        break;
                    default:
                        TitleMatchingEngineUserSelectsResult(imdbOp, true);
                        break;
                }

                #endregion
            }
            else TitleMatchingEngineAutoDecideBestMatch(imdbOp);


        }
        internal static bool IdentifyVideo
            (ref string imdbid, ref string tmdbID, 
             ref IMDbOperations imdbOP, IMLItem Item, 
             bool fileServerIsOnline, bool IsUNC,
             string location, string parent, string Year, 
             ConnectionResult connectionresult,
             IMLSection moviesSection)
        {

            if (!connectionresult.InternetConnectionAvailable && Settings.ConnectionDiagnosticsEnabled)
                return false;


            imdbid = IdentifyFilmByFingerprintOrTitle
                (Item,imdbid,connectionresult,
                 fileServerIsOnline,IsUNC,
                 location,parent,imdbOP, Year);

          
            //TMDbID = TheMovieDb.GetTmdbIdByImdbId(Item);

            TheMovieDb.TmdbGetTmdbIdByFilmImdbId(Item);

            return true;
        
        }
        private static void IdentifyFilmByIMDbTitleMatchingEngineFirstInternalThenExternal
            (IMLItem item, IMDbOperations imdbOp, ConnectionResult connectionresult)
        {
            Debugger.LogMessageToFile
                ("[IMDb Film Title Matcher] " +
                 "Primary film Title matching engine was set to 'Internal'.");

            IMDbTitleMatchingEngineInternal.IdentifyFilmByIMDbInternalTitleMatchingEngine
                (item, connectionresult);

            IMDbTitleIdentifierExternal
                .IdentifyFilmByIMDbExternalTitleMatchingEngine
                (item, connectionresult);
        
        }
        private static bool TitleMatchingEngineTryToFindExactMatch(IMDbOperations imdbOp, IMLItem item, string year)
        {

            #region Vars

            var exactMatchFound = false;
            #endregion


            #region try to find exact match

            ////MessageBox.Show("Assited search disabled");
            // check first x results for exact match
            // if we have exact match, check for duplicates

            Debugger.LogMessageToFile("[IMDb video identifier] Attempting to find exact match...");
            imdbOp.ImdbResult = ExactMatchDetector.FindExactMatch(imdbOp.ImdbList.Count, imdbOp.Title, year, imdbOp.ImdbList, Helpers.GetTagValueFromItem(item, "VideoDuration"));

            if (imdbOp.ImdbResult != null)
                exactMatchFound = true;

            if (!exactMatchFound)
                return false;

            Debugger.LogMessageToFile("[IMDb video identifier] Exact match was found!");
            Debugger.LogMessageToFile("[IMDb video identifier] Detecting duplicates...");
            var duplicateExists = TitleMatchingEngineHelpers.DuplicatesExist(imdbOp.Title, year, imdbOp.ImdbList);


            if (duplicateExists)
            {
                Debugger.LogMessageToFile("[IMDb video identifier] A duplicate exists for this video.");
                imdbOp.ImdbId = String.Empty;
                imdbOp.ImdbResult = null;
                return false;
            }
            

            imdbOp.ImdbId = imdbOp.ImdbResult.IMDb_ID;
            imdbOp.Title = imdbOp.ImdbResult.Title;
            return true;

            #endregion





        }
        private static string IdentifyFilmByIMDbFilmTitleMatchingEngines
            (IMLItem item, string imdbid, IMDbOperations imdbOp,
             ConnectionResult connectionresult)
        {
            if (Settings.PrimaryIMDbFilmTitleMatchingEngine == "Internal")
            {
                IdentifyFilmByIMDbTitleMatchingEngineFirstInternalThenExternal
                    (item, imdbOp, connectionresult);
            }
            else
            {
                IdentifyFilmByIMDbTitleMatchingEngineFirstExternalThenInternal
                    (item, connectionresult);
            }

            return imdbid;
        }
        //TODO: This function should be changed to use regural expressions. 
        private static string ExtractImdbIdFromFilename(IMLItem item, string imdbid,
            IMDbOperations imdbOP, IEnumerable<string> combinedSceneTags)
        {
            if (item.Name.Contains("tt"))
            {
                //MessageBox.Show("Step 3");

                #region if imdb index is found...

                int imdbid_index = item.Name.IndexOf("tt");

                if ((item.Name.Length - imdbid_index) > 2)
                {

                    //MessageBox.Show("Step 4");
                    Char firstDigit = item.Name[imdbid_index + 2];
                    if (imdbid_index >= 0 && Char.IsNumber(firstDigit))
                    {
                        //MessageBox.Show("Step 5");
                        int imdb_index_start = imdbid_index;
                        int imdb_index_end = 0;
                        imdbid_index = imdbid_index + 2;
                        string substring = item.Name.Substring(imdbid_index, item.Name.Length - imdbid_index - 1);


                        for (int i = imdbid_index; i <= item.Name.Length; i++)
                        {

                            if (Char.IsNumber(item.Name[i]))
                            {
                                imdb_index_end = i;
                            }
                            else break;

                        }

                        //MessageBox.Show("Substring: " + substring); 
                        //MessageBox.Show( Convert.ToString("Index start: " + imdb_index_start) );
                        //MessageBox.Show(Convert.ToString("Index end: " + imdb_index_end));
                        int imdbid_length = imdb_index_end - imdbid_index + 1;
                        //MessageBox.Show("IMDbID length: " + imdbid_length);
                        //MessageBox.Show(Convert.ToString("start index: " + imdb_index_start));
                        imdbid = item.Name.Substring(imdbid_index, imdbid_length);
                        imdbid = "tt" + imdbid;
                        //MessageBox.Show("imdbid after extracting from filename: "+ imdbid);

                        //TODO: IMDb ID should be publicly accessible by all functions!
                        if (imdbOP != null)
                            imdbOP.ImdbId = imdbid;

                        item.Tags["ImdbID"] = imdbid;
                        string left_namepart = item.Name.Substring(0, imdb_index_start);
                        //MessageBox.Show("left part: " + left_namepart);
                        string right_namepart = item.Name.Substring(imdb_index_end + 1,
                                                                    item.Name.Length - imdb_index_end - 1);
                        //MessageBox.Show("Right part: " + right_namepart);
                        item.Name = left_namepart + right_namepart;
                        item.SaveTags();

                    }

                }

                #endregion

                Debugger.LogMessageToFile("ImdbID " + imdbid + " was extracted from item's name...");
            }
            return imdbid;
        }