Esempio n. 1
0
        public BackdropItem GetRandomBackdrop()
        {
            BackdropItem _result = null;

            if (FileManager.Configuration.Options.IsMTNPathSpecified)
            {
                string _filePath = Helpers.GetUniqueFilename(".jpg");
                try
                {
                    if (VideoScreenShot.MakeBackdropSnapshot(MoviePath, _filePath))
                    {
                        if (File.Exists(_filePath))
                        {
                            _result = PrepareBackdropItem(_filePath, true);
                        }
                    }
                }
                finally
                {
                    FileManager.AddToGarbageFiles(_filePath);
                }
            }

            return(_result);
        }
Esempio n. 2
0
        public void ImportCover(MovieSheetsGenerator generator, bool IsLoadFromMetadata, MoviesheetsUpdateManager metadatamanager)
        {
            if (!string.IsNullOrEmpty(this.CoverPath))
            {
                generator.UpdateCover(this.CoverPath);
                return;
            }

            bool _coverDone = false;

            //process cover
            // if import is selected and mask is not empty
            if (FileManager.Configuration.Options.MovieSheetsOptions.AutoSelectFolderjpgAsCover &&
                !string.IsNullOrEmpty(FileManager.Configuration.Options.MovieSheetsOptions.AutoSelectFolderjpgAsCoverName))
            {
                string _coverPath = null;
                if (ConfigHelpers.CheckIfFileExists(MoviePath, FileManager.Configuration.Options.MovieSheetsOptions.AutoSelectFolderjpgAsCoverName, out _coverPath))
                {
                    CoverPath = _coverPath;
                    // signal that MyOwnThumbnailFromDiskImage should be updated
                    IsMyOwnThumbnailFromDiskImageRequired = true;
                    // update the sheets generators
                    if (generator != null)
                    {
                        generator.UpdateCover(_coverPath);
                    }
                    _coverDone = true;
                }
            }

            if (metadatamanager == null)
            {
                metadatamanager = MetadataManager;
            }

            if (!_coverDone && IsLoadFromMetadata && metadatamanager != null)
            {
                string _tmpCover = Helpers.GetUniqueFilename(".jpg");
                FileManager.AddToGarbageFiles(_tmpCover);
                _coverDone = metadatamanager.GetImage(MoviesheetsUpdateManager.COVER_STREAM_NAME, _tmpCover);
                if (generator != null)
                {
                    generator.UpdateCover(_tmpCover);
                }
                CoverPath = _tmpCover;
                IsMyOwnThumbnailFromDiskImageRequired = true;

                _coverDone = true;
            }

            if (!_coverDone && generator != null)
            {
                generator.UpdateCover(DefaultCoverPath);
            }
        }
Esempio n. 3
0
        public static bool MakeThumbnail(string movieFilename, string targetFile)
        {
            bool _result = false;

            if (FileManager.Configuration.Options.IsMTNPathSpecified)
            {
                if (Path.GetExtension(movieFilename).ToLowerInvariant().Contains(".iso"))
                {
                    return(false);
                }

                int _cnt = 15;

                string _command = string.Format(" -o .tmp -w {0} -t -c 1 -h 10 -r {1} -i -b 0{2}50 -D 12 -P \"{3}\"",
                                                FileManager.Configuration.Options.ThumbnailSize.Width, _cnt, Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator, movieFilename);
                string _imageUrl = Path.ChangeExtension(movieFilename, ".tmp");

                FileManager.AddToGarbageFiles(_imageUrl);

                try
                {
                    ProcessStartInfo _pi = new ProcessStartInfo(FileManager.Configuration.Options.MTNPath, _command);
                    _pi.CreateNoWindow  = true;
                    _pi.UseShellExecute = false;
                    Process _p = Process.Start(_pi);
                    _p.WaitForExit(20000);

                    if (File.Exists(_imageUrl))
                    {
                        Helpers.CreateThumbnailImage(_imageUrl, targetFile, true, true, Helpers.ThumbnailSize, false, Helpers.MaxThumbnailFilesize);

                        if (FileManager.Configuration.Options.AutogenerateFolderJpg)
                        {
                            try
                            {
                                File.Copy(targetFile, FileManager.Configuration.GetFolderjpgPath(movieFilename, true), FileManager.Configuration.Options.OverwriteExistingThumbs);
                            }
                            catch { }
                        }
                        _result = true;
                    }
                }
                finally
                {
                    Helpers.RemoveFile(_imageUrl);
                }
            }
            return(_result);
        }
Esempio n. 4
0
 private void ImportFromMetadata(MoviesheetsUpdateManager metadatamanager)
 {
     // if there is a .tgmd file add images from inside to the own backdrops pool
     if (metadatamanager != null && File.Exists(metadatamanager.TargetFilename))
     {
         string _path = Helpers.GetUniqueFilename(".jpg");
         if (metadatamanager.GetImage(MoviesheetsUpdateManager.BACKGROUND_STREAM_NAME, _path))
         {
             FileManager.AddToGarbageFiles(_path);
             // add it to the pool too
             BackdropItem _item = PrepareBackdropItem(_path, false);
             AddBackdropToLists(_item, true);
         }
         _path = Helpers.GetUniqueFilename(".jpg");
         if (metadatamanager.GetImage(MoviesheetsUpdateManager.FANART1_STREAM_NAME, _path))
         {
             FileManager.AddToGarbageFiles(_path);
             // add it to the pool too
             BackdropItem _item = PrepareBackdropItem(_path, false);
             AddBackdropToLists(_item, true);
         }
         _path = Helpers.GetUniqueFilename(".jpg");
         if (metadatamanager.GetImage(MoviesheetsUpdateManager.FANART2_STREAM_NAME, _path))
         {
             FileManager.AddToGarbageFiles(_path);
             // add it to the pool too
             BackdropItem _item = PrepareBackdropItem(_path, false);
             AddBackdropToLists(_item, true);
         }
         _path = Helpers.GetUniqueFilename(".jpg");
         if (metadatamanager.GetImage(MoviesheetsUpdateManager.FANART3_STREAM_NAME, _path))
         {
             FileManager.AddToGarbageFiles(_path);
             // add it to the pool too
             BackdropItem _item = PrepareBackdropItem(_path, false);
             AddBackdropToLists(_item, true);
         }
     }
 }
Esempio n. 5
0
        public static bool MakeBackdropSnapshot(string movieFilename, string targetFile)
        {
            bool _result = false;

            if (FileManager.Configuration.Options.IsMTNPathSpecified)
            {
                if (Path.GetExtension(movieFilename).ToLowerInvariant().Contains(".iso"))
                {
                    return(false);
                }

                double _duration          = 0d;
                System.Windows.Size _size = new System.Windows.Size();
                MediaInfoManager.GetDurationAndVideoResolution(movieFilename, out _duration, out _size);

                // always skip 10% from the beginning and from the end of the movie
                int _minSkipSeconds = (int)((_duration / 1000) * 0.1);

                Random _rand = new Random();
                _duration = (int)(_duration / 1000);
                try
                {
                    int _omitSec = _rand.Next(_minSkipSeconds, (int)_duration / 2 - _minSkipSeconds); // choose a number between minSkipSeconds and half of the duration
                    int _omitEnd = _rand.Next(_minSkipSeconds, (int)_duration / 2 - _minSkipSeconds); // chose a number between minSkipSeconds and half of the duration

                    string _command  = string.Format(" -o .tmp -B {0} -E {1} -t -c 1 -r 1 -i -b 0{2}50 -D 6 -P \"{3}\"", _omitSec, _omitEnd, Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator, movieFilename);
                    string _imageUrl = Path.ChangeExtension(movieFilename, ".tmp");

                    FileManager.AddToGarbageFiles(_imageUrl);

                    try
                    {
                        ProcessStartInfo _pi = new ProcessStartInfo(FileManager.Configuration.Options.MTNPath, _command);
                        _pi.CreateNoWindow  = true;
                        _pi.UseShellExecute = false;
                        Process _p = Process.Start(_pi);
                        _p.WaitForExit(8000);

                        Thread.Sleep(1200); // wait for the file to become available
                        if (File.Exists(_imageUrl))
                        {
                            try
                            {
                                File.Copy(_imageUrl, targetFile, true);
                                _result = true;
                            }
                            catch (Exception ex)
                            {
                                Loggy.Logger.DebugException("Videosnapshot: ", ex);
                            }
                        }
                    }
                    finally
                    {
                        Helpers.RemoveFile(_imageUrl);
                    }
                }
                catch (Exception ex)
                {
                    Loggy.Logger.DebugException("Calculate skip ", ex);
                }
            }
            return(_result);
        }
Esempio n. 6
0
        private static string RedirectISO(string filename)
        {
            string _result = null;

            try
            {
                if (!string.IsNullOrEmpty(filename) && File.Exists(filename))
                {
                    List <string> _candidates = new List <string>();

                    // open the ISO file
                    VolumeManager volMgr = new VolumeManager();
                    volMgr.AddDisk(VirtualDisk.OpenDisk(filename, FileAccess.Read));

                    VolumeInfo volInfo = null;
                    volInfo = volMgr.GetLogicalVolumes()[0];

                    DiscUtils.FileSystemInfo fsInfo = FileSystemManager.DetectDefaultFileSystems(volInfo)[0];

                    using (DiscFileSystem _dfs = fsInfo.Open(volInfo))
                    {
                        foreach (string _fname in _dfs.GetFiles("", "*.*", SearchOption.AllDirectories))
                        {
                            string _fileExt = System.IO.Path.GetExtension(_fname).ToLowerInvariant();
                            if (_fileExt == ".ifo" || _fileExt == ".mpls")
                            {
                                _candidates.Add(_fname);
                            }
                        }

                        double _biggestDuration = 0d;
                        string _tmpBRResult     = "";
                        // select from the candidates the one that has the longest duration (if mpls skip files bigger than 10K)
                        foreach (string _cpath in _candidates)
                        {
                            string _cext = Path.GetExtension(_cpath).ToLowerInvariant();
                            string _tmp  = Helpers.GetUniqueFilename(_cext);
                            using (FileStream _fs = new FileStream(_tmp, FileMode.Create, FileAccess.Write))
                            {
                                using (Stream source = _dfs.OpenFile(_cpath, FileMode.Open, FileAccess.Read))
                                {
                                    source.CopyTo(_fs);
                                }
                            }

                            // if it is a DVD iso
                            if (_cext == ".ifo")
                            {
                                if (string.Compare(Path.GetFileNameWithoutExtension(_cpath), "video_ts", true) == 0)
                                {
                                    File.Delete(_tmp);
                                    // skip the menu
                                    continue;
                                }

                                // use first ifo that is not the menu
                                FileManager.AddToGarbageFiles(_tmp);
                                _result = _tmp;
                                break;
                            }

                            // if it is a BLURAY iso (choose biggest mpls file)
                            if (_cext == ".mpls")
                            {
                                long _length = new FileInfo(_tmp).Length;
                                if (Path.GetExtension(_cpath).ToLowerInvariant() == ".mpls" && _length > 10 * 1024)
                                {
                                    File.Delete(_tmp);
                                    continue; // take next one, this is too big and mediainfo will hang
                                }

                                if (GetDurationMilliseconds(_tmp) > _biggestDuration)
                                {
                                    // important.. add it to the garbage files
                                    //FileManager.AddToGarbageFiles(_tmp);
                                    //_result = _tmp;
                                    if (!string.IsNullOrEmpty(_tmpBRResult))
                                    {
                                        File.Delete(_tmpBRResult); // remove previous winner and remember the current one
                                    }
                                    _tmpBRResult = _tmp;
                                }
                                else
                                {
                                    File.Delete(_tmp);
                                }
                            }
                        }
                        if (string.IsNullOrEmpty(_result) && !string.IsNullOrEmpty(_tmpBRResult))
                        {
                            FileManager.AddToGarbageFiles(_tmpBRResult);
                            _result = _tmpBRResult;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Loggy.Logger.DebugException("ISO Processing", ex);
            }

            return(_result);
        }