示例#1
0
        private void AddPreferredWords(Dictionary <string, Func <TokenMatch, string> > tokenHandlers, Series series, EpisodeFile episodeFile, List <string> preferredWords = null)
        {
            if (preferredWords == null)
            {
                preferredWords = _preferredWordService.GetMatchingPreferredWords(series, episodeFile.GetSceneOrFileName());
            }

            tokenHandlers["{Preferred Words}"] = m => string.Join(" ", preferredWords);
        }
        private void AddPreferredWords(Dictionary <string, Func <TokenMatch, string> > tokenHandlers, Series series, EpisodeFile episodeFile, PreferredWordMatchResults preferredWords = null)
        {
            if (preferredWords == null)
            {
                preferredWords = _preferredWordService.GetMatchingPreferredWords(series, episodeFile.GetSceneOrFileName());
            }

            tokenHandlers["{Preferred Words}"] = m => {
                var profileName = "";

                if (m.CustomFormat != null)
                {
                    profileName = m.CustomFormat.Trim();
                }

                if (profileName.IsNullOrWhiteSpace())
                {
                    return(string.Join(" ", preferredWords.All));
                }

                if (preferredWords.ByReleaseProfile.TryGetValue(profileName, out var profilePreferredWords))
                {
                    return(string.Join(" ", profilePreferredWords));
                }

                return(string.Empty);
            };
        }
示例#3
0
        public override MetadataFileResult EpisodeMetadata(Series series, EpisodeFile episodeFile)
        {
            if (!Settings.EpisodeMetadata)
            {
                return(null);
            }

            _logger.Debug("Generating Episode Metadata for: {0}", Path.Combine(series.Path, episodeFile.RelativePath));

            var watched = GetExistingWatchedStatus(series, episodeFile.RelativePath);

            var xmlResult = string.Empty;

            foreach (var episode in episodeFile.Episodes.Value)
            {
                var sb  = new StringBuilder();
                var xws = new XmlWriterSettings();
                xws.OmitXmlDeclaration = true;
                xws.Indent             = false;

                using (var xw = XmlWriter.Create(sb, xws))
                {
                    var doc   = new XDocument();
                    var image = episode.Images.SingleOrDefault(i => i.CoverType == MediaCoverTypes.Screenshot);

                    var details = new XElement("episodedetails");
                    details.Add(new XElement("title", episode.Title));
                    details.Add(new XElement("season", episode.SeasonNumber));
                    details.Add(new XElement("episode", episode.EpisodeNumber));
                    details.Add(new XElement("aired", episode.AirDate));
                    details.Add(new XElement("plot", episode.Overview));

                    if (episode.SeasonNumber == 0 && episode.AiredAfterSeasonNumber.HasValue)
                    {
                        details.Add(new XElement("displayafterseason", episode.AiredAfterSeasonNumber));
                    }
                    else if (episode.SeasonNumber == 0 && episode.AiredBeforeSeasonNumber.HasValue)
                    {
                        details.Add(new XElement("displayseason", episode.AiredBeforeSeasonNumber));
                        details.Add(new XElement("displayepisode", episode.AiredBeforeEpisodeNumber ?? -1));
                    }

                    var uniqueId = new XElement("uniqueid", episode.Id);
                    uniqueId.SetAttributeValue("type", "sonarr");
                    uniqueId.SetAttributeValue("default", true);
                    details.Add(uniqueId);

                    if (image == null)
                    {
                        details.Add(new XElement("thumb"));
                    }

                    else
                    {
                        details.Add(new XElement("thumb", image.Url));
                    }

                    details.Add(new XElement("watched", watched));

                    if (episode.Ratings != null && episode.Ratings.Votes > 0)
                    {
                        details.Add(new XElement("rating", episode.Ratings.Value));
                    }

                    if (episodeFile.MediaInfo != null)
                    {
                        var sceneName = episodeFile.GetSceneOrFileName();

                        var fileInfo      = new XElement("fileinfo");
                        var streamDetails = new XElement("streamdetails");

                        var video = new XElement("video");
                        video.Add(new XElement("aspect", (float)episodeFile.MediaInfo.Width / (float)episodeFile.MediaInfo.Height));
                        video.Add(new XElement("bitrate", episodeFile.MediaInfo.VideoBitrate));
                        video.Add(new XElement("codec", MediaInfoFormatter.FormatVideoCodec(episodeFile.MediaInfo, sceneName)));
                        video.Add(new XElement("framerate", episodeFile.MediaInfo.VideoFps));
                        video.Add(new XElement("height", episodeFile.MediaInfo.Height));
                        video.Add(new XElement("scantype", episodeFile.MediaInfo.ScanType));
                        video.Add(new XElement("width", episodeFile.MediaInfo.Width));

                        if (episodeFile.MediaInfo.RunTime != null)
                        {
                            video.Add(new XElement("duration", episodeFile.MediaInfo.RunTime.TotalMinutes));
                            video.Add(new XElement("durationinseconds", episodeFile.MediaInfo.RunTime.TotalSeconds));
                        }

                        streamDetails.Add(video);

                        var audio = new XElement("audio");
                        audio.Add(new XElement("bitrate", episodeFile.MediaInfo.AudioBitrate));
                        audio.Add(new XElement("channels", episodeFile.MediaInfo.AudioChannels));
                        audio.Add(new XElement("codec", MediaInfoFormatter.FormatAudioCodec(episodeFile.MediaInfo, sceneName)));
                        audio.Add(new XElement("language", episodeFile.MediaInfo.AudioLanguages));
                        streamDetails.Add(audio);

                        if (episodeFile.MediaInfo.Subtitles.IsNotNullOrWhiteSpace())
                        {
                            var subtitle = new XElement("subtitle");
                            subtitle.Add(new XElement("language", episodeFile.MediaInfo.Subtitles));
                            streamDetails.Add(subtitle);
                        }

                        fileInfo.Add(streamDetails);
                        details.Add(fileInfo);
                    }

                    //Todo: get guest stars, writer and director
                    //details.Add(new XElement("credits", tvdbEpisode.Writer.FirstOrDefault()));
                    //details.Add(new XElement("director", tvdbEpisode.Directors.FirstOrDefault()));

                    doc.Add(details);
                    doc.Save(xw);

                    xmlResult += doc.ToString();
                    xmlResult += Environment.NewLine;
                }
            }

            return(new MetadataFileResult(GetEpisodeMetadataFilename(episodeFile.RelativePath), xmlResult.Trim(Environment.NewLine.ToCharArray())));
        }