private Image LoadMediaCoverArtPosterWithCache(string fullFilePath) //, bool dontReadFilesInCloud, bool isFileInCloud)
        {
            Image image = PosterCacheRead(fullFilePath);

            if (image != null)
            {
                return(image);               //Found in cache
            }
            try
            {
                if (File.Exists(fullFilePath)) //Files can always be moved, deleted or become change outside application (Also may occure when this Rename files)
                {
                    if (ImageAndMovieFileExtentionsUtility.IsVideoFormat(fullFilePath))
                    {
                        var ffMpeg = new NReco.VideoConverter.FFMpegConverter();

                        using (Stream memoryStream = new MemoryStream())
                        {
                            ffMpeg.GetVideoThumbnail(fullFilePath, memoryStream);

                            if (memoryStream.Length > 0)
                            {
                                image = Image.FromStream(memoryStream);
                            }
                            else
                            {
                                image = null;
                            }
                        }
                    }
                    else if (ImageAndMovieFileExtentionsUtility.IsImageFormat(fullFilePath))
                    {
                        bool wasFileLocked = false;
                        image = ImageAndMovieFileExtentionsUtility.LoadImage(fullFilePath, out wasFileLocked);
                        if (image == null && wasFileLocked && File.Exists(fullFilePath))
                        {
                            image = ImageAndMovieFileExtentionsUtility.LoadImage(fullFilePath, out wasFileLocked);
                        }
                        //if (image == null) image = Utility.LoadImageWithoutLock(fullFilePath);
                    }
                }
            } catch (Exception ex)
            {
                Logger.Warn(ex, "LoadMediaCoverArtPoster was not able to create poster of the file " + fullFilePath);
            }
            if (image != null)
            {
                PosterCacheAdd(fullFilePath, image);
            }
            return(image);
        }
        private Image LoadMediaCoverArtThumbnail(string fullFilePath, Size maxSize, FileStatus fileStatus)
        {
            Image image = null;

            try
            {
                if (ImageAndMovieFileExtentionsUtility.IsVideoFormat(fullFilePath))
                {
                    #region Load Video Thumbnail Poster
                    WindowsProperty.WindowsPropertyReader windowsPropertyReader = new WindowsProperty.WindowsPropertyReader();
                    image = windowsPropertyReader.GetThumbnail(fullFilePath);

                    //DO NOT READ FROM FILE - WHEN NOT ALLOWED TO READ CLOUD FILES
                    if (image == null && !fileStatus.IsInCloudOrVirtualOrOffline)
                    {
                        image = LoadMediaCoverArtPosterWithCache(fullFilePath);
                    }
                    #endregion
                }
                else if (ImageAndMovieFileExtentionsUtility.IsImageFormat(fullFilePath))
                {
                    #region Load Picture Thumbnail Poster
                    WindowsProperty.WindowsPropertyReader windowsPropertyReader = new WindowsProperty.WindowsPropertyReader();
                    image = windowsPropertyReader.GetThumbnail(fullFilePath);

                    //DO NOT READ FROM FILE - WHEN NOT ALLOWED TO READ CLOUD FILES
                    if (image == null && !fileStatus.IsInCloudOrVirtualOrOffline)
                    {
                        image = ImageAndMovieFileExtentionsUtility.ThumbnailFromFile(fullFilePath); //Fast version - onlt load thumbnail from file
                        if (image == null)
                        {
                            image = LoadMediaCoverArtPosterWithCache(fullFilePath);                 //Slow loading, load full image
                        }
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "LoadMediaCoverArtThumbnail");
            }

            if (image != null)
            {
                image = Utility.ConvertImageToThumbnail(image, maxSize, Color.White, false);
            }
            return(image);
        }
Beispiel #3
0
        public static List <FileEntry> WriteXtraAtom(
            List <Metadata> metadataListToWrite, List <Metadata> metadataListOriginal, List <string> allowedFileNameDateTimeFormats,
            string writeXtraAtomAlbumVariable, bool writeXtraAtomAlbumVideo,
            string writeXtraAtomCategoriesVariable, bool writeXtraAtomCategoriesVideo,
            string writeXtraAtomCommentVariable, bool writeXtraAtomCommentPicture, bool writeXtraAtomCommentVideo,
            string writeXtraAtomKeywordsVariable, bool writeXtraAtomKeywordsPicture, bool writeXtraAtomKeywordsVideo,
            bool writeXtraAtomRatingPicture, bool writeXtraAtomRatingVideo,
            string writeXtraAtomSubjectVariable, bool writeXtraAtomSubjectPicture, bool writeXtraAtomSubjectVideo,
            string writeXtraAtomSubtitleVariable, bool writeXtraAtomSubtitleVideo,
            string writeXtraAtomArtistVariable, bool writeXtraAtomArtistVideo,
            out Dictionary <string, string> writeXtraAtomErrorMessageForFile)

        {
            Logger.Debug("WriteXtraAtom - started");
            writeXtraAtomErrorMessageForFile = new Dictionary <string, string>(); //Clear out values
            List <FileEntry> filesUpdatedByXtraAtom = new List <FileEntry>();

            if (metadataListToWrite.Count <= 0)
            {
                return(filesUpdatedByXtraAtom);
            }
            if (metadataListToWrite.Count != metadataListOriginal.Count)
            {
                return(filesUpdatedByXtraAtom);
            }
            int writeCount = metadataListToWrite.Count;

            for (int updatedRecord = 0; updatedRecord < writeCount; updatedRecord++)
            {
                Metadata metadataToWrite  = metadataListToWrite[updatedRecord];
                Metadata metadataOriginal = metadataListOriginal[updatedRecord];

                Logger.Debug("WriteXtraAtom - " + metadataToWrite.FileFullPath);
                if (metadataToWrite == metadataOriginal)
                {
                    continue;                                      //No changes found in data, No data to write
                }
                #region Is Video or Image format?
                bool isVideoFormat = false;
                bool isImageFormat = false;

                if (ImageAndMovieFileExtentionsUtility.IsImageFormat(metadataToWrite.FileFullPath))
                {
                    isVideoFormat = false;
                    isImageFormat = true;
                }
                else if (ImageAndMovieFileExtentionsUtility.IsVideoFormat(metadataToWrite.FileFullPath))
                {
                    isVideoFormat = true;
                    isImageFormat = false;
                }
                #endregion

                #region Replace Variable
                string writeXtraAtomAlbumReult       = metadataToWrite.ReplaceVariablesWrittenByUser(writeXtraAtomAlbumVariable, allowedFileNameDateTimeFormats);
                string writeXtraAtomCategoriesResult = metadataToWrite.ReplaceVariablesWrittenByUser(writeXtraAtomCategoriesVariable, allowedFileNameDateTimeFormats);
                string writeXtraAtomCommentResult    = metadataToWrite.ReplaceVariablesWrittenByUser(writeXtraAtomCommentVariable, allowedFileNameDateTimeFormats);
                string writeXtraAtomKeywordsResult   = metadataToWrite.ReplaceVariablesWrittenByUser(writeXtraAtomKeywordsVariable, allowedFileNameDateTimeFormats);
                string writeXtraAtomSubjectResult    = metadataToWrite.ReplaceVariablesWrittenByUser(writeXtraAtomSubjectVariable, allowedFileNameDateTimeFormats);
                string writeXtraAtomSubtitleResult   = metadataToWrite.ReplaceVariablesWrittenByUser(writeXtraAtomSubtitleVariable, allowedFileNameDateTimeFormats);
                string writeXtraAtomArtistResult     = metadataToWrite.ReplaceVariablesWrittenByUser(writeXtraAtomArtistVariable, allowedFileNameDateTimeFormats);
                #endregion

                #region Write Xtra Atrom using Property Writer
                if (writeXtraAtomKeywordsPicture || writeXtraAtomKeywordsVideo || writeXtraAtomCategoriesVideo || writeXtraAtomAlbumVideo || writeXtraAtomSubtitleVideo ||
                    writeXtraAtomArtistVideo || writeXtraAtomSubjectVideo || writeXtraAtomCommentVideo || writeXtraAtomRatingVideo ||
                    writeXtraAtomSubjectPicture || writeXtraAtomCommentPicture || writeXtraAtomRatingPicture)
                {
                    try
                    {
                        Logger.Debug("WriteXtraAtom - Start write XtraAtom: " + metadataToWrite.FileFullPath);
                        using (WindowsPropertyWriter windowsPropertyWriter = new WindowsPropertyWriter(metadataToWrite.FileFullPath))
                        {
                            if (isVideoFormat)
                            {
                                if (writeXtraAtomCategoriesVideo)
                                {
                                    windowsPropertyWriter.WriteCategories(string.IsNullOrEmpty(writeXtraAtomCategoriesResult) ? null : writeXtraAtomCategoriesResult);
                                }
                                if (writeXtraAtomAlbumVideo)
                                {
                                    windowsPropertyWriter.WriteAlbum(string.IsNullOrEmpty(writeXtraAtomAlbumReult) ? null : writeXtraAtomAlbumReult);
                                }
                                if (writeXtraAtomSubtitleVideo)
                                {
                                    windowsPropertyWriter.WriteSubtitle_Description(string.IsNullOrEmpty(writeXtraAtomSubtitleResult) ? null : writeXtraAtomSubtitleResult);
                                }
                                if (writeXtraAtomArtistVideo)
                                {
                                    windowsPropertyWriter.WriteArtist_Author(string.IsNullOrEmpty(writeXtraAtomArtistResult) ? null : writeXtraAtomArtistResult);
                                }
                                if (writeXtraAtomSubjectVideo)
                                {
                                    windowsPropertyWriter.WriteSubject_Description(string.IsNullOrEmpty(writeXtraAtomSubjectResult) ? null : writeXtraAtomSubjectResult);
                                }
                                if (writeXtraAtomCommentVideo)
                                {
                                    windowsPropertyWriter.WriteComment(string.IsNullOrEmpty(writeXtraAtomCommentResult) ? null : writeXtraAtomCommentResult);
                                }
                                if (writeXtraAtomRatingVideo)
                                {
                                    windowsPropertyWriter.WriteRating((metadataToWrite.PersonalRatingPercent == null ? (int)0 : (int)metadataToWrite.PersonalRatingPercent));
                                }
                                if (writeXtraAtomKeywordsVideo)
                                {
                                    windowsPropertyWriter.WriteKeywords(string.IsNullOrEmpty(writeXtraAtomKeywordsResult) ? null : writeXtraAtomKeywordsResult);
                                }
                            }
                            else if (isImageFormat)
                            {
                                if (writeXtraAtomSubjectPicture)
                                {
                                    windowsPropertyWriter.WriteSubject_Description(string.IsNullOrEmpty(writeXtraAtomSubjectResult) ? null : writeXtraAtomSubjectResult);
                                }
                                if (writeXtraAtomCommentPicture)
                                {
                                    windowsPropertyWriter.WriteComment(string.IsNullOrEmpty(writeXtraAtomCommentResult) ? null : writeXtraAtomCommentResult);
                                }
                                if (writeXtraAtomRatingPicture)
                                {
                                    windowsPropertyWriter.WriteRating((metadataToWrite.PersonalRatingPercent == null ? (int)0 : (int)metadataToWrite.PersonalRatingPercent));
                                }
                                if (writeXtraAtomKeywordsPicture)
                                {
                                    windowsPropertyWriter.WriteKeywords(string.IsNullOrEmpty(writeXtraAtomKeywordsResult) ? null : writeXtraAtomKeywordsResult);
                                }
                            }

                            windowsPropertyWriter.Close();

                            filesUpdatedByXtraAtom.Add(new FileEntry(metadataToWrite.FileFullPath, FileHandler.GetLastWriteTime(metadataToWrite.FileFullPath)));
                        }
                    }
                    catch (Exception ex)
                    {
                        string error = "Failed to write Microsoft's own Xtra Atom Propery on file.: " + metadataToWrite.FileFullPath;
                        Logger.Error(ex, error);
                        writeXtraAtomErrorMessageForFile.Add(metadataToWrite.FileFullPath, error);
                    }
                }
                else
                {
                    Logger.Debug("WriteXtraAtom - nothing to updated: " + metadataToWrite.FileFullPath);
                }
                #endregion
            }
            return(filesUpdatedByXtraAtom);
        }