private static bool ParseChildNodes(IMLItem item, string title, string videoHash, IEnumerable nodelist)
        {

            foreach (XmlNode childnode in
                from XmlNode node in nodelist
                where node.HasChildNodes
                from XmlNode childnode
                    in node.ChildNodes
                select childnode)
            {

                if (!ReadVideoHashAndTitle
                    (item, videoHash,
                    title, childnode))
                    return false;


                ReadAdditonalDetails
                    (item, childnode);

                item.SaveTags();
            }

            return true;
        }
        internal static string ConstructExtractedSubtitleFilename(IMLItem item, string zipfilePath, out string subtitleExtension)
        {
            string subtitleFilename =
                RecognizeCorrectSubtitle(zipfilePath);

            if (String.IsNullOrEmpty(subtitleFilename))
            {

                MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress,
                            "Could not extract subtitle. The archive is corrupt.");

                Debugger.LogMessageToFile("Could not extract subtitle for "
                            + item.Name + ". The archive is corrupt.");

                Thread.Sleep(Settings.SleepValue);

                subtitleExtension = null;

                return subtitleFilename;

            }

            subtitleExtension = subtitleFilename.Remove(0, subtitleFilename.Length - 4);

            return subtitleFilename;
        }
        private static bool ConstructMoveLocation(IMLItem item, 
            string extension, out string locationToMove)
        {

            bool cancelMoving;

            if (!Settings.SortingDestinationMusic.EndsWith(@"\"))
                Settings.SortingDestinationMusic = Settings.SortingDestinationMusic + @"\";


            string directoryToMove = ConstructMoveDirectory
                (item, out cancelMoving);


            string newFilename;

            if (ConstructNewFilename(item, out newFilename))
            {
                locationToMove = null;
                return true;
            }


            if (!directoryToMove.EndsWith(@"\"))
                directoryToMove = directoryToMove + @"\";


            locationToMove = directoryToMove +
                             newFilename + extension;


            return cancelMoving;

        }
        private static bool ReturnCases(bool deleteMissingLibraryEntries, 
            bool isUNC, bool fileServerIsOnline, string location,
                                        IMLItem item)
        {


            if (!deleteMissingLibraryEntries)
                return false;


            //if (!location.StartsWith(Settings.DvdDrive) || String.IsNullOrEmpty(Settings.DvdDrive))
            //{

            if (isUNC && !fileServerIsOnline)
                return false;


            Debugger.LogMessageToFile(String.Format("Validating item {0}...", item.Name));
            Helpers.UpdateProgress("Performing Diagnostic Operations", String.Format("Validating item {0}...", item.Name), item);


            return !File.Exists(location);
        
        
        }
        public static bool UploadVideoHash(IMLItem Item, string location, string imdbid, ConnectionResult connectionresult, bool FileServerIsOnline, bool IsUNC)
        {

            if (String.IsNullOrEmpty(imdbid))
            {
                Debugger.LogMessageToFile("[OSdb movie hash uploader] This video's IMDb ID is not available. Uploading of it's file hash cannot be performed.");
                return false;
            }

            if (!FileServerIsOnline && IsUNC)
            {
                Debugger.LogMessageToFile("[OSdb movie hash uploader] Your file server is offline. ");
                return false;
            }

            if (!File.Exists(location))
                return false;

            string moviehash = Helpers.GetTagValueFromItem(Item, "VideoHash");

            if (String.IsNullOrEmpty(moviehash))
                return false;

           
            #region get file info
            Debugger.LogMessageToFile("[OSdb movie hash uploader] Extracting file information for movie hash uploading...");
            FileInfo file = new FileInfo(location);
            long filesize = file.Length;
            string imdbidNumOnly = imdbid.Remove(0, 2);      
            #endregion

            return PerformUploading(Item, moviehash, connectionresult, filesize, imdbidNumOnly);
        
        }
        private static bool IdentifyFilmAndDownloadMetadata
            (IEnumerable <string> combinedSceneTags,
            IMLItem item, DirectoryInfo parent)
        {
            //TODO: Change this and other instances to "E.F.I.-processed"
            string processedFlag = Helpers
                                   .GetTagValueFromItem
                                       (item, "E.F.I.-processed");


            if (String.CompareOrdinal
                    (processedFlag,
                    "--processed--") == 0)
            {
                return(false);
            }



            if (SingleMovieItemUpdaterHelpers
                .PerformMovieIdentification
                    (combinedSceneTags,
                    parent, item))
            {
                return(true);
            }



            SetFilmItemProcessingFlags
            .SetDetailsFlag(item);


            return(false);
        }
예제 #7
0
        internal static void CleanItemNameSetOriginalTitleTag(IMLItem item)
        {
            string itemName = item.Name;

            if (String.IsNullOrEmpty(itemName))
            {
                return;
            }

            itemName  = itemName.Replace('_', ' ');
            itemName  = itemName.Replace('.', ' ');
            item.Name = itemName;


            string originalTitleTmp = Helpers.GetTagValueFromItem
                                          (item, "OriginalTitle");


            if (!String.IsNullOrEmpty(originalTitleTmp))
            {
                return;
            }

            item.Tags["OriginalTitle"] = item.Name;
            item.SaveTags();


            Debugger.LogMessageToFile(String.Format(
                                          "The item's original name {0} was stored to OrginalTitle tag.",
                                          item.Name));
        }
 public void ApplyRulesToItem(IMLItem item)
 {
     foreach (ReplacementRulesGroup group in this.ruleGroups)
     {
         group.ApplyRulesToItem(item);
     }
 }
        private static bool PerformUploading(IMLItem Item, string moviehash, ConnectionResult connectionresult, long filesize, string imdbidNumOnly)
        {
            try
            {
                MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress, "Updating video definitions database...");
                InsertVideoHash(Item, connectionresult.OsDbLoginResult.token, moviehash, filesize,
                                             imdbidNumOnly);
                return true;
            }
            catch
            {
                MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress,
                                               "Osdb database did not respond. Retrying...");
                Thread.Sleep(3000);
                try
                {
                    InsertVideoHash(Item, connectionresult.OsDbLoginResult.token, moviehash, filesize,
                                                 imdbidNumOnly);
                    return true;
                }
                catch
                {
                    Debugger.LogMessageToFile("Unable to communicate with OSdb. Video hash was not uploaded.");
                    MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress,
                                                   "Unable to communicate with OSdb. Video hash was not uploaded.");
                    return false;
                }

            }


        }//endof method
        private static void DeleteMediaImagesAndLibraryItem
            (IMLSection section, IMLItem item)
        {


            Debugger.LogMessageToFile(String.Format("The non-existent item {0}will be deleted from section.",
                item.Name));


            Helpers.UpdateProgress
                ("Performing Diagnostic Operations",
                String.Format("The non-existent item " +
                              "{0} will be deleted from section.",
                                item.Name), item);

            Thread.Sleep(100);


            string imageFile = item.ImageFile;
            string fanart = (string) item.Tags["fanart"];


            DeleteCoverAndFanartImages
                (fanart, imageFile);


            section.DeleteItem(item);
        
        
        }
        internal static bool WriteMovieDescriptor
            (IMLItem item, string itemTitle,
             string imdbid, string filmFolder,
             bool fileServerIsOnline, bool isUNC)
        {

            string movieHash = Helpers.GetTagValueFromItem(item, "Hash");
            string title = Helpers.GetTagValueFromItem(item, "Title");


            if (!ReturnCases(fileServerIsOnline, isUNC, title, movieHash))
                return false;


            var xmlpath = ConstructXmlDescriptorFilePath(item, filmFolder, movieHash);


            if (DescriptorAlreadyExists(item, xmlpath))
                return true;


            var doc = ConstructMovieXmlDescriptorFromSectionItem(item, itemTitle, imdbid, movieHash);


            return SaveXmlDocument(item, filmFolder, doc, xmlpath);


        }
        internal static void DownloadSeriesInformation(IMLItem item, string parentDir,
            ref string seriesName, ref string seriesID, bool fileServerIsOnline,
            bool isUNC, TVDBLib tvdb,string mdfSettingsb, IBaseSystem iBaseSystem )
        {


            if (String.IsNullOrEmpty(seriesName))
                return;

            WebClient client = new WebClient();
            bool foundSeries;

            TVdbTvEpisodeDetailsDownloaderHelpers.NormalizeSeriesName(ref seriesName);


            if (TVdbTvEpisodeDetailsDownloaderHelpers.GetSeriesMatchFromSectionOrTVDb(item, ref seriesName, out seriesID,
                tvdb, mdfSettingsb, iBaseSystem, out foundSeries))
                return;


            GetEpisodeKeysFromItemTagsAndPopulateEpisodeMetadata(item, seriesName, 
                seriesID, fileServerIsOnline, isUNC, tvdb, mdfSettingsb,
                iBaseSystem, client, foundSeries);
     
        
        }
        private static void ClearProcessedFlag(IMLItem item)
        {
            item.Tags["E.F.I.-processed"]
                = String.Empty;

            item.SaveTags();
        }
        //REFACTOR: 
        internal static void SetUpdateFlag(IMLItem item)
        {



            if (String.IsNullOrEmpty
                    (Helpers.GetTagValueFromItem
                         (item, "ImdbID")))
            {
                ClearProcessedFlag(item);
                return;
            }



            if (String.IsNullOrEmpty
                    (Helpers.GetTagValueFromItem
                         (item, "Year")))
            {
                ClearProcessedFlag(item);
                return;
            }



            if (String.IsNullOrEmpty
                    (Helpers.GetTagValueFromItem
                         (item, "Title")))
            {
                ClearProcessedFlag(item);
                return;
            }



            if (String.IsNullOrEmpty
                (Helpers.GetTagValueFromItem
                     (item, "OriginalTitle")))
            {
                ClearProcessedFlag(item);
                return;
            }
                

            if (String.IsNullOrEmpty
                (Helpers.GetTagValueFromItem
                     (item, "SortTitle")))
            {
                ClearProcessedFlag(item);
                return;
            }
                   


            item.Tags["E.F.I.-processed"]
                = "--processed--";
                
            item.SaveTags();
            
        }
        internal static bool CheckForExistingSubtitleSetHasSubtitleFlag
            (string itemName, IMLItem item, string parentPath,
             string subfilePathSrt, string subfilePathSub)
        {


            MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress,
                                                      "Determining if subtitle exists for " + item.Name);


            if (File.Exists(subfilePathSrt) || File.Exists(subfilePathSub))
            {
                item.Tags["HasSubtitle"] = "True";
                item.SaveTags();

                DeleteSubtitleZipFile(itemName, parentPath);

                return false; 
            
            }



            return true;
       
        }
        public static void FileIsInUse(string location, 
            bool fileServerIsOnline,
            IMLItem item)
        {
            if (!fileServerIsOnline)
                return;

            try
            {
                Debugger.LogMessageToFile("Checking if file is in use...");
                var filestream = File.OpenRead(location);
                filestream.Close();
                Settings.FileInUse = false;
            }
            catch (Exception)
            {
                Debugger.LogMessageToFile(String.Format
                    ("The file {0} is in use by another program.", location));

                UpdateProgress
                    ("Performing diagnostics",
                    String.Format
                    ("This item's media file {0} " +
                     "is in use by another program." +
                     " MediFairy can not perform" +
                     " this operation.", location));

                Thread.Sleep(1500);

                Settings.FileInUse = true;

            }
        }
        internal static void AddFileToSection
            (out IMLItem item, IMLSection section,
            string itemName, string itemLocation,
            string externalID)
        {
            //TODO: Implement option to not update the Media Section on each imported item.

            if (Settings.UpdateMediaSectionOnEachImportedItem)
            {
                section.BeginUpdate();
            }


            item = section.AddNewItem
                       (itemName, itemLocation);

            item.ExternalID = externalID;
            item.SaveTags();



            if (Settings.UpdateMediaSectionOnEachImportedItem)
            {
                section.EndUpdate();
            }
        }
        internal static string IdentifyMovieByVideoFingerprint(IMLItem item, ConnectionResult connectionresult, bool FileServerIsOnline, bool IsUNC, string location, string parent )
        {

            #region function variables

            string moviehash = Helpers.GetTagValueFromItem(item,"VideoHash");
            string imdbid = Helpers.GetTagValueFromItem(item,"ImdbID");
            #endregion


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

            #region Compute Hash
            if (String.IsNullOrEmpty(moviehash))
            {
                //if ( Importer.EnableHashing)
                //{
                if (!IsUNC || FileServerIsOnline)
                {
                    if (File.Exists(location))
                    {
                        Debugger.LogMessageToFile("Computing video fingerprint for " + item.Name + "...");
                        MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress, "Computing video fingerprint for " + item.Name + "...");
                        Thread.Sleep(200);
                        moviehash = Hasher.ComputeHash(location, item);
                        item.Tags["VideoHash"] = moviehash;
                        item.SaveTags();
                    }
                    else
                    {
                        MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress, "The video file in location field was not found. MediaFairy cannot identify this film.");
                        Thread.Sleep(Settings.SleepValue);
                    }
                }
                //}
            }
            else moviehash = Helpers.GetTagValueFromItem(item,"VideoHash");

            item.SaveTags();
            #endregion


            MovieDescriptorReader.ReadMovieDescriptor(item, moviehash, parent, item.Name );


            if (Settings.PrimaryVideoFingerprintMatchingSource == "OSDb")
            {
                OSDbVideoFingeprintIdentifier.IdentifyMovieByHashOSDb(item, connectionresult);
                imdbid = TMDbVideoFingerprintIdentifier.IdentifyMovieByHashTMDb(item, connectionresult);
            }
            else
            {
                TMDbVideoFingerprintIdentifier.IdentifyMovieByHashTMDb(item, connectionresult);
                imdbid = OSDbVideoFingeprintIdentifier.IdentifyMovieByHashOSDb(item, connectionresult);
            }

            return imdbid;
        }
예제 #19
0
 internal static bool PerformMovieIdentification
     (IEnumerable <string> combinedSceneTags,
     DirectoryInfo parent,
     IMLItem item)
 {
     return(ExtractMovieMetadataFromOfflineSources
                (combinedSceneTags, item));
 }
        internal static void RetrieveFileHash(IMLItem item, string location)
        {
            if (CheckForExistingHash(item))
                return;

            CalculateAndSaveHashToLibrary
                (item, location);
        }
        internal static void LinkFilmItemChains
            (IMLSection moviesSection,
             IMLItemList allFilmItems,
             IMLItem Item)
        {

            if (!MeediFier.Settings
                .FilmItemChainLinkerIsEnabled)
                return;


            if (allFilmItems == null
                || allFilmItems.Count <= 0)
                return;


            MainImportingEngine.ThisProgress.Progress
                (MainImportingEngine.CurrentProgress,
                 "scanning for un-linked files...");


            Application.DoEvents();


            foreach (IMLItem item in allFilmItems)
            {


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

                string itemToCompareImdbID = Helpers
                    .GetTagValueFromItem
                    (Item, "ImdbID");



                if (item.Location == Item.Location
                    || itemImdbID != itemToCompareImdbID)
                    continue;


                if (item.Location.StartsWith("|")
                    || Item.Location.StartsWith("|"))
                    continue;

                Item.Location =
                    "|" + Item.Location +
                    "|" + item.Location + "|";

                Item.SaveTags();

                moviesSection.DeleteItem(item);
            }


        }
        internal static bool GetSubtitleForVideo(string videoHash, string imdbid,
            string language, string logintoken, IMLItem item,
            string parentPath, string videoFilename, bool isMovie)
        {
            #region  vars
            WebClient webClient = new WebClient();
            webClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

            string firstsub = string.Empty;

            FastZip fz = new FastZip();
            #endregion

            if (string.IsNullOrEmpty(parentPath))
                return false;

            if (!parentPath.EndsWith(@"\"))
                parentPath += @"\";

            string zipfilePath = parentPath + videoHash + ".zip";

            try
            {

                firstsub = VideoSubtitleDownloaderHelpers.SearchForSubtitleByVideoHashParent(videoHash, language);

                if (!VideoSubtitleDownloaderHelpers.SearchForSubtitleByIMDbIdParent(imdbid, language,
                    logintoken, item, isMovie, ref firstsub))
                    return false;

                if (!VideoSubtitleDownloaderHelpers.PerformSubtitleDownload(item, zipfilePath, webClient, firstsub))
                    return false;

            }
            catch (Exception e)
            {
                MessageBox.Show(@"An error occured while trying to download
                the subtitle on online address: " + firstsub + @" to local location: "
                + zipfilePath + @". The error was: " + e);

                Debugger.LogMessageToFile("Error occured in subtitles downloading function: "
                    + e + ".  The intented subtitle zip location was: " + zipfilePath +
                    "  and oline subtitle location was: " + firstsub);

                return false;

            }

            if (!VideoSubtitleDownloaderHelpers.ValidateDownloadedDataAndRetry(language, item,
                firstsub, webClient, zipfilePath))
                return false;

            VideoSubtitleDownloaderHelpers.ExtractAndRenameSubtitle(language, item, parentPath,
                videoFilename, zipfilePath, fz);

            return true;
        }
        private static void GetEpisodeKeysFromItemTagsAndPopulateEpisodeMetadata
            (IMLItem item, string seriesName,
                            string seriesID, bool fileServerIsOnline,
                            bool isUNC, TVDBLib tvdb, string mdfSettingsb,
                            IBaseSystem iBaseSystem, WebClient client,
                            bool foundSeries)
        {

            if (!foundSeries)
            {
                MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress,
                "Series with name " + seriesName + " was not found.");

                Thread.Sleep(2000);
                
                return;
            
            }

            string episodeID = Helpers.GetTagValueFromItem(item, "EpisodeID");

            if (!String.IsNullOrEmpty(episodeID))
                return;
            
            int episodeNumber;
            int seasonNumber;

            if (TVdbTvEpisodeDetailsDownloaderHelpers
                .GetEpisodeKeysFromItemTags
                (item, out episodeNumber, out seasonNumber))
                return;

            if (seasonNumber == 0 || episodeNumber == 0)
                return;

            ITVDBEpisode episode;
            ITVDBSeries series;


            if (TVdbTvEpisodeDetailsDownloaderHelpers
                .GetSeriesAndEpisodeFromTVDb(seriesName, seriesID, tvdb,
                        episodeNumber, seasonNumber,
                        out episode, out series))
                return;


            TVdbTvEpisodeDetailsDownloaderHelpers
                .PopulateEpisodeMetadata
                (item, fileServerIsOnline, isUNC,
                        mdfSettingsb,
                        iBaseSystem, seasonNumber, client,
                        series,
                        episode);



        }
        //REFACTOR:
        internal static void SetUpdateFlag(IMLItem item)
        {
            if (String.IsNullOrEmpty
                    (Helpers.GetTagValueFromItem
                        (item, "ImdbID")))
            {
                ClearProcessedFlag(item);
                return;
            }



            if (String.IsNullOrEmpty
                    (Helpers.GetTagValueFromItem
                        (item, "Year")))
            {
                ClearProcessedFlag(item);
                return;
            }



            if (String.IsNullOrEmpty
                    (Helpers.GetTagValueFromItem
                        (item, "Title")))
            {
                ClearProcessedFlag(item);
                return;
            }



            if (String.IsNullOrEmpty
                    (Helpers.GetTagValueFromItem
                        (item, "OriginalTitle")))
            {
                ClearProcessedFlag(item);
                return;
            }


            if (String.IsNullOrEmpty
                    (Helpers.GetTagValueFromItem
                        (item, "SortTitle")))
            {
                ClearProcessedFlag(item);
                return;
            }



            item.Tags["E.F.I.-processed"]
                = "--processed--";

            item.SaveTags();
        }
 internal static bool DescriptorAlreadyExists(IMLItem item, string xmlpath)
 {
     if (File.Exists(xmlpath))
     {
         item.Tags["HasDescriptor"] = "true";
         item.SaveTags();
         return true;
     }
     return false;
 }
 public void ApplyRulesToItem(IMLItem item)
 {
     foreach (ReplacementRule rule in this.rules)
     {
         if (rule.ApplyRuleToItem(item))
         {
             break;
         }
     }
 }
예제 #27
0
        internal static void InitializeItemKeys
            (int itemID, IMLItem item, out string moviehash,
            out string imdbid, out string tmdbID,
            out string year, out string itemTitle,
            out string sortTitle, out string location)
        {
            MainImportingEngine.SpecialStatus
                = String.Format("Updating {0}...", item.Name);


            Debugger.LogMessageToFile
                (String.Format("{0}" +
                               "Starting to work with library item:" +
                               " {1} with ID: {2}",
                               Environment.NewLine,
                               item.Name, itemID));


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


            moviehash = Helpers
                        .GetTagValueFromItem
                            (item, "VideoHash");


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


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


            year = Helpers
                   .GetTagValueFromItem
                       (item, "Year");


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


            sortTitle = Helpers
                        .GetTagValueFromItem
                            (item, "SortTitle");



            location = item.Location;
        }
        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 bool ExtractMovieMetadataFromOfflineSources(IEnumerable<string> combinedSceneTags, IMLItem item)
        {
            if (MovieFileMetadataExtractor
                        .ExtractMetadataFromMovieFilename
                        (item, combinedSceneTags))
                        return true;

                    CleanItemNameSetOriginalTitleTag(item);

                    return false;
        }
        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;
        }
        internal static bool ExtractTitleFromItemAndSetSortTitleTag(IMLItem item)
        {
            if (String.IsNullOrEmpty
                        (ExtractTitleFromItem(item)))
                        return true;

                    SetFilmItemProcessingFlags
                        .SetSortTitleTag
                        (item);

                    return false;
        }
예제 #32
0
        internal static void UpdateProgress
            (string generalStatus,
            string specialStatus, IMLItem item)
        {

            Application.DoEvents();

            string importerText = String.IsNullOrEmpty(specialStatus)
                ? generalStatus : specialStatus;

            if (MainImportingEngine.ThisProgress == null)
                return;

            if (StatusForm.statusForm == null)
                return;


            MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress, importerText);

            StatusForm.statusForm.UpdateProgress(MainImportingEngine.CurrentProgress);

            StatusForm.statusForm.statusLabel.Text =
                !String.IsNullOrEmpty(generalStatus)
                ? generalStatus 
                : MainImportingEngine.GeneralStatus;
           
            Application.DoEvents();

            if (item != null)
            {
                StatusForm.statusForm.ItemNameLabel.Text = item.Name;

                string locationTmp = item.Location.Trim('|');
                string[] locations = locationTmp.Split('|');

                for (int i = 0; i < locations.Length; i++)
                {
                    if (i < 3)
                    StatusForm.statusForm.ItemLocationlistBox.Items[i] = locations[i];

                }


                StatusForm.statusForm.SpecialStatusLabel.Text = specialStatus;
            }

            Application.DoEvents();

            StatusForm.statusForm.Refresh();


        }
 internal IMLItem Query(IMLItem item)
 {
     string tagValues = this.ValuesOfChainingTags(item);
     if (this.cache.Keys.Contains(tagValues))
     {
         return this.cache[tagValues];
     }
     else
     {
         this.cache.Add(tagValues, item);
         return item;
     }
 }
        internal static bool PerformSecondaryFilmItemUpdating
            (IMLSection moviesSection,
             IMLItemList allFilmItems, IMLItem item)
        {

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


            //VideoSusbtitleDownloader
            //    .DownloadSubtitleForVideoParent
            //    (moviehash, imdbid, Item,
            //     location, connectionresult,
            //    Settings.UseSameSubtitlesFolder,
            //    Settings.SubtitlesFolder, true);
             

            //MediaArchivers
            //    .ArchiveFilm
            //    (Item, parent,
            //    Settings.ArchiveLocation);


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


            FilmItemChainLinker
                .LinkFilmItemChains
                (moviesSection,
                 allFilmItems, item);


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


            FilmItemProccessSigner
                .SignFilmItemProcess(item);



            return true;

        }
        internal static string RetrieveImdbidFromNfoFile(IMLItem Item,ref string ImdbID, bool FileServerIsOnline, bool IsUNC, DirectoryInfo parent, string pluginpath)
        {

            if (!Settings.EnableNfoParsing)
                return ImdbID;

            if (!String.IsNullOrEmpty(ImdbID))
                return ImdbID;

            if (!FileServerIsOnline && IsUNC)
                return ImdbID;


            try
            {

                 Debugger.LogMessageToFile("Entered .nfo parser.");

                 #region Detect if parent is Root (contains more than one films)

                 if (DirectoryContainsMultipleNfoFiles(parent))
                     return ImdbID;

                 if (ParentDirectoryIsAMediaSource(parent))
                     return ImdbID;

                 if (ParentDirectoryContainsMultipleVideoFiles(parent, pluginpath))
                     return ImdbID;

                #endregion

                    
                 #region search directory for .nfo files

                Debugger.LogMessageToFile("Searching film's directory for .nfo files...");
                // ReSharper disable LoopCanBeConvertedToQuery
                foreach (FileInfo file in parent.GetFiles("*.nfo", SearchOption.TopDirectoryOnly))
                // ReSharper restore LoopCanBeConvertedToQuery
                    ImdbID = ReadFileExtractImdbId(ImdbID, file, Item);

                #endregion
                        

            }
            catch (Exception e)
            {
                Debugger.LogMessageToFile("The .nfo file parsing method returned an unexpected error: " + e );
            }

            return ImdbID;
        }
        internal string ValuesOfChainingTags(IMLItem item)
        {
            MLItem tmpItem = new MLItem(null);
            tmpItem.CopyFrom(item);
            tmpItem.AddBaseTagsToTags();
            object tagValuesObject = tmpItem.Tags[this.import.Importer.TagsToChainBy[0]];
            string tagValues = (tagValuesObject == DBNull.Value) ? string.Empty : (string)tagValuesObject;
            foreach (string tagName in this.import.Importer.TagsToChainBy.Skip(1))
            {
                tagValues += "<**-**>" + tmpItem.Tags[tagName];
            }

            return tagValues;
        }
        public static string GetTagValueFromItem(IMLItem item, string tagName)
        {
            string tagValue = String.Empty;
               try
               {
               tagValue = (string)item.Tags[tagName];
               }
               // ReSharper disable EmptyGeneralCatchClause
               catch (Exception)
               // ReSharper restore EmptyGeneralCatchClause
               { }

               return tagValue;
        }
        internal static void SetSortTitleTag
            (IMLItem item)
        {
            string title = Helpers
                           .GetTagValueFromItem
                               (item, "Title");


            string sortTitle = Helpers
                               .GetTagValueFromItem
                                   (item, "SortTitle");



            if (String.IsNullOrEmpty(title))
            {
                return;
            }


            if (!String.IsNullOrEmpty(sortTitle))
            {
                return;
            }



            if (title.StartsWith("The"))
            {
                sortTitle = title.Remove
                                (0, 4) + ", The ";


                Debugger.LogMessageToFile
                    (String.Format
                        ("Set item's SortTitle to:" +
                        " '{0}'.", sortTitle));
            }
            else
            {
                sortTitle = title;
            }


            item.Tags["SortTitle"]
                = sortTitle;

            item.SaveTags();
        }
예제 #39
0
        internal static bool ExtractMovieMetadataFromOfflineSources
            (IEnumerable <string> combinedSceneTags, IMLItem item)
        {
            if (MovieFileMetadataExtractor
                .ExtractMetadataFromMovieFilename
                    (item, combinedSceneTags))
            {
                return(true);
            }


            CleanItemNameSetOriginalTitleTag(item);


            return(false);
        }
예제 #40
0
        internal static bool ExtractTitleFromItemAndSetSortTitleTag
            (IMLItem item)
        {
            if (String.IsNullOrEmpty
                    (ExtractTitleFromItem(item)))
            {
                return(true);
            }


            SetFilmItemProcessingFlags
            .SetSortTitleTag
                (item);


            return(false);
        }
        private static void AddToMoviesSection
            (FileSystemInfo file, IMLSection moviesSection,
            string fileName, string parentName,
            bool useParentFolder, out IMLItem item)
        {
            Application.DoEvents();



            if (useParentFolder)
            {
                Debugger.LogMessageToFile
                    ("Will use the parent directory's" +
                    " name as Item's name.");

                Debugger.LogMessageToFile
                    (String.Format
                        ("Adding file {0} to Films section...",
                        file.FullName));


                AddFileToSection
                    (out item, moviesSection,
                    parentName, file.FullName,
                    file.FullName);
            }
            else
            {
                Debugger.LogMessageToFile
                    ("Will use the file's" +
                    " name as Item's name.");

                Debugger.LogMessageToFile
                    (String.Format
                        ("Adding file {0}" +
                        " to Films section...",
                        file.FullName));


                AddFileToSection
                    (out item, moviesSection,
                    fileName, file.FullName,
                    file.FullName);
            }
        }
        public static string GetTagValueFromItem
            (IMLItem item, string tagName)
        {
            string tagValue = string.Empty;

            try
            {
                tagValue = (string)
                           item.Tags[tagName];
            }

            // ReSharper disable EmptyGeneralCatchClause
            catch
            // ReSharper restore EmptyGeneralCatchClause
            { }

            return(tagValue);
        }
        public static void FileIsInUse
            (string location,
            bool fileServerIsOnline,
            IMLItem item)
        {
            if (!fileServerIsOnline)
            {
                return;
            }


            try
            {
                Debugger.LogMessageToFile("Checking if file is in use...");
                var filestream = File.OpenRead(location);
                filestream.Close();
                Settings.FileInUse = false;
            }
            catch (Exception)
            {
                Debugger.LogMessageToFile(String.Format
                                              ("The file {0} is in use by another program.", location));

                UpdateProgress
                    ("Performing diagnostics",
                    String.Format
                        ("This item's media file {0} " +
                        "is in use by another program." +
                        " MediFairy can not perform" +
                        " this operation.", location));


                Thread.Sleep(1500);

                Settings.FileInUse = true;
            }
        }
        private static bool SearchForExistingItemInMoviesSection
            (FileSystemInfo file, IEnumerable <string> filmLocations,
            IMLSection section)
        {
            if (filmLocations == null)
            {
                return(false);
            }


            // ReSharper disable LoopCanBeConvertedToQuery
            foreach (var movieFolder in Settings.FilmsFolders)
            // ReSharper restore LoopCanBeConvertedToQuery
            {
                if (!file.FullName.Contains(movieFolder))
                {
                    continue;
                }

                //if (filmLocations.Any(location => location == file.FullName))
                //    return true;

                IMLItem item =
                    section.FindItemByExternalID
                        (file.FullName);


                if (item != null)
                {
                    return(true);
                }
            }


            return(false);
        }
예제 #45
0
        internal static string ExtractTitleFromItem
            (IMLItem item)
        {
            string itemTitle
                = Helpers.GetTagValueFromItem
                      (item, "Title");


            if (!String.IsNullOrEmpty(itemTitle))
            {
                return(itemTitle);
            }

            itemTitle = item.Name;

            if (!String.IsNullOrEmpty(itemTitle))
            {
                return(itemTitle);
            }


            itemTitle = String.Empty;
            return(itemTitle);
        }
        //TODO: This function should be changed to use regural expressions. 
        private static void ExtractYearFromFilename(IMLItem item)
        {


            #region First Try: Year in parenthesis
            int tempIndex = item.Name.IndexOf("[19");

            int yearIndex = tempIndex >= 0
                ? tempIndex + 1
                : 0;

            tempIndex = item.Name.IndexOf("(19");
            if (tempIndex >= 0) yearIndex = tempIndex + 1;

            tempIndex = item.Name.IndexOf(".19");
            if (tempIndex >= 0) yearIndex = tempIndex + 1;

            tempIndex = item.Name.IndexOf("[20");
            if (tempIndex >= 0) yearIndex = tempIndex + 1;

            tempIndex = item.Name.IndexOf("(20");
            if (tempIndex >= 0) yearIndex = tempIndex + 1;

            tempIndex = item.Name.IndexOf(".20");
            if (tempIndex >= 0) yearIndex = tempIndex + 1;
            #endregion

            #region Second Try: Year without parenthesis
            if (yearIndex == 0)
            {
                int lastChar = item.Name.Length - 1;
                int firstYearChar = lastChar - 3;
                string numberWord = item.Name.Substring(firstYearChar, 4);

                if (!numberWord.Contains("x") && !numberWord.Contains("E") 
                    && !numberWord.Contains("S") )
                    //the number extracted must Not belong to episode numbers
                {
                    if (item.Name.Length >= 8)
                    {
                        if (Char.IsDigit(item.Name[lastChar]))
                        {
                            if (Char.IsDigit(item.Name[firstYearChar]))
                            {
                                #region Second Try: Year without parenthesis
                                tempIndex = item.Name.IndexOf("19");
                                if (tempIndex >= 0) yearIndex = tempIndex;

                                tempIndex = item.Name.IndexOf("20");
                                if (tempIndex >= 0) yearIndex = tempIndex;
                                #endregion
                            }
                        }
                    }
                }
            }
            #endregion




            #region Extract Year and store it in item's tag

            if (yearIndex <= 0)
                return;

            string year = item
                .Name.Substring
                (yearIndex, 4);


            item.Tags["Year"] = year;
            item.SaveTags();


            item.Name = item.Name.Trim();
                       
            Char yearPrevChar = item.Name[yearIndex -1];



            if (String.CompareOrdinal(yearPrevChar.ToString
                (CultureInfo.InvariantCulture),
                '('.ToString(CultureInfo.InvariantCulture)) == 0 
                || String.CompareOrdinal(yearPrevChar.ToString
                (CultureInfo.InvariantCulture),
                '['.ToString(CultureInfo.InvariantCulture)) == 0 
                || String.CompareOrdinal(yearPrevChar.ToString
                (CultureInfo.InvariantCulture),
                '.'.ToString(CultureInfo.InvariantCulture)) == 0)
                yearIndex = yearIndex - 1;


            item.Name = item.Name.Substring(0, yearIndex);
            item.Name = item.Name.Trim();
            item.SaveTags();



            Debugger.LogMessageToFile
                (String.Format
                ("The film's Year ({0})" +
                 " was extracted from" +
                 " item's name.", year));


            #endregion

        }
        //TODO: This function should be changed to use regural expressions. 
        private static string ExtractImdbIdFromFilename
            (IMLItem item, IEnumerable<string> combinedSceneTags)
        {


            string imdbid = String.Empty;

            if (combinedSceneTags == null)
                return imdbid;

            
            if (!item.Name.Contains("tt"))
                return imdbid;


            int imdbidIndex
                = item.Name.IndexOf
                ("tt", StringComparison.Ordinal);


            if ((item.Name.Length - imdbidIndex) <= 2)
                return imdbid;


            Char firstDigit = item.Name[imdbidIndex + 2];
            if (imdbidIndex >= 0 && Char.IsNumber(firstDigit))
            {
                int imdbIndexStart = imdbidIndex;
                int imdbIndexEnd = 0;
                imdbidIndex = imdbidIndex + 2;
                //string substring = item.Name.Substring(imdbid_index, item.Name.Length - imdbid_index - 1);


                for (int i = imdbidIndex; i <= item.Name.Length; i++)
                {
                    if (Char.IsNumber(item.Name[i]))
                    {
                        imdbIndexEnd = i;
                    }
                    else break;
                }

                int imdbidLength = imdbIndexEnd - imdbidIndex + 1;
                imdbid = item.Name.Substring(imdbidIndex, imdbidLength);
                imdbid = "tt" + imdbid;


                item.Tags["ImdbID"] = imdbid;

                string leftNamepart = item.Name.Substring(0, imdbIndexStart);

                string rightNamepart = item.Name.Substring(imdbIndexEnd + 1,
                                                           item.Name.Length - imdbIndexEnd - 1);

                item.Name = leftNamepart + rightNamepart;
                item.SaveTags();
            }


            Debugger.LogMessageToFile
                (String.Format
                ("ImdbID {0} was extracted" +
                 " from item's name...", imdbid));



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


            if (!Settings.ExtractMetadataFromFilenames)
                return false;


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


           

            Helpers.UpdateProgress
                ("Performing diagnostic operations",
                "Performing local metadata extraction...");
                
            Debugger.LogMessageToFile
                ("Performing local metadata extraction...");



            try
            {

                 ExtractImdbIdFromFilename
                    (item, combinedSceneTags);



                item.Name = VideoFilenameCleaner
                    .CleanVideoFilename
                    (item.Name, combinedSceneTags );

                item.SaveTags();

                //TODO: The change I made to the video filename cleaner should avoid the need of calling this function more than once.
            
                item.Name = VideoFilenameCleaner
                    .CleanVideoFilename
                    (item.Name, combinedSceneTags).Trim();

                item.SaveTags();

                item.Name = VideoFilenameCleaner
                    .CleanVideoFilename
                    (item.Name, combinedSceneTags).Trim();


                item.SaveTags(); 


                ExtractYearFromFilename(item);



            }
            catch (Exception e)
            {

                
                Debugger.LogMessageToFile
                    ("An unexpected error occured" +
                     " in the filename parsing method. " +
                     "The error was: " + e );

            }

            return false;
        }
        //REFACTOR:
        internal static void SetDetailsFlag(IMLItem item)
        {
            if (
                (!String.IsNullOrEmpty
                     (Helpers.GetTagValueFromItem
                         (item, "Title")))
                &&
                (!String.IsNullOrEmpty
                     (Helpers.GetTagValueFromItem
                         (item, "Year")))
                &&
                (!String.IsNullOrEmpty
                     (Helpers.GetTagValueFromItem
                         (item, "Actors")))
                &&
                (!String.IsNullOrEmpty
                     (Helpers.GetTagValueFromItem
                         (item, "ActorRoles")))
                &&
                (!String.IsNullOrEmpty
                     (Helpers.GetTagValueFromItem
                         (item, "Director")))
                &&
                (!String.IsNullOrEmpty
                     (Helpers.GetTagValueFromItem
                         (item, "Genre")))
                &&
                (!String.IsNullOrEmpty
                     (Helpers.GetTagValueFromItem
                         (item, "LongOverview")))
                &&
                (!String.IsNullOrEmpty
                     (Helpers.GetTagValueFromItem
                         (item, "Overview")))
                &&
                (!String.IsNullOrEmpty
                     (Helpers.GetTagValueFromItem
                         (item, "Rating")))
                &&
                (!String.IsNullOrEmpty
                     (Helpers.GetTagValueFromItem
                         (item, "ReleaseDate")))
                &&
                (!String.IsNullOrEmpty
                     (Helpers.GetTagValueFromItem
                         (item, "Review")))
                &&
                (!String.IsNullOrEmpty
                     (Helpers.GetTagValueFromItem
                         (item, "Runtime")))
                &&
                (!String.IsNullOrEmpty
                     (Helpers.GetTagValueFromItem
                         (item, "Studio")))
                )
            {
                item.Tags
                ["HasDetails"]
                    = "True";

                item.SaveTags();
            }
            else
            {
                item.Tags
                ["HasDetails"]
                    = String.Empty;

                item.SaveTags();
            }
        }