Ejemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string _testMovie = @"d:\Test\Inglorious Basterds [2009]\CD1 Inglorious Basterds.avi";
            string _ffmpeg    = @"d:\Work\mtn-200808a-win32\mtn.exe";
            //VideoScreenShot.MakeThumbnail(_testMovie);

            double _duration = 0d;                                 // MediaInfoManager.GetDurationMilliseconds(movieFilename);

            System.Windows.Size _size = new System.Windows.Size(); // MediaInfoManager.GetVideoResolution(movieFilename);
            MediaInfoManager.GetDurationAndVideoResolution(_testMovie, out _duration, out _size);

            int _cnt = 5;

            System.Windows.Size _thumbSize = FileManager.Configuration.Options.ThumbnailSize;
            double _rap = 1;

            if (_size.Width >= _size.Height)
            {
                _rap = _size.Width / _thumbSize.Width;
                _cnt = (int)Math.Round(_thumbSize.Height / (_size.Height / _rap));
            }
            else
            {
                _rap = _size.Height / _thumbSize.Height;
                _cnt = (int)Math.Round(_thumbSize.Width / (_size.Width / _rap));
            }

            //string _command = string.Format("{0} -i \"{1}\" -ss 0:0:5.0  -vframes 1  -vcodec png  -y -f      image2 frame.png",
            string _command = string.Format(" -o .tg.jpg -w {0} -t -c 1 -h 10 -r {1} -i -b 0.50 -D 12 -P \"{2}\"",
                                            FileManager.Configuration.Options.ThumbnailSize.Width, _cnt, _testMovie);
            string _imageUrl = Path.ChangeExtension(Helpers.GetCorrectThumbnailPath(_testMovie, true), ".tg.jpg");

            try
            {
                ProcessStartInfo _pi = new ProcessStartInfo(_ffmpeg, _command);
                _pi.CreateNoWindow  = true;
                _pi.UseShellExecute = false;
                Process.Start(_pi).WaitForExit(20000);


                if (File.Exists(_imageUrl))
                {
                    Helpers.CreateThumbnailImage(_imageUrl, Helpers.GetCorrectThumbnailPath(_testMovie, true), true, true, Helpers.ThumbnailSize, false, Helpers.MaxThumbnailFilesize);
                }
            }
            finally
            {
                if (File.Exists(_imageUrl))
                {
                    try
                    {
                        File.Delete(_imageUrl);
                    }
                    catch { }
                }
            }

            //MoviePlayer.Show(this, @"d:\Test\Inglorious Basterds [2009]\CD1 Inglorious Basterds.avi", null, new Size(0,0));
        }
Ejemplo n.º 2
0
 private void Refresh(string fileName)
 {
     if (!string.IsNullOrEmpty(fileName))
     {
         this.Dispatcher.BeginInvoke((Action) delegate
         {
             string _tmp = null;
             MediaData   = MediaInfoManager.GetMediaInfoData(fileName, true, false, true, out _tmp);
             TextContent = _tmp;
         }, DispatcherPriority.ApplicationIdle);
     }
 }
Ejemplo n.º 3
0
        public static bool AppendFullMediaInfoToNfoFile(MovieInfo info, string movieFilepath, Stream output)
        {
            bool _result = false;

            // try to add fullmediainfo to a ThumbGen generated .nfo file
            if (info != null)
            {
                using (MemoryStream _ms = new MemoryStream())
                {
                    // save MovieInfo to stream
                    info.Save(_ms, movieFilepath, false);
                    _ms.Position = 0;
                    // load the stream into _nfo
                    XmlDocument _nfo = new XmlDocument();
                    _nfo.Load(_ms);
                    // load the full media info into _media
                    XmlDocument _media           = new XmlDocument();
                    string      _tmpMediaDataXml = null;
                    MediaInfoManager.GetMediaInfoData(movieFilepath, true, true, false, out _tmpMediaDataXml);
                    if (!string.IsNullOrEmpty(_tmpMediaDataXml))
                    {
                        _media.LoadXml(_tmpMediaDataXml);
                    }
                    if (_media.DocumentElement != null)
                    {
                        // import the fullmedia in the _nfo document
                        XmlNode _nodeDest2 = _nfo.ImportNode(_media.DocumentElement, true);
                        _nfo.DocumentElement.AppendChild(_nodeDest2);
                    }

                    if (output != null)
                    {
                        output.Position = 0;
                        _nfo.Save(output);
                        output.Position = 0;
                        _result         = true;
                    }
                }
            }

            return(_result);
        }
Ejemplo n.º 4
0
        public void Save(Stream target, string movieFilename, bool appendMedia)
        {
            if (target != null)
            {
                try
                {
                    XmlSerializer _xs = new XmlSerializer(typeof(MovieInfo));
                    _xs.Serialize(target, this);

                    if (appendMedia)
                    {
                        try
                        {
                            MediaInfoManager.AppendFullMediaInfoToNfoFile(this, movieFilename, target);
                        }
                        catch { }
                    }
                }
                catch { }
            }
        }
Ejemplo n.º 5
0
        private static void SaveNfo(string movieFilename, MovieInfo movie, MediaInfoData mediainfo, string targetFile)
        {
            if (movie != null)
            {
                if (mediainfo != null)
                {
                    movie.MediaInfo = mediainfo;
                }

                movie.Filename = Path.GetFileName(movieFilename);

                // autotranslating items to English
                if (FileManager.Configuration.Options.MovieSheetsOptions.AutotranslateGenre && movie.Genre.Count != 0)
                {
                    Translator.TranslatorManager _tm = new Translator.TranslatorManager();
                    List <string> _glist             = new List <string>();

                    TextInfo _ti = new CultureInfo("en").TextInfo;

                    foreach (string _g in movie.Genre)
                    {
                        string _ss = _tm.Translate(_g);
                        if (!string.IsNullOrEmpty(_ss))
                        {
                            _ss = _ti.ToTitleCase(_ss);
                            _glist.Add(_ss);
                        }
                    }
                    movie.Genre = _glist;
                }

                string _folder = Path.GetDirectoryName(targetFile);
                Directory.CreateDirectory(_folder);
                try
                {
                    if (FileManager.Configuration.Options.ExportNfoAsTvixie) // Tvixie format
                    {
                        XmlSerializer _xs = new XmlSerializer(typeof(MovieInfo));
                        using (MemoryStream _ms = new MemoryStream())
                        {
                            XmlTextWriter _tw = new XmlTextWriter(_ms, Encoding.UTF8);
                            _tw.Formatting = Formatting.Indented;
                            _xs.Serialize(_tw, movie);
                            _ms.Position = 0;
                            MemoryStream _res = Helpers.XslTransformEmbededStream(TVIXIE_EXPORT_XSL, _ms, null);
                            using (FileStream _fs = new FileStream(targetFile, FileMode.Create, FileAccess.ReadWrite))
                            {
                                _res.CopyTo(_fs);
                            }
                            if (_res != null)
                            {
                                _res.Dispose();
                            }
                        }
                    }
                    else if (FileManager.Configuration.Options.ExportNfoAsWDTVHUB) // WDTV Live Hub format
                    {
                        XmlSerializer _xs = new XmlSerializer(typeof(MovieInfo));
                        using (MemoryStream _ms = new MemoryStream())
                        {
                            XmlTextWriter _tw = new XmlTextWriter(_ms, Encoding.UTF8);
                            _tw.Formatting = Formatting.Indented;
                            _xs.Serialize(_tw, movie);
                            _ms.Position = 0;
                            Dictionary <string, string> _params = new Dictionary <string, string>();
                            _params.Add("IsEpisode", EpisodeData.IsEpisodeFile(movieFilename) ? "1" : "0");
                            _params.Add("ExportBackdropsType", ((int)FileManager.Configuration.Options.NamingOptions.ExportBackdropType).ToString());
                            MemoryStream _res = Helpers.XslTransformEmbededStream(WDTVHUB_EXPORT_XSL, _ms, _params);
                            // format the xml
                            _res.Position = 0;
                            XmlReader _xr  = XmlReader.Create(_res);
                            XDocument _doc = XDocument.Load(_xr);
                            try
                            {
                                _res.Dispose();
                                _res = new MemoryStream();
                                XmlWriterSettings _set = new XmlWriterSettings();
                                _set.Indent = true;
                                XmlWriter _xw = XmlWriter.Create(_res, _set);
                                _doc.Save(_xw);
                                _xw.Close();
                            }
                            catch { }

                            // stupid patch for &
                            _res.Position = 0;
                            var str = PatchAmpersandAnd(Encoding.UTF8.GetString(_res.ToArray()));
                            using (var sw = new StreamWriter(targetFile))
                            {
                                sw.Write(str);
                            }
                            // Old way, before patching the &
                            //using (FileStream _fs = new FileStream(targetFile, FileMode.Create, FileAccess.ReadWrite))
                            //{
                            //    _res.Position = 0;
                            //    _res.CopyTo(_fs);
                            //}
                            _res.Dispose();
                        }
                    }
                    else if (FileManager.Configuration.Options.ExportNfoAsWDTVHUB_V2) // WDTV Live Hub format (new firmware)
                    {
                        XmlSerializer _xs = new XmlSerializer(typeof(MovieInfo));
                        using (MemoryStream _ms = new MemoryStream())
                        {
                            XmlTextWriter _tw = new XmlTextWriter(_ms, Encoding.UTF8);
                            _tw.Formatting = Formatting.Indented;
                            _xs.Serialize(_tw, movie);
                            _ms.Position = 0;
                            Dictionary <string, string> _params = new Dictionary <string, string>();
                            _params.Add("IsEpisode", EpisodeData.IsEpisodeFile(movieFilename) ? "1" : "0");
                            _params.Add("ExportBackdropsType", ((int)FileManager.Configuration.Options.NamingOptions.ExportBackdropType).ToString(CultureInfo.InvariantCulture));
                            MemoryStream _res = Helpers.XslTransformEmbededStream(WDTVHUB_EXPORT_XSL_V2, _ms, _params);
                            // format the xml
                            _res.Position = 0;
                            XmlReader _xr  = XmlReader.Create(_res);
                            XDocument _doc = XDocument.Load(_xr);
                            try
                            {
                                _res.Dispose();
                                _res = new MemoryStream();
                                XmlWriterSettings _set = new XmlWriterSettings();
                                _set.Indent = true;
                                XmlWriter _xw = XmlWriter.Create(_res, _set);
                                _doc.Save(_xw);
                                _xw.Close();
                            }
                            catch { }

                            // stupid patch for &
                            _res.Position = 0;
                            var str = PatchAmpersandAnd(Encoding.UTF8.GetString(_res.ToArray()));
                            using (var sw = new StreamWriter(targetFile))
                            {
                                sw.Write(str);
                            }
                            // Old way, before patching the &
                            //using (FileStream _fs = new FileStream(targetFile, FileMode.Create, FileAccess.ReadWrite))
                            //{
                            //    _res.Position = 0;
                            //    _res.CopyTo(_fs);
                            //}
                            _res.Dispose();
                        }
                    }
                    else if (FileManager.Configuration.Options.ExportNfoAsXBMC) // XBMC format
                    {
                        XmlSerializer _xs = new XmlSerializer(typeof(MovieInfo));
                        using (MemoryStream _ms = new MemoryStream())
                        {
                            XmlTextWriter _tw = new XmlTextWriter(_ms, Encoding.UTF8);
                            _tw.Formatting = Formatting.Indented;
                            _xs.Serialize(_tw, movie);
                            _ms.Position = 0;
                            MemoryStream _res = Helpers.XslTransformEmbededStream(XBMC_EXPORT_XSL, _ms, null);

                            _res.Position = 0;
                            XmlReader _xr  = XmlReader.Create(_res);
                            XDocument _doc = XDocument.Load(_xr);
                            try
                            {
                                // patch trailer
                                if (!string.IsNullOrEmpty(movie.Trailer))
                                {
                                    Match  m  = Regex.Match(movie.Trailer, "watch\\?v=(?<ID>.*)", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                                    string id = m.Success ? m.Groups["ID"].Value.Trim() : null;
                                    if (!string.IsNullOrEmpty(id))
                                    {
                                        XElement trailerNode = _doc.Descendants("trailer").FirstOrDefault();
                                        if (trailerNode == null)
                                        {
                                            trailerNode = new XElement("trailer");
                                        }
                                        trailerNode.Value = string.Format("plugin://plugin.video.youtube/?action=play_video&videoid={0}", id);
                                        _doc.Element("movie").Add(trailerNode);
                                    }
                                }

                                // patch mediainfo
                                if (mediainfo != null)
                                {
                                    Match  _m      = Regex.Match(mediainfo.VideoResolution, "(?<Width>\\d+)x(?<Height>\\d+)", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                                    string _width  = _m.Success ? _m.Groups["Width"].Value : "0";
                                    string _height = _m.Success ? _m.Groups["Height"].Value : "0";

                                    XElement _fileInfo = new XElement("fileinfo");
                                    _doc.Element("movie").Add(_fileInfo);
                                    XElement _streamDetails =
                                        new XElement("streamdetails",
                                                     new XElement("audio",
                                                                  new XElement("channels", mediainfo.AudioChannels),
                                                                  new XElement("codec", mediainfo.AudioCodec != null ? mediainfo.AudioCodec.Replace("-", "") : mediainfo.AudioCodec)),
                                                     new XElement("video",
                                                                  new XElement("aspect", mediainfo.AspectRatio),
                                                                  new XElement("duration", mediainfo.Duration),
                                                                  new XElement("codec", mediainfo.VideoCodec),
                                                                  new XElement("height", _height),
                                                                  new XElement("width", _width))
                                                     );
                                    _fileInfo.Add(_streamDetails);

                                    List <string> _subsList = MediaInfoManager.GetAllDistinctSubtitles(mediainfo.GetSubtitlesList(true, mediainfo.EmbeddedSubtitles), mediainfo.GetSubtitlesList(true, mediainfo.ExternalSubtitlesList));
                                    foreach (string _sub in _subsList)
                                    {
                                        XElement _s = new XElement("subtitle",
                                                                   new XElement("language"),
                                                                   new XElement("longlanguage", _sub)
                                                                   );
                                        _streamDetails.Add(_s);
                                    }
                                }
                                // end patch mediainfo
                                _res.Dispose();
                                _res = new MemoryStream();

                                XmlWriterSettings _set = new XmlWriterSettings();
                                _set.Indent = true;

                                XmlWriter _xw = XmlWriter.Create(_res, _set);

                                _doc.Save(_xw);
                                _xw.Close();
                            }
                            catch { }



                            using (FileStream _fs = new FileStream(targetFile, FileMode.Create, FileAccess.ReadWrite))
                            {
                                _res.Position = 0;
                                _res.CopyTo(_fs);
                            }
                            if (_res != null)
                            {
                                _res.Dispose();
                            }
                        }
                    }
                    else // ThumbGen's format
                    {
                        using (FileStream _fs = new FileStream(targetFile, FileMode.Create, FileAccess.ReadWrite))
                        {
                            XmlSerializer _xs = new XmlSerializer(typeof(MovieInfo));
                            XmlTextWriter _tw = new XmlTextWriter(_fs, Encoding.UTF8);
                            _tw.Formatting = Formatting.Indented;
                            _xs.Serialize(_tw, movie);
                        }

                        if (FileManager.Configuration.Options.PutFullMediaInfoToExportedNfo)
                        {
                            try
                            {
                                MediaInfoManager.AppendFullMediaInfoToNfoFile(targetFile, movieFilename);
                            }
                            catch { }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Loggy.Logger.DebugException("Gen nfo", ex);
                }
            }
        }
Ejemplo n.º 6
0
        public static bool MakeThumbnail2(string movieFilename, string targetFile)
        {
            bool _result = false;

            double _duration = 0d;                                 // MediaInfoManager.GetDurationMilliseconds(movieFilename);

            System.Windows.Size _size = new System.Windows.Size(); // MediaInfoManager.GetVideoResolution(movieFilename);
            MediaInfoManager.GetDurationAndVideoResolution(movieFilename, out _duration, out _size);

            if (_duration != 0d)
            {
                Collection <string> _snaps = new Collection <string>();

                Random _rnd = new Random();
                Dictionary <TimeSpan, object> _frames = new Dictionary <TimeSpan, object>();
                List <string> _filesList = new List <string>();
                try
                {
                    int _cnt = 5;
                    System.Windows.Size _thumbSize = FileManager.Configuration.Options.ThumbnailSize;
                    double _rap = 1;
                    if (_size.Width >= _size.Height)
                    {
                        _rap = _size.Width / _thumbSize.Width;
                        _cnt = (int)Math.Round(_thumbSize.Height / (_size.Height / _rap));
                    }
                    else
                    {
                        _rap = _size.Height / _thumbSize.Height;
                        _cnt = (int)Math.Round(_thumbSize.Width / (_size.Width / _rap));
                    }

                    for (int _i = 0; _i < _cnt; _i++)
                    {
                        string _thumb = Helpers.GetUniqueFilename(".jpg");
                        _filesList.Add(_thumb);
                        int _start = (int)((_i * _duration) / _cnt);
                        int _stop  = (int)(((_i + 1) * _duration) / _cnt);
                        _frames.Add(TimeSpan.FromMilliseconds((double)_rnd.Next(_start, _stop)), _thumb);
                    }

                    if (VideoScreenShot.CaptureScreen(new Uri(movieFilename, UriKind.RelativeOrAbsolute), _frames, makeJpeg))
                    {
                        VideoScreenShot.GenerateThumbnail(_filesList, targetFile);

                        if (FileManager.Configuration.Options.AutogenerateFolderJpg)
                        {
                            try
                            {
                                File.Copy(targetFile, FileManager.Configuration.GetFolderjpgPath(movieFilename, true), FileManager.Configuration.Options.OverwriteExistingThumbs);
                            }
                            catch { }
                        }

                        _result = true;
                    }
                }
                finally
                {
                    foreach (string _file in _filesList)
                    {
                        try
                        {
                            if (File.Exists(_file))
                            {
                                File.Delete(_file);
                            }
                        }
                        catch { }
                    }
                }
            }

            return(_result);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        private void GenerateNfoFile_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog _sfd = new SaveFileDialog();

            _sfd.Title      = "Select target .nfo file name";
            _sfd.Filter     = "All files (*.*)|*.*";
            _sfd.DefaultExt = ".nfo";

            if ((bool)_sfd.ShowDialog())
            {
                MediaInfoData _mi = string.IsNullOrEmpty(fsMovieFile.Filepath) ? null : MediaInfoManager.GetMediaInfoData(fsMovieFile.Filepath);
                nfoHelper.GenerateNfoFile(fsMovieFile.Filepath, m_MovieInfo, _mi, _sfd.FileName);
            }
        }
Ejemplo n.º 9
0
        public IEnumerable <FileInfo> CollectFiles(string path, bool recurseSubfolders, IEnumerable <string> extensionsToCollect, bool ignoreFilter)
        {
            List <FileInfo> _matchingFiles = new List <FileInfo>();

            try
            {
                //var files = from f in Directory.GetFiles(path, "*", recurseSubfolders ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
                //select new FileInfo(f);
                List <FileInfo> files = new List <FileInfo>();
                FindFile(path, "*.*", files, recurseSubfolders, ignoreFilter, extensionsToCollect);

                foreach (FileInfo _fi in files)
                {
                    // check if it is a dummy file
                    if (FileManager.IsDummyFile(_fi.FullName))
                    {
                        continue;
                    }

                    // filter out if it exists already
                    if (!_matchingFiles.Contains(_fi, new FileInfoComparer()) &&
                        (extensionsToCollect != null && extensionsToCollect.Count() != 0 && extensionsToCollect.Contains("*" + _fi.Extension.ToLowerInvariant())))
                    {
                        // check also filtering!
                        bool        _skip    = false;
                        UserOptions _options = FileManager.Configuration.Options;
                        if (!ignoreFilter && _options.FileBrowserOptions.IsFilterActive())
                        {
                            _skip = (_options.FileBrowserOptions.FilterWithoutMoviesheet && FileManager.Configuration.HasMoviesheet(_fi.FullName)) ||
                                    (_options.FileBrowserOptions.FilterWithoutExtraMoviesheet && FileManager.Configuration.HasExtraMoviesheet(_fi.FullName)) ||
                                    (_options.FileBrowserOptions.FilterWithoutMovieInfo && nfoHelper.HasMovieInfoFile(_fi.FullName)) ||
                                    (_options.FileBrowserOptions.FilterWithoutExtSubtitles && MediaInfoManager.HasExternalSubtitles(_fi.FullName)) ||
                                    (_options.FileBrowserOptions.FilterWithoutThumbnail && FileManager.Configuration.HasThumbnail(_fi.FullName)) ||
                                    (_options.FileBrowserOptions.FilterWithoutMetadata && FileManager.Configuration.HasMoviesheetMetadata(_fi.FullName)) ||
                                    (_options.FileBrowserOptions.FilterWithoutFolderJpg && FileManager.Configuration.HasFolderJpg(_fi.FullName));
                        }
                        if (!_skip)
                        {
                            _matchingFiles.Add(_fi);
                        }
                    }
                }

                //_matchingFiles = Sort<FileInfo>(_matchingFiles).ToList<FileInfo>();
            }
            catch (Exception ex)
            {
                Loggy.Logger.DebugException(string.Format("Exception collecting files from {0}:", path), ex);
            }

            return(_matchingFiles);
        }
Ejemplo n.º 10
0
        public void CreateMovieInfoFile(MediaInfoData mediainfo, MovieInfo movieinfo)
        {
            MediaInfoData _mediainfo = mediainfo == null?MediaInfoManager.GetMediaInfoData(MoviePath) : mediainfo;

            nfoHelper.GenerateNfoFile(MoviePath, movieinfo, _mediainfo);
        }