예제 #1
0
        private static void OnFormattedDurationChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            MediaInfoData _mid = obj as MediaInfoData;

            if (_mid != null)
            {
                long _dur = Helpers.GetDurationSeconds(args.NewValue as string);

                long _ds = 0;
                if (string.IsNullOrEmpty(_mid.DurationSeconds) || long.TryParse(_mid.DurationSeconds, out _ds)) // seconds
                {
                    if (_dur != _ds && string.IsNullOrEmpty(_mid.DurationSeconds))
                    {
                        _mid.DurationSeconds = _dur.ToString();
                    }
                }
                _ds = 0;
                if (string.IsNullOrEmpty(_mid.Duration) || long.TryParse(_mid.Duration, out _ds)) // minutes
                {
                    if (_dur != _ds / 60)
                    {
                        _mid.Duration = ((int)(_dur / 60)).ToString();
                    }
                }
            }
        }
예제 #2
0
 // get the duration as double
 private static double GetDuration(MediaInfo mi)
 {
     if (mi != null)
     {
         return(MediaInfoData.GetDurationFromString(mi.Get(StreamKind.General, 0, "Duration")));
     }
     else
     {
         return(0d);
     }
 }
예제 #3
0
        private static void OnFileSizeChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            MediaInfoData _mid = obj as MediaInfoData;

            if (_mid != null && !string.IsNullOrEmpty(args.NewValue as string))
            {
                // comes in bytes, keep it formatted
                double _fs = 0;
                if (double.TryParse(args.NewValue as string, out _fs))
                {
                    _mid.FileSize = Helpers.GetFormattedFileSize(_fs);
                }
            }
        }
예제 #4
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);
            }
        }
예제 #5
0
        private static void SetFormat(MediaInfoData result, MediaInfo mi, string filePath)
        {
            if (mi != null)
            {
                string _format        = mi.Get(StreamKind.General, 0, "Format");
                string _formatCodec   = mi.Get(StreamKind.General, 0, "CodecID");
                string _formatProfile = mi.Get(StreamKind.General, 0, "Format_Profile").ToLowerInvariant();

                // store the untouche
                result.ContainerFormat = _format;

                if (!string.IsNullOrEmpty(_format))
                {
                    _format = _format.ToLowerInvariant();
                }
                if (_format.Contains("mpeg") || _format.Contains("avi") || _format.Contains("divx"))
                {
                    result.Format.Flag = MediaInfoFlags.Format_Mpeg;
                }
                if (_format.Contains("matroska"))
                {
                    result.Format.Flag = MediaInfoFlags.Format_MKV;
                }

                if (_format.Contains("dvd"))
                {
                    result.Format.Flag = MediaInfoFlags.Format_DVD;
                }

                if (Path.GetExtension(filePath).ToLowerInvariant().Contains("m2ts") || _format.Contains("blu-ray"))
                {
                    result.Format.Flag = MediaInfoFlags.Format_Bluray;
                }

                if (_formatCodec.Contains("qt") || _formatProfile.Contains("quicktime"))
                {
                    result.Format.Flag = MediaInfoFlags.Format_Mov;
                }

                if (_format.Contains("realmedia") || _formatCodec.Contains("rv40"))
                {
                    result.Format.Flag = MediaInfoFlags.Format_Rmvb;
                }

                //duration
                //string _duration = string.Empty;
                double _dur = GetDuration(mi); // milliseconds
                result.DurationSeconds = ((int)(_dur / 1000)).ToString();
            }
        }
예제 #6
0
        private void OnCurrentDirectoryChanged(object sender, EventArgs args)
        {
            TextContent = null;

            if (FileManager.Configuration.Options.FileBrowserOptions.ShowMediaInfo)
            {
                MediaData = new MediaInfoData();

                DirInfo _dir = (DataContext as ExplorerWindowViewModel).CurrentDirectory;
                if (_dir.DirType == ObjectType.File)
                {
                    Refresh(_dir.Path);
                }
            }
            else
            {
                TextContent = MEDIA_INFO_OFF;
                MediaData   = null;
            }
        }
예제 #7
0
 private void PatchMediainfo(MediaInfoData dest)
 {
     if (dest != null)
     {
         dest.EmbeddedSubtitles     = PatchListItem <EmbeddedSubtitle>(dest.EmbeddedSubtitles, MediaInfo.EmbeddedSubtitles);
         dest.ExternalSubtitlesList = PatchListItem <EmbeddedSubtitle>(dest.ExternalSubtitlesList, MediaInfo.ExternalSubtitlesList);
         dest.ContainerFormat       = PatchStringItem(dest.ContainerFormat, MediaInfo.ContainerFormat);
         dest.AudioCodec            = PatchStringItem(dest.AudioCodec, MediaInfo.AudioCodec);
         dest.AudioBitrate          = PatchStringItem(dest.AudioBitrate, MediaInfo.AudioBitrate);
         dest.VideoCodec            = PatchStringItem(dest.VideoCodec, MediaInfo.VideoCodec);
         dest.VideoBitrate          = PatchStringItem(dest.VideoBitrate, MediaInfo.VideoBitrate);
         dest.OverallBitrate        = PatchStringItem(dest.OverallBitrate, MediaInfo.OverallBitrate);
         dest.AspectRatio           = PatchStringItem(dest.AspectRatio, MediaInfo.AspectRatio);
         dest.FileSizeBytes         = PatchStringItem(dest.FileSizeBytes, MediaInfo.FileSizeBytes);
         dest.Duration      = PatchStringItem(dest.Duration, MediaInfo.Duration);
         dest.FrameRate     = PatchStringItem(dest.FrameRate, MediaInfo.FrameRate);
         dest.Language      = PatchStringItem(dest.Language, MediaInfo.Language);
         dest.LanguageCode  = PatchStringItem(dest.LanguageCode, MediaInfo.LanguageCode);
         dest.LanguageCodes = PatchListItem <string>(dest.LanguageCodes, MediaInfo.LanguageCodes);
         dest.Languages     = PatchListItem <string>(dest.Languages, MediaInfo.Languages);
     }
 }
예제 #8
0
        private static void OnDurationSecondsChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            MediaInfoData _mid = obj as MediaInfoData;

            if (_mid != null)
            {
                double _dur = GetDurationFromString(args.NewValue as string);
                // set FormattedDuration, DurationSeconds based on the new value
                if (_dur != 0)
                {
                    TimeSpan _ts = TimeSpan.FromMilliseconds(_dur * 1000); // _dur comes as seconds
                    string   _s  = string.Format("{0}h {1}m", _ts.Hours, _ts.Minutes);
                    if (string.Compare(_s, _mid.FormattedDuration, true) != 0)
                    {
                        _mid.FormattedDuration = _s;
                    }
                }
                string _d = ((int)_dur / 60).ToString();
                if (string.Compare(_d, _mid.Duration, true) != 0)
                {
                    _mid.Duration = _d;
                }
            }
        }
예제 #9
0
        public static void DoGenerateNfoFile(bool silent, string moviePath, MovieInfo info, MediaInfoData mediainfo)
        {
            MovieInfo _info = null;

            try
            {
                _info = info;
            }
            catch { }

            if (_info == null)
            {
                return;
            }

            bool _doIt = true;

            if (File.Exists(FileManager.Configuration.GetMovieInfoPath(moviePath, false, MovieinfoType.Export))) // always use the Export naming for save
            {
                _doIt = MessageBox.Show("A MovieInfo file already exists. Do you want to replace it?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes;
            }

            if (_doIt && string.IsNullOrEmpty(_info.IMDBID))
            {
                if (silent)
                {
                    _doIt = true;
                }
                else
                {
                    _doIt = MessageBox.Show("Your data does not contain IMDb Id.\n\nIt is recommended to fill in the IMDB Id for a later more accurate detection.\n\nContinue without IMDb Id?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes;
                }
            }

            if (_doIt)
            {
                try
                {
                    nfoHelper.GenerateNfoFile(moviePath, info, mediainfo);
                    if (!silent)
                    {
                        MessageBox.Show("A .nfo file with the current Movie Info data was generated.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
예제 #10
0
 public static void GenerateNfoFile(string movieFilename, MovieInfo movie, MediaInfoData mediainfo, string targetPath)
 {
     SaveNfo(movieFilename, movie, mediainfo, targetPath);
 }
예제 #11
0
 public static void GenerateNfoFile(string movieFilename, MovieInfo movie, MediaInfoData mediainfo)
 {
     GenerateNfoFile(movieFilename, movie, mediainfo, FileManager.Configuration.GetMovieInfoPath(movieFilename, true, MovieinfoType.Export)); // always generate respecting the naming convention for Export!
 }
예제 #12
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);
                }
            }
        }
예제 #13
0
            public void ThreadPoolCallback()
            {
                try
                {
                    try
                    {
                        Loggy.Logger.Debug(string.Format("Entering Thread {0}", Thread.CurrentThread.ManagedThreadId));
                        Loggy.Logger.Factory.Flush();

                        try
                        {
                            MovieItem _movieItem = FileManager.GetMovieByFilePath(this.MoviePath);
                            FileManager.SetMovieItemStatus(_movieItem, MovieItemStatus.Querying);
                        }
                        catch { }

                        MoviesheetsUpdateManager _man = new MoviesheetsUpdateManager(this.MetadataFile, this.MoviePath);

                        MoviesheetInfo _metadataInfo = _man.GetMetadataInfo();

                        string _ext          = _metadataInfo != null && !string.IsNullOrEmpty(_metadataInfo.CoverExtension) ? _metadataInfo.CoverExtension : ".jpg";
                        string _tmpCoverPath = Helpers.GetUniqueFilename(_ext);
                        _ext = _metadataInfo != null && !string.IsNullOrEmpty(_metadataInfo.BackgroundExtension) ? _metadataInfo.BackgroundExtension : ".jpg";
                        string _tmpBackgroundPath = Helpers.GetUniqueFilename(_ext);
                        _ext = _metadataInfo != null && !string.IsNullOrEmpty(_metadataInfo.Fanart1Extension) ? _metadataInfo.Fanart1Extension : ".jpg";
                        string _tmpFanart1Path = Helpers.GetUniqueFilename(_ext);
                        _ext = _metadataInfo != null && !string.IsNullOrEmpty(_metadataInfo.Fanart2Extension) ? _metadataInfo.Fanart2Extension : ".jpg";
                        string _tmpFanart2Path = Helpers.GetUniqueFilename(_ext);
                        _ext = _metadataInfo != null && !string.IsNullOrEmpty(_metadataInfo.Fanart3Extension) ? _metadataInfo.Fanart3Extension : ".jpg";
                        string _tmpFanart3Path = Helpers.GetUniqueFilename(_ext);

                        MovieInfo     _movieinfo = _man.GetMovieInfo();
                        MediaInfoData _mediainfo = _movieinfo != null ? _movieinfo.MediaInfo : null;

                        Action ExtractImagesIfNeeded = new Action(delegate
                        {
                            if (!File.Exists(_tmpCoverPath))
                            {
                                _man.GetImage(MoviesheetsUpdateManager.COVER_STREAM_NAME, _tmpCoverPath);
                            }
                            if (!File.Exists(_tmpBackgroundPath))
                            {
                                _man.GetImage(MoviesheetsUpdateManager.BACKGROUND_STREAM_NAME, _tmpBackgroundPath);
                            }
                            if (!File.Exists(_tmpFanart1Path))
                            {
                                _man.GetImage(MoviesheetsUpdateManager.FANART1_STREAM_NAME, _tmpFanart1Path);
                            }
                            if (!File.Exists(_tmpFanart2Path))
                            {
                                _man.GetImage(MoviesheetsUpdateManager.FANART2_STREAM_NAME, _tmpFanart2Path);
                            }
                            if (!File.Exists(_tmpFanart3Path))
                            {
                                _man.GetImage(MoviesheetsUpdateManager.FANART3_STREAM_NAME, _tmpFanart3Path);
                            }
                        });

                        try
                        {
                            foreach (UpdateItem _item in Items)
                            {
                                // if cancellation was approved, jump out
                                if (CancelProcessing.WaitOne(20))
                                {
                                    return;
                                }

                                switch (_item.ItemType)
                                {
                                case UpdateItemType.Moviesheet:
                                case UpdateItemType.Extrasheet:
                                case UpdateItemType.ParentFoldersheet:
                                    if (_item.Template != null)
                                    {
                                        SheetType _sheetType = _item.ItemType == UpdateItemType.Extrasheet ? SheetType.Extra : _item.ItemType == UpdateItemType.ParentFoldersheet ? SheetType.Spare : SheetType.Main;

                                        MovieSheetsGenerator _Generator = new MovieSheetsGenerator(_sheetType, this.MoviePath);

                                        _Generator.SelectedTemplate = _item.Template;

                                        // call the Action responsible to extract images if missing
                                        ExtractImagesIfNeeded.Invoke();

                                        // try to get latest IMDB rating for the movie
                                        if (_movieinfo != null && FileManager.Configuration.Options.UpdateIMDbRating)
                                        {
                                            try
                                            {
                                                string _newRating = new IMDBMovieInfo().GetIMDbRating(_movieinfo.IMDBID);
                                                if (!string.IsNullOrEmpty(_newRating))
                                                {
                                                    _movieinfo.Rating = _newRating;
                                                    try
                                                    {
                                                        // update back the metadata (as the rating is needed for playlists)
                                                        using (MemoryStream _ms = new MemoryStream())
                                                        {
                                                            _movieinfo.Save(_ms, this.MoviePath, true);
                                                            _man.AddPart(NFO_STREAM_NAME, _ms);
                                                        }
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Loggy.Logger.DebugException("Updating Rating into .tgmd.", ex);
                                                    }
                                                }
                                            }
                                            catch { }
                                        }

                                        // set items

                                        _Generator.MovieInfo = _movieinfo;
                                        _Generator.MediaInfo = _mediainfo;
                                        _Generator.UpdateCover(_tmpCoverPath);
                                        _Generator.UpdateBackdrop(MoviesheetImageType.Background, _tmpBackgroundPath);
                                        _Generator.UpdateBackdrop(MoviesheetImageType.Fanart1, _tmpFanart1Path);
                                        _Generator.UpdateBackdrop(MoviesheetImageType.Fanart2, _tmpFanart2Path);
                                        _Generator.UpdateBackdrop(MoviesheetImageType.Fanart3, _tmpFanart3Path);

                                        _Generator.RenderAndReplicateMoviesheet(_item.TargetPath, true);
                                        _Generator.Dispose();
                                        _Generator.MovieInfo        = null;
                                        _Generator.MediaInfo        = null;
                                        _Generator.SelectedTemplate = null;
                                        _Generator = null;
                                    }
                                    break;

                                case UpdateItemType.Thumbnail:
                                    if (!File.Exists(_tmpCoverPath))
                                    {
                                        _man.GetImage(MoviesheetsUpdateManager.COVER_STREAM_NAME, _tmpCoverPath);
                                    }
                                    Helpers.CreateThumbnailImage(_tmpCoverPath, _item.TargetPath, FileManager.Configuration.Options.KeepAspectRatio);
                                    break;

                                case UpdateItemType.ExtraThumbnail:
                                    if (!File.Exists(_tmpCoverPath))
                                    {
                                        _man.GetImage(MoviesheetsUpdateManager.COVER_STREAM_NAME, _tmpCoverPath);
                                    }
                                    Helpers.CreateExtraThumbnailImage(_tmpCoverPath, _item.TargetPath);
                                    break;

                                case UpdateItemType.Nfo:
                                    if (_movieinfo != null)
                                    {
                                        nfoHelper.GenerateNfoFile(_item.MoviePath, _movieinfo, _movieinfo.MediaInfo != null ? _movieinfo.MediaInfo : null);
                                    }
                                    break;

                                case UpdateItemType.ImagesExport:
                                    Executor _executor = new Executor(_item.MoviePath);
                                    // make sure the images are extracted to their temp locations (as maybe no sheet needs to be generated, only export is wanted
                                    ExtractImagesIfNeeded.Invoke();
                                    // export images (that are required)
                                    _executor.ExportCover(_tmpCoverPath);
                                    _executor.ExportBackdrop(_tmpBackgroundPath, MoviesheetImageType.Background);
                                    _executor.ExportBackdrop(_tmpFanart1Path, MoviesheetImageType.Fanart1);
                                    _executor.ExportBackdrop(_tmpFanart2Path, MoviesheetImageType.Fanart2);
                                    _executor.ExportBackdrop(_tmpFanart3Path, MoviesheetImageType.Fanart3);
                                    break;
                                }
                            } // foreach

                            try
                            {
                                MovieItem _movieItem = FileManager.GetMovieByFilePath(this.MoviePath);
                                _movieItem.MovieItemStatus = MovieItemStatus.Done;
                            }
                            catch (Exception ex)
                            {
                                Loggy.Logger.DebugException("Set movieitem status:", ex);
                            }
                            _man = null;
                        }
                        finally
                        {
                            Helpers.RemoveFile(_tmpCoverPath);
                            Helpers.RemoveFile(_tmpBackgroundPath);
                            Helpers.RemoveFile(_tmpFanart1Path);
                            Helpers.RemoveFile(_tmpFanart2Path);
                            Helpers.RemoveFile(_tmpFanart3Path);
                        }
                    }

                    catch (Exception ex)
                    {
                        try
                        {
                            MovieItem _movieItem = FileManager.GetMovieByFilePath(this.MoviePath);
                            FileManager.SetMovieItemStatus(_movieItem, MovieItemStatus.Exception);
                            Loggy.Logger.DebugException(string.Format("Processing file {0}", this.MoviePath), ex);
                        }
                        catch { }
                    }
                }
                finally
                {
                    if (this.DoneEvent != null)
                    {
                        this.DoneEvent.Set();
                    }
                }
            }
예제 #14
0
 private static void ProcessSubtitles(MediaInfoData result, MediaInfo mi, string filePath)
 {
     // check embedded subtitles
     // process each sub and add it to the list
     if (mi != null && !IsISO(filePath))
     {
         try
         {
             int _subsCnt = mi.Count_Get(StreamKind.Text);
             if (_subsCnt != 0)
             {
                 for (int _i = 0; _i < _subsCnt; _i++)
                 {
                     EmbeddedSubtitle _sub = new EmbeddedSubtitle();
                     _sub.Format   = mi.Get(StreamKind.Text, _i, "Format");
                     _sub.Language = mi.Get(StreamKind.Text, _i, "Language");
                     if (string.IsNullOrEmpty(_sub.Language))
                     {
                         _sub.Language = mi.Get(StreamKind.Text, _i, "Title");
                     }
                     _sub.Language = string.IsNullOrEmpty(_sub.Language) ? FileManager.Configuration.Options.MovieSheetsOptions.DefaultExternalSubtitlesLanguage : _sub.Language;
                     if (PopulateLanguages(_sub))
                     {
                         if (!string.IsNullOrEmpty(_sub.Language) && !string.IsNullOrEmpty(_sub.Format))
                         {
                             result.EmbeddedSubtitles.Add(_sub);
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             Loggy.Logger.DebugException("Embedded subs: ", ex);
         }
     }
     // process also the external subtitles
     try
     {
         ExternalSubtitlesInfo _subtitles = CollectExternalSubtitles(filePath, false);
         if (_subtitles.HasExternalSubtitles)
         {
             foreach (ExtSubData _subData in _subtitles.SubFiles)
             {
                 EmbeddedSubtitle _sub = new EmbeddedSubtitle();
                 _sub.Format   = _subData.Format;
                 _sub.Language = _subData.TwoLetterLanguageCode;
                 if (PopulateLanguages(_sub))
                 {
                     if (!string.IsNullOrEmpty(_sub.Language) && !string.IsNullOrEmpty(_sub.Format))
                     {
                         result.ExternalSubtitlesList.Add(_sub);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Loggy.Logger.DebugException("External subs: ", ex);
     }
 }
예제 #15
0
        public static MediaInfoData GetMediaInfoData(string filePath, bool getTextData, bool getXml, bool getDetails, out string textData)
        {
            MediaInfoData _result = new MediaInfoData();

            textData = string.Empty;

            if (FileManager.Configuration.Options.DisableMediaInfoProcessing)
            {
                return(_result);
            }

            try
            {
                string _originalFilePath = filePath;

                if (IsISO(filePath))
                {
                    filePath = RedirectISO(filePath);
                    if (string.IsNullOrEmpty(filePath))
                    {
                        ProcessSubtitles(_result, null, _originalFilePath);
                        return(_result); // get out if u couldn't extract the .ifo
                    }
                }

                MediaInfo _mi = new MediaInfo();
                _mi.Open(filePath);

                if (getTextData)
                {
                    if (getXml)
                    {
                        _mi.Option("Inform", "XML");
                        textData = _mi.Inform();
                        // sometimes mediainfo returns invalid chars in node name. try to fix that (for now the &)
                        // Temporary Fix until it gets fixed in mediainfo
                        textData = Regex.Replace(textData, "(</?\\w+)(&)(\\w+)", "$1_$3", RegexOptions.IgnoreCase);
                        textData = Regex.Replace(textData, "(</?\\w+)(#)(\\w+)", "$1_$3", RegexOptions.IgnoreCase);
                    }
                    else
                    {
                        _mi.Option("Inform", "TEXT");
                        textData = _mi.Inform();
                    }
                }

                if (!getDetails)
                {
                    _mi.Close();
                    return(_result);
                }

                // format
                SetFormat(_result, _mi, filePath);

                // filesize (be aware of a possible redirection .iso->.ifo for example... use in that case the _originalFilePath
                string _filesize = string.Compare(_originalFilePath, filePath, true) == 0 ? _mi.Get(StreamKind.General, 0, "FileSize") : new FileInfo(_originalFilePath).Length.ToString();
                //double _fs = 0;
                //if (double.TryParse(_filesize, out _fs))
                //{
                //    _filesize = Helpers.GetFormattedFileSize(_fs);
                //}
                _result.FileSizeBytes = _filesize;

                // resolution
                // check resolution
                string _height      = _mi.Get(StreamKind.Video, 0, "Height");
                string _width       = _mi.Get(StreamKind.Video, 0, "Width");
                string _aspectRatio = _mi.Get(StreamKind.Video, 0, "DisplayAspectRatio");

                _result.VideoResolution = string.Format("{0}x{1}", _width, _height);

                // check aspect ratio
                if (!string.IsNullOrEmpty(_aspectRatio))
                {
                    double _aspect = 0d;
                    try
                    {
                        _aspect = Double.Parse(_aspectRatio.Replace(",", "."), CultureInfo.InvariantCulture);
                    }
                    catch { }

                    _aspectRatio = string.Format("{0:0.00}:1", _aspect).Replace(",", ".");
                    if (_aspect > 1.3 && _aspect < 1.4)
                    {
                        _aspectRatio = "4:3";
                    }
                    if (_aspect == 1.500)
                    {
                        _aspectRatio = "3:2";
                    }
                    if (_aspect > 1.7 && _aspect < 1.8)
                    {
                        _aspectRatio = "16:9";
                    }

                    if (_aspect > 2.3 && _aspect < 2.4)
                    {
                        _aspectRatio = "2.35:1";
                    }
                }
                _result.AspectRatio = _aspectRatio;

                // check refresh rate
                _result.FrameRate = _mi.Get(StreamKind.Video, 0, "FrameRate");

                int    _h  = 5000;
                int    _w  = 5000;
                double _ar = 0;
                Int32.TryParse(_height, out _h);
                Int32.TryParse(_width, out _w);
                double.TryParse(_aspectRatio, out _ar);

                if (_w != 0 && _h != 0)
                {
                    _result.Resolution.Flag = MediaInfoFlags.Resolution_288p;
                }
                if (_w > 320 && _h > 240)
                {
                    _result.Resolution.Flag = MediaInfoFlags.Resolution_480p;
                }

                if (_h >= 576)
                {
                    _result.Resolution.Flag = MediaInfoFlags.Resolution_576p;
                }

                if ((_ar == _16_9 && _w >= 1280 && _h >= 720) || (_ar != _16_9 && _w > 720 && _h > 544) || _w >= 1280)
                {
                    _result.Resolution.Flag = MediaInfoFlags.Resolution_720p;
                }

                if ((_ar == _16_9 && _w >= 1920 && _h >= 1080) || (_ar != _16_9 && _w > 1280 || _h > 817))
                {
                    _result.Resolution.Flag = MediaInfoFlags.Resolution_1080p;
                }

                // check overallbitrate
                _result.OverallBitrate = Helpers.GetFormattedBitrate(_mi.Get(StreamKind.General, 0, "OverallBitRate"));
                if (string.IsNullOrEmpty(_result.OverallBitrate))
                {
                    _result.OverallBitrate = Helpers.GetFormattedBitrate(_mi.Get(StreamKind.General, 0, "OverallBitRate_Nominal"));
                }

                // check videobitrate
                _result.VideoBitrate = Helpers.GetFormattedBitrate(_mi.Get(StreamKind.Video, 0, "BitRate"));
                if (string.IsNullOrEmpty(_result.VideoBitrate))
                {
                    _result.VideoBitrate = Helpers.GetFormattedBitrate(_mi.Get(StreamKind.Video, 0, "BitRate_Nominal"));
                }

                //check video codec
                string _fr = _mi.Get(StreamKind.Video, 0, "Format");
                if (!string.IsNullOrEmpty(_fr) && _fr.ToLowerInvariant().Contains("mpeg"))
                {
                    _result.Video.Flag = MediaInfoFlags.Video_mpeg;
                }

                string _videoCodec = _mi.Get(StreamKind.Video, 0, "CodecID/Hint");
                if (string.IsNullOrEmpty(_videoCodec))
                {
                    _videoCodec = _mi.Get(StreamKind.Video, 0, "CodecID");
                }

                // check videocodec
                _result.VideoCodec = GetCodecInfoText(_mi, StreamKind.Video);

                if (string.IsNullOrEmpty(_videoCodec))
                {
                    _videoCodec = _result.VideoCodec;
                }

                if (!string.IsNullOrEmpty(_videoCodec))
                {
                    _videoCodec = _videoCodec.ToLowerInvariant();
                }
                if (_videoCodec.Contains("xvid"))
                {
                    _result.Video.Flag = MediaInfoFlags.Video_Xvid;
                }
                if (_videoCodec.Contains("divx") || _videoCodec.Contains("dx"))
                {
                    _result.Video.Flag = MediaInfoFlags.Video_Divx;
                }
                if (_videoCodec.Contains("wmv"))
                {
                    _result.Video.Flag = MediaInfoFlags.Video_WMVHD;
                }
                if (_videoCodec.Contains("avc"))
                {
                    _result.Video.Flag = MediaInfoFlags.Video_H264;
                }
                if (!string.IsNullOrEmpty(_fr) && _fr.ToLowerInvariant().Contains("avc"))
                {
                    _result.Video.Flag = MediaInfoFlags.Video_H264;
                }


                // check language
                int _cnt = _mi.Count_Get(StreamKind.Audio);

                for (int _ia = 0; _ia < _cnt; _ia++)
                {
                    string _languageCode = _mi.Get(StreamKind.Audio, _ia, "Language");
                    if (string.IsNullOrEmpty(_languageCode))
                    {
                        _languageCode = FileManager.Configuration.Options.MovieSheetsOptions.DefaultAudioLanguage;
                    }
                    _result.LanguageCode = _ia == 0 || string.IsNullOrEmpty(_result.LanguageCode) ? _languageCode : _result.LanguageCode;
                    _result.LanguageCodes.Add(_languageCode);

                    if (!string.IsNullOrEmpty(_languageCode))
                    {
                        CultureInfo _ci = null;
                        try
                        {
                            _ci = Helpers.GetCultureInfo(_languageCode);
                        }
                        catch (Exception ex)
                        {
                            Loggy.Logger.DebugException("Lang2", ex);
                        }
                        if (_ci != null && _ci != CultureInfo.InvariantCulture)
                        {
                            _result.Language = _ia == 0 || string.IsNullOrEmpty(_result.Language) ? _ci.EnglishName : _result.Language;
                            _result.Languages.Add(_ci.EnglishName);
                        }
                    }
                }

                // check audio
                string _audioFormat   = _mi.Get(StreamKind.Audio, 0, "Format").ToLowerInvariant();
                string _audioCodec    = _mi.Get(StreamKind.Audio, 0, "CodecID").ToLowerInvariant();
                string _audioHint     = _mi.Get(StreamKind.Audio, 0, "CodecID/Hint").ToLowerInvariant();
                string _audioChannels = _mi.Get(StreamKind.Audio, 0, "Channel(s)").ToLowerInvariant();
                string _audioProfile  = _mi.Get(StreamKind.Audio, 0, "Format_Profile").ToLowerInvariant();

                _result.AudioBitrate = Helpers.GetFormattedBitrate(_mi.Get(StreamKind.Audio, 0, "BitRate"));
                if (string.IsNullOrEmpty(_result.AudioBitrate))
                {
                    _result.AudioBitrate = Helpers.GetFormattedBitrate(_mi.Get(StreamKind.Audio, 0, "BitRate_Nominal"));
                    if (string.IsNullOrEmpty(_result.AudioBitrate))
                    {
                        _result.AudioBitrate = _mi.Get(StreamKind.Audio, 0, "BitRate_Mode");
                    }
                }

                _result.AudioCodec    = GetCodecInfoText(_mi, StreamKind.Audio);
                _result.AudioChannels = _audioChannels;

                if (_audioFormat.Contains("dts") || _audioCodec.Contains("dts") || _audioHint.Contains("dts"))
                {
                    _result.Audio.Flag = MediaInfoFlags.Audio_DTS;
                }
                if (_audioFormat.Contains("dts") && (_audioProfile.Contains("ma")))
                {
                    _result.Audio.Flag = MediaInfoFlags.Audio_DTSHD;
                }

                if (_audioFormat.Contains("mp3") || _audioCodec.Contains("55") || _audioHint.Contains("mp3"))
                {
                    _result.Audio.Flag = MediaInfoFlags.Audio_MP3;
                }
                if (_audioFormat.Contains("ac-3") || _audioCodec.Contains("ac3") || _audioHint.Contains("ac3"))
                {
                    if (_audioChannels.Contains("6"))
                    {
                        _result.Audio.Flag = MediaInfoFlags.Audio_DolbyDigital;
                    }
                    else
                    {
                        _result.Audio.Flag = MediaInfoFlags.Audio_DolbyStereo;
                    }
                }
                if (_audioFormat.Contains("truehd") || (_audioCodec.Contains("truehd")))
                {
                    _result.Audio.Flag = MediaInfoFlags.Audio_DolbyTrueHD;
                }

                if (_audioFormat.Contains("aac") || _audioCodec.Contains("aac") || _audioHint.Contains("aac"))
                {
                    if (_audioChannels.Contains("6"))
                    {
                        _result.Audio.Flag = MediaInfoFlags.Audio_AAC51;
                    }
                    else
                    {
                        //if (_audioProfile.Contains("lc"))
                        //{
                        //    _result.Audio.Flag = MediaInfoFlags.Audio_AACStereoLC;
                        //}
                        //else
                        //{
                        _result.Audio.Flag = MediaInfoFlags.Audio_AACStereo;
                        //}
                    }
                }
                if (_audioFormat.Contains("flac") || _audioCodec.Contains("flac"))
                {
                    _result.Audio.Flag = MediaInfoFlags.Audio_Flac;
                }
                if (_audioFormat.Contains("wma") || _audioCodec.Contains("162"))
                {
                    _result.Audio.Flag = MediaInfoFlags.Audio_WMA;
                }
                if (_audioFormat.Contains("vorbis") || _audioCodec.Contains("vorbis"))
                {
                    _result.Audio.Flag = MediaInfoFlags.Audio_Vorbis;
                }

                ProcessSubtitles(_result, _mi, filePath);

                // set this flag for the ThumbGen's GUI.. to signal presence of any kind of subtitles
                string _subsLanguage = _mi.Get(StreamKind.Text, 0, "Language").ToLowerInvariant();
                if (!string.IsNullOrEmpty(_subsLanguage))
                {
                    _result.Subtitles.Flag = !string.IsNullOrEmpty(_result.SubtitlesText) || _result.ExternalSubtitlesList.Count != 0 ? MediaInfoFlags.Subtitles_Generic : MediaInfoFlags.Unknown;
                }

                _mi.Close();
            }
            catch { }

            return(_result);
        }
예제 #16
0
        public void CreateMovieInfoFile(MediaInfoData mediainfo, MovieInfo movieinfo)
        {
            MediaInfoData _mediainfo = mediainfo == null?MediaInfoManager.GetMediaInfoData(MoviePath) : mediainfo;

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