save additional info to recording nfo's

This commit is contained in:
Luke Pulverenti 2016-11-26 19:40:15 -05:00
parent d54c11fb74
commit 921ec9cd11
6 changed files with 221 additions and 41 deletions

View File

@ -170,7 +170,9 @@ namespace Emby.Server.Implementations.Data
createMediaStreamsTableCommand,
"create index if not exists idx_mediastreams1 on mediastreams(ItemId)"
"create index if not exists idx_mediastreams1 on mediastreams(ItemId)",
"pragma shrink_memory"
};
@ -3591,6 +3593,15 @@ namespace Emby.Server.Implementations.Data
}
}
if (!string.IsNullOrWhiteSpace(query.ExternalId))
{
whereClauses.Add("ExternalId=@ExternalId");
if (statement != null)
{
statement.TryBind("@ExternalId", query.ExternalId);
}
}
if (!string.IsNullOrWhiteSpace(query.Name))
{
whereClauses.Add("CleanName=@Name");

View File

@ -414,9 +414,9 @@ namespace Emby.Server.Implementations.HttpServer
httpRes.StatusCode = 200;
httpRes.AddHeader("Access-Control-Allow-Origin", "*");
httpRes.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
httpRes.AddHeader("Access-Control-Allow-Headers",
"Content-Type, Authorization, Range, X-MediaBrowser-Token, X-Emby-Authorization");
httpRes.ContentType = "text/html";
httpRes.AddHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Range, X-MediaBrowser-Token, X-Emby-Authorization");
httpRes.ContentType = "text/plain";
Write(httpRes, string.Empty);
return;
}

View File

@ -1601,6 +1601,14 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
{
try
{
var program = string.IsNullOrWhiteSpace(timer.ProgramId) ? null : _libraryManager.GetItemList(new InternalItemsQuery
{
IncludeItemTypes = new[] { typeof(LiveTvProgram).Name },
Limit = 1,
ExternalId = timer.ProgramId
}).FirstOrDefault();
if (timer.IsSports)
{
AddGenre(timer.Genres, "Sports");
@ -1615,14 +1623,37 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
AddGenre(timer.Genres, "News");
}
// dummy this up
if (program == null)
{
program = new LiveTvProgram
{
Name = timer.Name,
HomePageUrl = timer.HomePageUrl,
ShortOverview = timer.ShortOverview,
Overview = timer.Overview,
Genres = timer.Genres,
CommunityRating = timer.CommunityRating,
OfficialRating = timer.OfficialRating,
ProductionYear = timer.ProductionYear,
PremiereDate = timer.OriginalAirDate,
IndexNumber = timer.EpisodeNumber,
ParentIndexNumber = timer.SeasonNumber
};
}
if (timer.IsProgramSeries)
{
SaveSeriesNfo(timer, recordingPath, seriesPath);
SaveVideoNfo(timer, recordingPath, false);
SaveSeriesNfo(timer, seriesPath);
SaveVideoNfo(timer, recordingPath, program, false);
}
else if (!timer.IsMovie || timer.IsSports || timer.IsNews)
{
SaveVideoNfo(timer, recordingPath, true);
SaveVideoNfo(timer, recordingPath, program, true);
}
else
{
SaveVideoNfo(timer, recordingPath, program, false);
}
}
catch (Exception ex)
@ -1631,7 +1662,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
}
}
private void SaveSeriesNfo(TimerInfo timer, string recordingPath, string seriesPath)
private void SaveSeriesNfo(TimerInfo timer, string seriesPath)
{
var nfoPath = Path.Combine(seriesPath, "tvshow.nfo");
@ -1676,7 +1707,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
}
public const string DateAddedFormat = "yyyy-MM-dd HH:mm:ss";
private void SaveVideoNfo(TimerInfo timer, string recordingPath, bool lockData)
private void SaveVideoNfo(TimerInfo timer, string recordingPath, BaseItem item, bool lockData)
{
var nfoPath = Path.ChangeExtension(recordingPath, ".nfo");
@ -1694,6 +1725,8 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
CloseOutput = false
};
var options = _config.GetNfoConfiguration();
using (XmlWriter writer = XmlWriter.Create(stream, settings))
{
writer.WriteStartDocument(true);
@ -1707,45 +1740,64 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
writer.WriteElementString("title", timer.EpisodeTitle);
}
if (timer.OriginalAirDate.HasValue)
if (item.PremiereDate.HasValue)
{
var formatString = _config.GetNfoConfiguration().ReleaseDateFormat;
var formatString = options.ReleaseDateFormat;
writer.WriteElementString("aired", timer.OriginalAirDate.Value.ToLocalTime().ToString(formatString));
writer.WriteElementString("aired", item.PremiereDate.Value.ToLocalTime().ToString(formatString));
}
if (timer.EpisodeNumber.HasValue)
if (item.IndexNumber.HasValue)
{
writer.WriteElementString("episode", timer.EpisodeNumber.Value.ToString(CultureInfo.InvariantCulture));
writer.WriteElementString("episode", item.IndexNumber.Value.ToString(CultureInfo.InvariantCulture));
}
if (timer.SeasonNumber.HasValue)
if (item.ParentIndexNumber.HasValue)
{
writer.WriteElementString("season", timer.SeasonNumber.Value.ToString(CultureInfo.InvariantCulture));
writer.WriteElementString("season", item.ParentIndexNumber.Value.ToString(CultureInfo.InvariantCulture));
}
}
else
{
writer.WriteStartElement("movie");
if (!string.IsNullOrWhiteSpace(timer.Name))
if (!string.IsNullOrWhiteSpace(item.Name))
{
writer.WriteElementString("title", timer.Name);
writer.WriteElementString("title", item.Name);
}
if (!string.IsNullOrWhiteSpace(item.OriginalTitle))
{
writer.WriteElementString("originaltitle", item.OriginalTitle);
}
if (item.PremiereDate.HasValue)
{
var formatString = options.ReleaseDateFormat;
writer.WriteElementString("premiered", item.PremiereDate.Value.ToLocalTime().ToString(formatString));
writer.WriteElementString("releasedate", item.PremiereDate.Value.ToLocalTime().ToString(formatString));
}
}
writer.WriteElementString("dateadded", DateTime.UtcNow.ToLocalTime().ToString(DateAddedFormat));
if (timer.ProductionYear.HasValue)
if (item.ProductionYear.HasValue)
{
writer.WriteElementString("year", timer.ProductionYear.Value.ToString(CultureInfo.InvariantCulture));
}
if (!string.IsNullOrEmpty(timer.OfficialRating))
{
writer.WriteElementString("mpaa", timer.OfficialRating);
writer.WriteElementString("year", item.ProductionYear.Value.ToString(CultureInfo.InvariantCulture));
}
var overview = (timer.Overview ?? string.Empty)
if (!string.IsNullOrEmpty(item.OfficialRating))
{
writer.WriteElementString("mpaa", item.OfficialRating);
}
if (!string.IsNullOrEmpty(item.OfficialRatingDescription))
{
writer.WriteElementString("mpaadescription", item.OfficialRatingDescription);
}
var overview = (item.Overview ?? string.Empty)
.StripHtml()
.Replace(""", "'");
@ -1756,24 +1808,116 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
writer.WriteElementString("lockdata", true.ToString().ToLower());
}
if (timer.CommunityRating.HasValue)
if (item.CommunityRating.HasValue)
{
writer.WriteElementString("rating", timer.CommunityRating.Value.ToString(CultureInfo.InvariantCulture));
writer.WriteElementString("rating", item.CommunityRating.Value.ToString(CultureInfo.InvariantCulture));
}
foreach (var genre in timer.Genres)
foreach (var genre in item.Genres)
{
writer.WriteElementString("genre", genre);
}
if (!string.IsNullOrWhiteSpace(timer.ShortOverview))
if (!string.IsNullOrWhiteSpace(item.ShortOverview))
{
writer.WriteElementString("outline", timer.ShortOverview);
writer.WriteElementString("outline", item.ShortOverview);
}
if (!string.IsNullOrWhiteSpace(timer.HomePageUrl))
if (!string.IsNullOrWhiteSpace(item.HomePageUrl))
{
writer.WriteElementString("website", timer.HomePageUrl);
writer.WriteElementString("website", item.HomePageUrl);
}
var people = item.Id == Guid.Empty ? new List<PersonInfo>() : _libraryManager.GetPeople(item);
var directors = people
.Where(i => IsPersonType(i, PersonType.Director))
.Select(i => i.Name)
.ToList();
foreach (var person in directors)
{
writer.WriteElementString("director", person);
}
var writers = people
.Where(i => IsPersonType(i, PersonType.Writer))
.Select(i => i.Name)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
foreach (var person in writers)
{
writer.WriteElementString("writer", person);
}
foreach (var person in writers)
{
writer.WriteElementString("credits", person);
}
var rt = item.GetProviderId(MetadataProviders.RottenTomatoes);
if (!string.IsNullOrEmpty(rt))
{
writer.WriteElementString("rottentomatoesid", rt);
}
var tmdbCollection = item.GetProviderId(MetadataProviders.TmdbCollection);
if (!string.IsNullOrEmpty(tmdbCollection))
{
writer.WriteElementString("collectionnumber", tmdbCollection);
}
var imdb = item.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrEmpty(imdb))
{
if (item is Series)
{
writer.WriteElementString("imdb_id", imdb);
}
else
{
writer.WriteElementString("imdbid", imdb);
}
}
var tvdb = item.GetProviderId(MetadataProviders.Tvdb);
if (!string.IsNullOrEmpty(tvdb))
{
writer.WriteElementString("tvdbid", tvdb);
}
var tmdb = item.GetProviderId(MetadataProviders.Tmdb);
if (!string.IsNullOrEmpty(tmdb))
{
writer.WriteElementString("tmdbid", tmdb);
}
if (item.CriticRating.HasValue)
{
writer.WriteElementString("criticrating", item.CriticRating.Value.ToString(CultureInfo.InvariantCulture));
}
if (!string.IsNullOrEmpty(item.CriticRatingSummary))
{
writer.WriteElementString("criticratingsummary", item.CriticRatingSummary);
}
if (!string.IsNullOrWhiteSpace(item.Tagline))
{
writer.WriteElementString("tagline", item.Tagline);
}
foreach (var studio in item.Studios)
{
writer.WriteElementString("studio", studio);
}
if (item.VoteCount.HasValue)
{
writer.WriteElementString("votes", item.VoteCount.Value.ToString(CultureInfo.InvariantCulture));
}
writer.WriteEndElement();
@ -1782,6 +1926,11 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
}
}
private static bool IsPersonType(PersonInfo person, string type)
{
return string.Equals(person.Type, type, StringComparison.OrdinalIgnoreCase) || string.Equals(person.Role, type, StringComparison.OrdinalIgnoreCase);
}
private void AddGenre(List<string> genres, string genre)
{
if (!genres.Contains(genre, StringComparer.OrdinalIgnoreCase))

View File

@ -229,7 +229,6 @@ namespace Emby.Server.Implementations.Sync
commandText = "update SyncJobs set TargetId=?,Name=?,Profile=?,Quality=?,Bitrate=?,Status=?,Progress=?,UserId=?,ItemIds=?,Category=?,ParentId=?,UnwatchedOnly=?,ItemLimit=?,SyncNewContent=?,DateCreated=?,DateLastModified=?,ItemCount=? where Id=?";
}
paramList.Add(job.Id.ToGuidParamValue());
paramList.Add(job.TargetId);
paramList.Add(job.Name);
paramList.Add(job.Profile);
@ -249,6 +248,15 @@ namespace Emby.Server.Implementations.Sync
paramList.Add(job.DateLastModified.ToDateTimeParamValue());
paramList.Add(job.ItemCount);
if (insert)
{
paramList.Insert(0, job.Id.ToGuidParamValue());
}
else
{
paramList.Add(job.Id.ToGuidParamValue());
}
connection.RunInTransaction(conn =>
{
conn.Execute(commandText, paramList.ToArray());
@ -698,7 +706,6 @@ namespace Emby.Server.Implementations.Sync
}
var paramList = new List<object>();
paramList.Add(jobItem.Id.ToGuidParamValue());
paramList.Add(jobItem.ItemId);
paramList.Add(jobItem.ItemName);
paramList.Add(jobItem.MediaSourceId);
@ -716,6 +723,15 @@ namespace Emby.Server.Implementations.Sync
paramList.Add(jobItem.JobItemIndex);
paramList.Add(jobItem.ItemDateModifiedTicks);
if (insert)
{
paramList.Insert(0, jobItem.Id.ToGuidParamValue());
}
else
{
paramList.Add(jobItem.Id.ToGuidParamValue());
}
connection.RunInTransaction(conn =>
{
conn.Execute(commandText, paramList.ToArray());

View File

@ -680,14 +680,17 @@ namespace MediaBrowser.Api.Library
/// <param name="request">The request.</param>
public void Post(RefreshLibrary request)
{
try
Task.Run(() =>
{
_libraryManager.ValidateMediaLibrary(new Progress<double>(), CancellationToken.None);
}
catch (Exception ex)
{
Logger.ErrorException("Error refreshing library", ex);
}
try
{
_libraryManager.ValidateMediaLibrary(new Progress<double>(), CancellationToken.None);
}
catch (Exception ex)
{
Logger.ErrorException("Error refreshing library", ex);
}
});
}
/// <summary>

View File

@ -141,6 +141,7 @@ namespace MediaBrowser.Controller.Entities
public SeriesStatus[] SeriesStatuses { get; set; }
public string AlbumArtistStartsWithOrGreater { get; set; }
public string ExternalSeriesId { get; set; }
public string ExternalId { get; set; }
public string[] AlbumNames { get; set; }
public string[] ArtistNames { get; set; }