Example #1
0
        static List <BitmapSource> getImages(List <MediaFileItem> items, bool useThumbs)
        {
            List <BitmapSource> images = new List <BitmapSource>();

            foreach (MediaFileItem item in items)
            {
                if (MediaFormatConvert.isImageFile(item.Location) && !useThumbs)
                {
                    images.Add(new BitmapImage(new Uri(item.Location)));
                }
                else
                {
                    if (item.Metadata != null && item.Metadata.Thumbnail != null)
                    {
                        images.Add(item.Metadata.Thumbnail.Image);
                    }
                }
            }

            return(images);
        }
Example #2
0
        private bool getMediaFiles(System.IO.FileInfo info, object state)
        {
            if (CancellationToken.IsCancellationRequested)
            {
                return(false);
            }

            ScanLocation location = (state as Tuple <ScanLocation, ObservableCollection <ScanLocation>, List <String> >).Item1;
            ObservableCollection <ScanLocation> excludeLocations = (state as Tuple <ScanLocation, ObservableCollection <ScanLocation>, List <String> >).Item2;
            List <String> items = (state as Tuple <ScanLocation, ObservableCollection <ScanLocation>, List <String> >).Item3;

            String addItem = null;

            switch (location.MediaType)
            {
            case Search.MediaType.All:
            {
                if (MediaViewer.Model.Utils.MediaFormatConvert.isMediaFile(info.Name))
                {
                    addItem = info.FullName;
                }
                break;
            }

            case Search.MediaType.Images:
            {
                if (MediaFormatConvert.isImageFile(info.Name))
                {
                    addItem = info.FullName;
                }
                break;
            }

            case Search.MediaType.Video:
            {
                if (MediaFormatConvert.isVideoFile(info.Name))
                {
                    addItem = info.FullName;
                }
                break;
            }
            }

            if (addItem != null)
            {
                String path = FileUtils.getPathWithoutFileName(addItem);

                bool excluded = false;

                foreach (ScanLocation excludeLocation in excludeLocations)
                {
                    if (excludeLocation.IsRecursive)
                    {
                        if (path.StartsWith(excludeLocation.Location))
                        {
                            if (excludeLocation.MediaType == Search.MediaType.All ||
                                (excludeLocation.MediaType == Search.MediaType.Images && MediaFormatConvert.isImageFile(addItem)) ||
                                (excludeLocation.MediaType == Search.MediaType.Video && MediaFormatConvert.isVideoFile(addItem)))
                            {
                                excluded = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (path.Equals(excludeLocation.Location))
                        {
                            if (excludeLocation.MediaType == Search.MediaType.All ||
                                (excludeLocation.MediaType == Search.MediaType.Images && MediaFormatConvert.isImageFile(addItem)) ||
                                (excludeLocation.MediaType == Search.MediaType.Video && MediaFormatConvert.isVideoFile(addItem)))
                            {
                                excluded = true;
                                break;
                            }
                        }
                    }
                }

                if (!items.Contains(addItem) && !excluded)
                {
                    items.Add(addItem);
                }
            }

            return(true);
        }
Example #3
0
        private void startTranscode()
        {
            Dictionary <String, Object> options = new Dictionary <string, object>();

            if (State.Width != null)
            {
                options.Add("Width", State.Width.Value);
            }

            if (State.Height != null)
            {
                options.Add("Height", State.Height.Value);
            }

            options.Add("QualityLevel", State.JpegQuality);
            options.Add("Rotation", Enum.Parse(typeof(Rotation), State.JpegRotationCollectionView.CurrentItem.ToString()));
            options.Add("Interlace", Enum.Parse(typeof(PngInterlaceOption), State.PngInterlacingCollectionView.CurrentItem.ToString()));
            options.Add("TiffCompression", Enum.Parse(typeof(TiffCompressOption), State.TiffCompressionCollectionView.CurrentItem.ToString()));
            options.Add("FlipHorizontal", State.FlipHorizontal);
            options.Add("FlipVertical", State.FlipVertical);

            TotalProgress    = 0;
            TotalProgressMax = State.Items.Count;

            foreach (MediaFileItem item in State.Items)
            {
                if (CancellationToken.IsCancellationRequested)
                {
                    return;
                }

                FileStream imageStream = null;

                item.EnterReadLock();
                try
                {
                    ItemProgress = 0;

                    if (MediaFormatConvert.isImageFile(item.Location))
                    {
                        String outputPath = State.OutputPath + "\\" + Path.GetFileNameWithoutExtension(item.Location) + "." + ((String)State.OutputFormatCollectionView.CurrentItem).ToLower();

                        outputPath = FileUtils.getUniqueFileName(outputPath);

                        ItemInfo = "Loading image: " + item.Location;

                        imageStream = File.Open(item.Location, FileMode.Open, FileAccess.Read);
                        Rotation rotation = ImageUtils.getBitmapRotation(imageStream);
                        imageStream.Position = 0;

                        BitmapImage loadedImage = new BitmapImage();

                        loadedImage.BeginInit();
                        loadedImage.CacheOption  = BitmapCacheOption.OnLoad;
                        loadedImage.StreamSource = imageStream;
                        loadedImage.Rotation     = rotation;
                        loadedImage.EndInit();

                        imageStream.Close();
                        imageStream = null;

                        ItemInfo = "Writing image: " + outputPath;

                        ImageTranscoder.writeImage(outputPath, loadedImage, options,
                                                   State.IsCopyMetadata ? item.Metadata as ImageMetadata : null, this);

                        InfoMessages.Add("Finished: " + item.Location + " -> " + outputPath);
                    }
                    else
                    {
                        InfoMessages.Add("Skipped: " + item.Location + " is not a image file");
                    }

                    TotalProgress++;
                    ItemProgress = 100;
                }
                catch (Exception e)
                {
                    InfoMessages.Add("Error: " + e.Message);
                    Logger.Log.Error("Error: " + e.Message);
                    return;
                }
                finally
                {
                    item.ExitReadLock();
                    if (imageStream != null)
                    {
                        imageStream.Close();
                    }
                }
            }
        }
Example #4
0
        private bool iterateFiles(System.IO.DirectoryInfo location, object state)
        {
            if (CancellationToken.IsCancellationRequested)
            {
                return(false);
            }

            Tuple <ScanLocation, ObservableCollection <ScanLocation> > locationArgs = state as Tuple <ScanLocation, ObservableCollection <ScanLocation> >;

            ScanLocation scanLocation = locationArgs.Item1;
            ObservableCollection <ScanLocation> excludeLocations = locationArgs.Item2;

            FileInfo[] files = null;

            try
            {
                files = location.GetFiles("*.*");
            }
            catch (UnauthorizedAccessException e)
            {
                Logger.Log.Warn(e.Message);
            }
            catch (DirectoryNotFoundException e)
            {
                Logger.Log.Warn(e.Message);
            }

            List <BaseMetadata> staleItems = new List <BaseMetadata>();

            using (MetadataDbCommands metadataCommands = new MetadataDbCommands())
            {
                staleItems = metadataCommands.getAllMetadataInDirectory(location.FullName);
            }

            foreach (FileInfo info in files)
            {
                if (CancellationToken.IsCancellationRequested)
                {
                    return(false);
                }

                if (MediaViewer.Model.Utils.MediaFormatConvert.isMediaFile(info.Name))
                {
                    staleItems.RemoveAll(x => x.Name.Equals(info.Name));
                }

                String addItem = null;

                switch (scanLocation.MediaType)
                {
                case Search.MediaType.All:
                {
                    if (MediaViewer.Model.Utils.MediaFormatConvert.isMediaFile(info.Name))
                    {
                        addItem = info.FullName;
                    }
                    break;
                }

                case Search.MediaType.Images:
                {
                    if (MediaFormatConvert.isImageFile(info.Name))
                    {
                        addItem = info.FullName;
                    }
                    break;
                }

                case Search.MediaType.Video:
                {
                    if (MediaFormatConvert.isVideoFile(info.Name))
                    {
                        addItem = info.FullName;
                    }
                    break;
                }

                case Search.MediaType.Audio:
                {
                    if (MediaFormatConvert.isAudioFile(info.Name))
                    {
                        addItem = info.FullName;
                    }
                    break;
                }
                }

                if (addItem != null)
                {
                    String path = FileUtils.getPathWithoutFileName(addItem);

                    bool excluded = false;

                    foreach (ScanLocation excludeLocation in excludeLocations)
                    {
                        if (excludeLocation.IsRecursive)
                        {
                            if (path.StartsWith(excludeLocation.Location))
                            {
                                if (excludeLocation.MediaType == Search.MediaType.All ||
                                    (excludeLocation.MediaType == Search.MediaType.Images && MediaFormatConvert.isImageFile(addItem)) ||
                                    (excludeLocation.MediaType == Search.MediaType.Video && MediaFormatConvert.isVideoFile(addItem)))
                                {
                                    excluded = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (path.Equals(excludeLocation.Location))
                            {
                                if (excludeLocation.MediaType == Search.MediaType.All ||
                                    (excludeLocation.MediaType == Search.MediaType.Images && MediaFormatConvert.isImageFile(addItem)) ||
                                    (excludeLocation.MediaType == Search.MediaType.Video && MediaFormatConvert.isVideoFile(addItem)))
                                {
                                    excluded = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (!excluded)
                    {
                        importItem(info);
                    }
                }
            }

            if (staleItems.Count > 0)
            {
                using (MetadataDbCommands metadataCommands = new MetadataDbCommands())
                {
                    foreach (BaseMetadata staleItem in staleItems)
                    {
                        metadataCommands.delete(staleItem);
                    }
                }

                Logger.Log.Info("Removed " + staleItems.Count + " stale media items from " + location.FullName);
                InfoMessages.Add("Removed " + staleItems.Count + " stale media items from " + location.FullName);
            }

            return(true);
        }