1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00

New: Add TVDB URL in Kodi metadata

This commit is contained in:
Zippy79 2021-08-02 05:29:25 +09:00 committed by GitHub
parent 4bf3ab1511
commit 155dbd4dd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 95 additions and 76 deletions

View File

@ -15,6 +15,7 @@ import ProviderFieldFormGroup from 'Components/Form/ProviderFieldFormGroup';
function EditMetadataModalContent(props) {
const {
advancedSettings,
isSaving,
saveError,
item,
@ -56,6 +57,7 @@ function EditMetadataModalContent(props) {
return (
<ProviderFieldFormGroup
key={field.name}
advancedSettings={advancedSettings}
provider="metadata"
{...field}
isDisabled={!enable.value}
@ -88,6 +90,7 @@ function EditMetadataModalContent(props) {
}
EditMetadataModalContent.propTypes = {
advancedSettings: PropTypes.bool.isRequired,
isSaving: PropTypes.bool.isRequired,
saveError: PropTypes.object,
item: PropTypes.object.isRequired,

View File

@ -9,9 +9,10 @@ import EditMetadataModalContent from './EditMetadataModalContent';
function createMapStateToProps() {
return createSelector(
(state) => state.settings.advancedSettings,
(state, { id }) => id,
(state) => state.settings.metadata,
(id, metadata) => {
(advancedSettings, id, metadata) => {
const {
isSaving,
saveError,
@ -22,6 +23,7 @@ function createMapStateToProps() {
const settings = selectSettings(_.find(items, { id }), pendingChanges, saveError);
return {
advancedSettings,
id,
isSaving,
saveError,

View File

@ -137,87 +137,97 @@ public override MetadataFile FindMetadataFile(Series series, string path)
public override MetadataFileResult SeriesMetadata(Series series)
{
if (!Settings.SeriesMetadata)
var xmlResult = string.Empty;
if (Settings.SeriesMetadata)
{
return null;
}
_logger.Debug("Generating Series Metadata for: {0}", series.Title);
var sb = new StringBuilder();
var xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.Indent = false;
_logger.Debug("Generating tvshow.nfo for: {0}", series.Title);
var sb = new StringBuilder();
var xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.Indent = false;
using (var xw = XmlWriter.Create(sb, xws))
{
var tvShow = new XElement("tvshow");
tvShow.Add(new XElement("title", series.Title));
if (series.Ratings != null && series.Ratings.Votes > 0)
using (var xw = XmlWriter.Create(sb, xws))
{
tvShow.Add(new XElement("rating", series.Ratings.Value));
}
var tvShow = new XElement("tvshow");
tvShow.Add(new XElement("plot", series.Overview));
tvShow.Add(new XElement("mpaa", series.Certification));
tvShow.Add(new XElement("id", series.TvdbId));
tvShow.Add(new XElement("title", series.Title));
var uniqueId = new XElement("uniqueid", series.TvdbId);
uniqueId.SetAttributeValue("type", "tvdb");
uniqueId.SetAttributeValue("default", true);
tvShow.Add(uniqueId);
if (series.ImdbId.IsNotNullOrWhiteSpace())
{
var imdbId = new XElement("uniqueid", series.ImdbId);
imdbId.SetAttributeValue("type", "imdb");
tvShow.Add(imdbId);
}
foreach (var genre in series.Genres)
{
tvShow.Add(new XElement("genre", genre));
}
if (series.Tags.Any())
{
var tags = _tagService.GetTags(series.Tags);
foreach (var tag in tags)
if (series.Ratings != null && series.Ratings.Votes > 0)
{
tvShow.Add(new XElement("tag", tag.Label));
}
}
if (series.FirstAired.HasValue)
{
tvShow.Add(new XElement("premiered", series.FirstAired.Value.ToString("yyyy-MM-dd")));
}
tvShow.Add(new XElement("studio", series.Network));
foreach (var actor in series.Actors)
{
var xmlActor = new XElement("actor",
new XElement("name", actor.Name),
new XElement("role", actor.Character));
if (actor.Images.Any())
{
xmlActor.Add(new XElement("thumb", actor.Images.First().Url));
tvShow.Add(new XElement("rating", series.Ratings.Value));
}
tvShow.Add(xmlActor);
tvShow.Add(new XElement("plot", series.Overview));
tvShow.Add(new XElement("mpaa", series.Certification));
tvShow.Add(new XElement("id", series.TvdbId));
var uniqueId = new XElement("uniqueid", series.TvdbId);
uniqueId.SetAttributeValue("type", "tvdb");
uniqueId.SetAttributeValue("default", true);
tvShow.Add(uniqueId);
if (series.ImdbId.IsNotNullOrWhiteSpace())
{
var imdbId = new XElement("uniqueid", series.ImdbId);
imdbId.SetAttributeValue("type", "imdb");
tvShow.Add(imdbId);
}
foreach (var genre in series.Genres)
{
tvShow.Add(new XElement("genre", genre));
}
if (series.Tags.Any())
{
var tags = _tagService.GetTags(series.Tags);
foreach (var tag in tags)
{
tvShow.Add(new XElement("tag", tag.Label));
}
}
if (series.FirstAired.HasValue)
{
tvShow.Add(new XElement("premiered", series.FirstAired.Value.ToString("yyyy-MM-dd")));
}
tvShow.Add(new XElement("studio", series.Network));
foreach (var actor in series.Actors)
{
var xmlActor = new XElement("actor",
new XElement("name", actor.Name),
new XElement("role", actor.Character));
if (actor.Images.Any())
{
xmlActor.Add(new XElement("thumb", actor.Images.First().Url));
}
tvShow.Add(xmlActor);
}
var doc = new XDocument(tvShow);
doc.Save(xw);
xmlResult += doc.ToString();
}
}
if (Settings.SeriesMetadataUrl)
{
if (Settings.SeriesMetadata)
{
xmlResult += Environment.NewLine;
}
var doc = new XDocument(tvShow);
doc.Save(xw);
_logger.Debug("Saving tvshow.nfo for {0}", series.Title);
return new MetadataFileResult("tvshow.nfo", doc.ToString());
xmlResult += "https://www.thetvdb.com/?tab=series&id=" + series.TvdbId;
}
return xmlResult == string.Empty ? null : new MetadataFileResult("tvshow.nfo", xmlResult);
}
public override MetadataFileResult EpisodeMetadata(Series series, EpisodeFile episodeFile)

View File

@ -19,25 +19,29 @@ public class XbmcMetadataSettings : IProviderConfig
public XbmcMetadataSettings()
{
SeriesMetadata = true;
SeriesMetadataUrl = false;
EpisodeMetadata = true;
SeriesImages = true;
SeasonImages = true;
EpisodeImages = true;
}
[FieldDefinition(0, Label = "Series Metadata", Type = FieldType.Checkbox, Section = MetadataSectionType.Metadata, HelpText = "tvshow.nfo")]
[FieldDefinition(0, Label = "Series Metadata", Type = FieldType.Checkbox, Section = MetadataSectionType.Metadata, HelpText = "tvshow.nfo with full series metadata")]
public bool SeriesMetadata { get; set; }
[FieldDefinition(1, Label = "Episode Metadata", Type = FieldType.Checkbox, Section = MetadataSectionType.Metadata, HelpText = "<filename>.nfo")]
[FieldDefinition(1, Label = "Series Metadata URL", Type = FieldType.Checkbox, Section = MetadataSectionType.Metadata, HelpText = "tvshow.nfo with TheTVDB show URL (can be combined with 'Series Metadata')", Advanced = true)]
public bool SeriesMetadataUrl { get; set; }
[FieldDefinition(2, Label = "Episode Metadata", Type = FieldType.Checkbox, Section = MetadataSectionType.Metadata, HelpText = "<filename>.nfo")]
public bool EpisodeMetadata { get; set; }
[FieldDefinition(2, Label = "Series Images", Type = FieldType.Checkbox, Section = MetadataSectionType.Image, HelpText = "fanart.jpg, poster.jpg, banner.jpg")]
[FieldDefinition(3, Label = "Series Images", Type = FieldType.Checkbox, Section = MetadataSectionType.Image, HelpText = "fanart.jpg, poster.jpg, banner.jpg")]
public bool SeriesImages { get; set; }
[FieldDefinition(3, Label = "Season Images", Type = FieldType.Checkbox, Section = MetadataSectionType.Image, HelpText = "season##-poster.jpg, season##-banner.jpg, season-specials-poster.jpg, season-specials-banner.jpg")]
[FieldDefinition(4, Label = "Season Images", Type = FieldType.Checkbox, Section = MetadataSectionType.Image, HelpText = "season##-poster.jpg, season##-banner.jpg, season-specials-poster.jpg, season-specials-banner.jpg")]
public bool SeasonImages { get; set; }
[FieldDefinition(4, Label = "Episode Images", Type = FieldType.Checkbox, Section = MetadataSectionType.Image, HelpText = "<filename>-thumb.jpg")]
[FieldDefinition(5, Label = "Episode Images", Type = FieldType.Checkbox, Section = MetadataSectionType.Image, HelpText = "<filename>-thumb.jpg")]
public bool EpisodeImages { get; set; }
public bool IsValid => true;