Пример #1
0
        public static EpisodeData GetEpisodeData(string filePath)
        {
            EpisodeData _result = new EpisodeData(filePath);

            _result.ExtractData();

            return(_result);
        }
Пример #2
0
        public override bool GetResults(string keywords, string imdbID, bool skipImages)
        {
            bool _result = false;

            m_IMDbId = imdbID;

            try
            {
                m_EpisodeData = EpisodeData.GetEpisodeData(this.CurrentMovie.Filename);
            }
            catch { }

            try
            {
                // don't start querying if there's no episode number detected
                if (!string.IsNullOrEmpty(m_EpisodeData.Episode) && GetMirrors())
                {
                    if (GetSeries(keywords))
                    {
                        foreach (KeyValuePair <int, TheTVDBSerieItem> _item in m_Series)
                        {
                            if (FileManager.CancellationPending)
                            {
                                return(ResultsList.Count != 0);
                            }

                            if (skipImages)
                            {
                                string          _id        = _item.Value.ID.ToString();
                                ResultMovieItem _movieItem = new ResultMovieItem(_id, _item.Value.Title, null, CollectorName);
                                _movieItem.MovieInfo = _item.Value.MovieInfo;
                                SetCurrentEpisodeRelatedInfo(Convert.ToInt32(_id), _movieItem.MovieInfo);

                                _movieItem.CollectorMovieUrl = !string.IsNullOrEmpty(_id) ? string.Format("http://thetvdb.com/index.php?tab=series&id={0}", _id) : null;
                                ResultsList.Add(_movieItem);
                            }
                            else
                            {
                                GetEpisodes(_item.Value);
                                GetPosters(_item.Value);
                            }

                            _result = true;
                        }
                    }
                }
            }
            catch { }

            return(_result);
        }
Пример #3
0
 public static bool IsSameSeriesBeingProcessed(string currentMoviePath, EpisodeData episodeData)
 {
     // do the trick only if you have detected current season and episode
     if (!string.IsNullOrEmpty(episodeData.Episode) /* && !string.IsNullOrEmpty(m_EpisodeData.Season)*/)
     {
         // check if maybe we are processing a known series
         // decide if it is a new series or the currently processed one
         if (string.Compare(CurrentSeriesHelper.SeriesRootFolder, TVShowsHelper.GetCurrentSeriesRootFolder(currentMoviePath), true) == 0)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #4
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);
                }
            }
        }
Пример #5
0
        public static bool Show(Window owner, string folder, string imageUrl)
        {
            BatchApplyFolderBox _box = new BatchApplyFolderBox();

            _box.Owner = owner;
            _box.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            _box.TheFolder.Text        = string.Format(@"{0}\", folder);

            _box.PromptWatermarkText.Visibility = (owner is ResultsListBox) ? (owner as ResultsListBox).Watermark.Visibility : Visibility.Collapsed;

            AsyncImageDownloader.GetImageAsync(_box, imageUrl, SetImageData);

            bool?_res = _box.ShowDialog();

            if (_res.HasValue && _res.Value)
            {
                bool _promptUser = FileManager.Configuration.Options.AddWatermark && (bool)_box.rbManual.IsChecked;
                _box.Dispatcher.BeginInvoke((Action) delegate
                {
                    IEnumerable <FileInfo> _movies = new FilesCollector().CollectFiles(folder, false);
                    string _season = string.Empty;

                    foreach (FileInfo _movie in _movies)
                    {
                        string _destFile = Helpers.GetCorrectThumbnailPath(_movie.FullName, true);
                        if (File.Exists(_destFile) && !_box.OverwriteAllFlag)
                        {
                            continue;
                        }

                        string _text = FileManager.Configuration.Options.WatermarkOptions.Text;

                        if (!_promptUser)
                        {
                            //detect season
                            EpisodeData _epData = EpisodeData.GetEpisodeData(_movie.Name);
                            string _s           = _epData.Season;
                            _season             = string.IsNullOrEmpty(_s) ? _season : _s;
                            // detect episode
                            string _episode = _epData.Episode;
                            if (string.IsNullOrEmpty(_episode))
                            {
                                // detect Cd number
                                _episode = KeywordGenerator.ExtractCDNumber(_movie.Name);
                                if (string.IsNullOrEmpty(_episode))
                                {
                                    // default text
                                    _episode = FileManager.Configuration.Options.WatermarkOptions.Text;
                                }
                            }

                            // apply mask
                            string _mask = FileManager.Configuration.Options.BatchAutoMask;
                            if (string.IsNullOrEmpty(_mask))
                            {
                                _mask = "S$SE$E";
                            }

                            _text = _mask.Replace("$S", _season).Replace("$E", _episode).Trim();
                        }
                        else
                        {
                            InputBoxDialogResult _ibres = InputBox.Show(null, _text,
                                                                        "type text here",
                                                                        "Add custom text for " + System.IO.Path.GetFileName(_movie.FullName),
                                                                        false, false, null, false);
                            if (_ibres.SkipFolder)
                            {
                                return;
                            }
                            if (string.IsNullOrEmpty(_ibres.Keywords))
                            {
                                continue;
                            }
                            _text = _ibres.Keywords;
                        }

                        FileManager.Configuration.Options.WatermarkOptions.Text = string.IsNullOrEmpty(_text) ? FileManager.Configuration.Options.WatermarkOptions.Text : _text;

                        Helpers.CreateThumbnailImage(imageUrl, _destFile, FileManager.Configuration.Options.KeepAspectRatio);
                    }
                }, _promptUser ? DispatcherPriority.Send : DispatcherPriority.Background);
            }
            return((bool)_res);
        }