allow custom language per item

pull/702/head
Luke Pulverenti 11 years ago
parent 0a3b16dfbe
commit 28b0ff1e75

@ -311,10 +311,12 @@ namespace MediaBrowser.Api
SetProductionLocations(item, request);
var hasLanguage = item as IHasLanguage;
if (hasLanguage != null)
var hasLang = item as IHasPreferredMetadataLanguage;
if (hasLang != null)
{
hasLanguage.Language = request.Language;
hasLang.PreferredMetadataCountryCode = request.PreferredMetadataCountryCode;
hasLang.PreferredMetadataLanguage = request.PreferredMetadataLanguage;
}
var hasAspectRatio = item as IHasAspectRatio;

@ -4,5 +4,11 @@ namespace MediaBrowser.Controller.Entities
public class AdultVideo : Video, IHasPreferredMetadataLanguage
{
public string PreferredMetadataLanguage { get; set; }
/// <summary>
/// Gets or sets the preferred metadata country code.
/// </summary>
/// <value>The preferred metadata country code.</value>
public string PreferredMetadataCountryCode { get; set; }
}
}

@ -9,19 +9,13 @@ namespace MediaBrowser.Controller.Entities.Audio
/// <summary>
/// Class Audio
/// </summary>
public class Audio : BaseItem, IHasMediaStreams, IHasAlbumArtist, IHasArtist, IHasMusicGenres, IHasLanguage
public class Audio : BaseItem, IHasMediaStreams, IHasAlbumArtist, IHasArtist, IHasMusicGenres
{
public Audio()
{
Artists = new List<string>();
}
/// <summary>
/// Gets or sets the language.
/// </summary>
/// <value>The language.</value>
public string Language { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance has embedded image.
/// </summary>

@ -960,7 +960,7 @@ namespace MediaBrowser.Controller.Entities
/// Gets the preferred metadata language.
/// </summary>
/// <returns>System.String.</returns>
public virtual string GetPreferredMetadataLanguage()
public string GetPreferredMetadataLanguage()
{
string lang = null;
@ -971,6 +971,13 @@ namespace MediaBrowser.Controller.Entities
lang = hasLang.PreferredMetadataLanguage;
}
if (string.IsNullOrEmpty(lang))
{
lang = Parents.OfType<IHasPreferredMetadataLanguage>()
.Select(i => i.PreferredMetadataLanguage)
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
}
if (string.IsNullOrEmpty(lang))
{
lang = ConfigurationManager.Configuration.PreferredMetadataLanguage;
@ -979,6 +986,36 @@ namespace MediaBrowser.Controller.Entities
return lang;
}
/// <summary>
/// Gets the preferred metadata language.
/// </summary>
/// <returns>System.String.</returns>
public string GetPreferredMetadataCountryCode()
{
string lang = null;
var hasLang = this as IHasPreferredMetadataLanguage;
if (hasLang != null)
{
lang = hasLang.PreferredMetadataCountryCode;
}
if (string.IsNullOrEmpty(lang))
{
lang = Parents.OfType<IHasPreferredMetadataLanguage>()
.Select(i => i.PreferredMetadataCountryCode)
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
}
if (string.IsNullOrEmpty(lang))
{
lang = ConfigurationManager.Configuration.MetadataCountryCode;
}
return lang;
}
/// <summary>
/// Determines if a given user has access to this item
/// </summary>

@ -23,6 +23,12 @@ namespace MediaBrowser.Controller.Entities
public string PreferredMetadataLanguage { get; set; }
/// <summary>
/// Gets or sets the preferred metadata country code.
/// </summary>
/// <value>The preferred metadata country code.</value>
public string PreferredMetadataCountryCode { get; set; }
/// <summary>
///
/// </summary>

@ -5,7 +5,7 @@ using System.Collections.Generic;
namespace MediaBrowser.Controller.Entities
{
public class Game : BaseItem, IHasSoundtracks, IHasTrailers, IHasThemeMedia, IHasTags, IHasLanguage, IHasScreenshots, IHasPreferredMetadataLanguage
public class Game : BaseItem, IHasSoundtracks, IHasTrailers, IHasThemeMedia, IHasTags, IHasScreenshots, IHasPreferredMetadataLanguage
{
public List<Guid> SoundtrackIds { get; set; }
@ -14,6 +14,12 @@ namespace MediaBrowser.Controller.Entities
public string PreferredMetadataLanguage { get; set; }
/// <summary>
/// Gets or sets the preferred metadata country code.
/// </summary>
/// <value>The preferred metadata country code.</value>
public string PreferredMetadataCountryCode { get; set; }
public Game()
{
MultiPartGameFiles = new List<string>();
@ -26,12 +32,6 @@ namespace MediaBrowser.Controller.Entities
ScreenshotImagePaths = new List<string>();
}
/// <summary>
/// Gets or sets the language.
/// </summary>
/// <value>The language.</value>
public string Language { get; set; }
public List<Guid> LocalTrailerIds { get; set; }
/// <summary>

@ -1,15 +0,0 @@

namespace MediaBrowser.Controller.Entities
{
/// <summary>
/// Interface IHasLanguage
/// </summary>
public interface IHasLanguage
{
/// <summary>
/// Gets or sets the language.
/// </summary>
/// <value>The language.</value>
string Language { get; set; }
}
}

@ -11,5 +11,11 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
/// <value>The preferred metadata language.</value>
string PreferredMetadataLanguage { get; set; }
/// <summary>
/// Gets or sets the preferred metadata country code.
/// </summary>
/// <value>The preferred metadata country code.</value>
string PreferredMetadataCountryCode { get; set; }
}
}

@ -33,6 +33,12 @@ namespace MediaBrowser.Controller.Entities.Movies
public string PreferredMetadataLanguage { get; set; }
/// <summary>
/// Gets or sets the preferred metadata country code.
/// </summary>
/// <value>The preferred metadata country code.</value>
public string PreferredMetadataCountryCode { get; set; }
protected override bool GetBlockUnratedValue(UserConfiguration config)
{
return config.BlockUnratedMovies;

@ -21,6 +21,12 @@ namespace MediaBrowser.Controller.Entities.Movies
public List<Guid> ThemeSongIds { get; set; }
public List<Guid> ThemeVideoIds { get; set; }
/// <summary>
/// Gets or sets the preferred metadata country code.
/// </summary>
/// <value>The preferred metadata country code.</value>
public string PreferredMetadataCountryCode { get; set; }
public string PreferredMetadataLanguage { get; set; }
public Movie()

@ -21,6 +21,12 @@ namespace MediaBrowser.Controller.Entities.TV
public int SeasonCount { get; set; }
/// <summary>
/// Gets or sets the preferred metadata country code.
/// </summary>
/// <value>The preferred metadata country code.</value>
public string PreferredMetadataCountryCode { get; set; }
public Series()
{
AirDays = new List<DayOfWeek>();

@ -14,6 +14,12 @@ namespace MediaBrowser.Controller.Entities
public List<Guid> SoundtrackIds { get; set; }
public string PreferredMetadataLanguage { get; set; }
/// <summary>
/// Gets or sets the preferred metadata country code.
/// </summary>
/// <value>The preferred metadata country code.</value>
public string PreferredMetadataCountryCode { get; set; }
public Trailer()
{

@ -86,7 +86,6 @@
<Compile Include="Entities\IHasBudget.cs" />
<Compile Include="Entities\IHasCriticRating.cs" />
<Compile Include="Entities\IHasImages.cs" />
<Compile Include="Entities\IHasLanguage.cs" />
<Compile Include="Entities\IHasMediaStreams.cs" />
<Compile Include="Entities\IHasPreferredMetadataLanguage.cs" />
<Compile Include="Entities\IHasProductionLocations.cs" />

@ -269,10 +269,10 @@ namespace MediaBrowser.Controller.Providers
{
var val = reader.ReadElementContentAsString();
var hasLanguage = item as IHasLanguage;
var hasLanguage = item as IHasPreferredMetadataLanguage;
if (hasLanguage != null)
{
hasLanguage.Language = val;
hasLanguage.PreferredMetadataLanguage = val;
}
break;

@ -36,6 +36,9 @@ namespace MediaBrowser.Model.Dto
public int? AbsoluteEpisodeNumber { get; set; }
public bool? DisplaySpecialsWithSeasons { get; set; }
public string PreferredMetadataLanguage { get; set; }
public string PreferredMetadataCountryCode { get; set; }
/// <summary>
/// Gets or sets the DVD season number.
/// </summary>
@ -209,12 +212,6 @@ namespace MediaBrowser.Model.Dto
/// <value>The provider ids.</value>
public Dictionary<string, string> ProviderIds { get; set; }
/// <summary>
/// Gets or sets the language.
/// </summary>
/// <value>The language.</value>
public string Language { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance is HD.
/// </summary>

@ -151,8 +151,6 @@ namespace MediaBrowser.Providers.MediaInfo
// Disc number
audio.ParentIndexNumber = GetDictionaryDiscValue(tags, "disc");
audio.Language = GetDictionaryValue(tags, "language");
audio.ProductionYear = GetDictionaryNumericValue(tags, "date");
// Several different forms of retaildate

@ -499,6 +499,7 @@ namespace MediaBrowser.Providers.Movies
// Id could be ImdbId or TmdbId
var language = item.GetPreferredMetadataLanguage();
var country = item.GetPreferredMetadataCountryCode();
var dataFilePath = GetDataFilePath(item);
@ -514,9 +515,7 @@ namespace MediaBrowser.Providers.Movies
tmdbId = mainResult.id.ToString(_usCulture);
var movieDataPath = GetMovieDataPath(ConfigurationManager.ApplicationPaths, isBoxSet, tmdbId);
dataFilePath = Path.Combine(movieDataPath, "all.json");
dataFilePath = GetDataFilePath(isBoxSet, tmdbId, language);
var directory = Path.GetDirectoryName(dataFilePath);
@ -527,7 +526,7 @@ namespace MediaBrowser.Providers.Movies
if (isForcedRefresh || ConfigurationManager.Configuration.EnableTmdbUpdates || !HasAltMeta(item))
{
dataFilePath = GetDataFilePath(isBoxSet, tmdbId);
dataFilePath = GetDataFilePath(isBoxSet, tmdbId, language);
if (!string.IsNullOrEmpty(dataFilePath))
{
@ -543,19 +542,18 @@ namespace MediaBrowser.Providers.Movies
/// </summary>
/// <param name="id">The id.</param>
/// <param name="isBoxSet">if set to <c>true</c> [is box set].</param>
/// <param name="dataPath">The data path.</param>
/// <param name="preferredMetadataLanguage">The preferred metadata language.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
internal async Task DownloadMovieInfo(string id, bool isBoxSet, string dataPath, string preferredMetadataLanguage, CancellationToken cancellationToken)
internal async Task DownloadMovieInfo(string id, bool isBoxSet, string preferredMetadataLanguage, CancellationToken cancellationToken)
{
var mainResult = await FetchMainResult(id, isBoxSet, preferredMetadataLanguage, cancellationToken).ConfigureAwait(false);
if (mainResult == null) return;
var dataFilePath = Path.Combine(dataPath, "all.json");
var dataFilePath = GetDataFilePath(isBoxSet, id, preferredMetadataLanguage);
Directory.CreateDirectory(dataPath);
Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath));
JsonSerializer.SerializeToFile(mainResult, dataFilePath);
}
@ -574,14 +572,17 @@ namespace MediaBrowser.Providers.Movies
return null;
}
return GetDataFilePath(item is BoxSet, id);
return GetDataFilePath(item is BoxSet, id, item.GetPreferredMetadataLanguage());
}
internal string GetDataFilePath(bool isBoxset, string tmdbId)
internal string GetDataFilePath(bool isBoxset, string tmdbId, string preferredLanguage)
{
var path = GetMovieDataPath(ConfigurationManager.ApplicationPaths, isBoxset, tmdbId);
return Path.Combine(path, "all.json");
var filename = string.Format("all-{0}.json",
preferredLanguage ?? string.Empty);
return Path.Combine(path, filename);
}
/// <summary>
@ -730,16 +731,18 @@ namespace MediaBrowser.Providers.Movies
movie.VoteCount = movieData.vote_count;
}
var preferredCountryCode = movie.GetPreferredMetadataCountryCode();
//release date and certification are retrieved based on configured country and we fall back on US if not there and to minimun release date if still no match
if (movieData.releases != null && movieData.releases.countries != null)
{
var ourRelease = movieData.releases.countries.FirstOrDefault(c => c.iso_3166_1.Equals(ConfigurationManager.Configuration.MetadataCountryCode, StringComparison.OrdinalIgnoreCase)) ?? new Country();
var ourRelease = movieData.releases.countries.FirstOrDefault(c => c.iso_3166_1.Equals(preferredCountryCode, StringComparison.OrdinalIgnoreCase)) ?? new Country();
var usRelease = movieData.releases.countries.FirstOrDefault(c => c.iso_3166_1.Equals("US", StringComparison.OrdinalIgnoreCase)) ?? new Country();
var minimunRelease = movieData.releases.countries.OrderBy(c => c.release_date).FirstOrDefault() ?? new Country();
if (!movie.LockedFields.Contains(MetadataFields.OfficialRating))
{
var ratingPrefix = ConfigurationManager.Configuration.MetadataCountryCode.Equals("us", StringComparison.OrdinalIgnoreCase) ? "" : ConfigurationManager.Configuration.MetadataCountryCode + "-";
var ratingPrefix = string.Equals(preferredCountryCode, "us", StringComparison.OrdinalIgnoreCase) ? "" : preferredCountryCode + "-";
movie.OfficialRating = !string.IsNullOrEmpty(ourRelease.certification)
? ratingPrefix + ourRelease.certification
: !string.IsNullOrEmpty(usRelease.certification)

@ -219,7 +219,7 @@ namespace MediaBrowser.Providers.Movies
{
try
{
await UpdateMovie(id, isBoxSet, moviesDataPath, language, cancellationToken).ConfigureAwait(false);
await UpdateMovie(id, isBoxSet, language, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
@ -241,19 +241,14 @@ namespace MediaBrowser.Providers.Movies
/// </summary>
/// <param name="id">The id.</param>
/// <param name="isBoxSet">if set to <c>true</c> [is box set].</param>
/// <param name="dataPath">The data path.</param>
/// <param name="preferredMetadataLanguage">The preferred metadata language.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
private Task UpdateMovie(string id, bool isBoxSet, string dataPath, string preferredMetadataLanguage, CancellationToken cancellationToken)
private Task UpdateMovie(string id, bool isBoxSet, string preferredMetadataLanguage, CancellationToken cancellationToken)
{
_logger.Info("Updating movie from tmdb " + id + ", language " + preferredMetadataLanguage);
var itemDataPath = Path.Combine(dataPath, id);
Directory.CreateDirectory(dataPath);
return MovieDbProvider.Current.DownloadMovieInfo(id, isBoxSet, itemDataPath, preferredMetadataLanguage, cancellationToken);
return MovieDbProvider.Current.DownloadMovieInfo(id, isBoxSet, preferredMetadataLanguage, cancellationToken);
}
class Result

@ -326,12 +326,12 @@ namespace MediaBrowser.Providers.Savers
}
}
var hasLanguage = item as IHasLanguage;
var hasLanguage = item as IHasPreferredMetadataLanguage;
if (hasLanguage != null)
{
if (!string.IsNullOrEmpty(hasLanguage.Language))
if (!string.IsNullOrEmpty(hasLanguage.PreferredMetadataLanguage))
{
builder.Append("<Language>" + SecurityElement.Escape(hasLanguage.Language) + "</Language>");
builder.Append("<Language>" + SecurityElement.Escape(hasLanguage.PreferredMetadataLanguage) + "</Language>");
}
}

@ -739,10 +739,12 @@ namespace MediaBrowser.Server.Implementations.Dto
dto.MediaType = item.MediaType;
dto.LocationType = item.LocationType;
var hasLanguage = item as IHasLanguage;
if (hasLanguage != null)
var hasLang = item as IHasPreferredMetadataLanguage;
if (hasLang != null)
{
dto.Language = hasLanguage.Language;
dto.PreferredMetadataCountryCode = hasLang.PreferredMetadataCountryCode;
dto.PreferredMetadataLanguage = hasLang.PreferredMetadataLanguage;
}
var hasCriticRating = item as IHasCriticRating;

@ -62,7 +62,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
if (program != null)
{
dto.ProgramInfo = GetProgramInfoDto(program);
dto.ProgramInfo = GetProgramInfoDto(program, channel.ChannelInfo.Name);
dto.ProgramInfo.TimerId = dto.Id;
dto.ProgramInfo.SeriesTimerId = dto.SeriesTimerId;
@ -260,7 +260,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return dto;
}
public ProgramInfoDto GetProgramInfoDto(LiveTvProgram item, User user = null)
public ProgramInfoDto GetProgramInfoDto(LiveTvProgram item, string channelName, User user = null)
{
var program = item.ProgramInfo;
@ -283,7 +283,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
AspectRatio = program.AspectRatio,
IsRepeat = program.IsRepeat,
EpisodeTitle = program.EpisodeTitle,
ChannelName = program.ChannelName,
ChannelName = channelName,
IsMovie = program.IsMovie,
IsSeries = program.IsSeries,
IsSports = program.IsSports,

@ -123,11 +123,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv
public LiveTvChannel GetInternalChannel(string id)
{
var guid = new Guid(id);
return GetInternalChannel(new Guid(id));
}
private LiveTvChannel GetInternalChannel(Guid id)
{
LiveTvChannel channel = null;
_channels.TryGetValue(guid, out channel);
_channels.TryGetValue(id, out channel);
return channel;
}
@ -272,11 +275,24 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return item;
}
private LiveTvChannel GetChannel(LiveTvProgram program)
{
var programChannelId = program.ProgramInfo.ChannelId;
var internalProgramChannelId = _tvDtoService.GetInternalChannelId(program.ServiceName, programChannelId);
return GetInternalChannel(internalProgramChannelId);
}
public async Task<ProgramInfoDto> GetProgram(string id, CancellationToken cancellationToken, User user = null)
{
var program = GetInternalProgram(id);
var dto = _tvDtoService.GetProgramInfoDto(program, user);
var channel = GetChannel(program);
var channelName = channel == null ? null : channel.ChannelInfo.Name;
var dto = _tvDtoService.GetProgramInfoDto(program, channelName, user);
await AddRecordingInfo(new[] { dto }, cancellationToken).ConfigureAwait(false);
@ -311,7 +327,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv
var returnArray = programs
.OrderBy(i => i.ProgramInfo.StartDate)
.Select(i => _tvDtoService.GetProgramInfoDto(i, user))
.Select(i =>
{
var channel = GetChannel(i);
var channelName = channel == null ? null : channel.ChannelInfo.Name;
return _tvDtoService.GetProgramInfoDto(i, channelName, user);
})
.ToArray();
await AddRecordingInfo(returnArray, cancellationToken).ConfigureAwait(false);
@ -447,7 +470,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
var returnArray = entities
.Select(i =>
{
var channel = string.IsNullOrEmpty(i.RecordingInfo.ChannelId) ? null : GetInternalChannel(_tvDtoService.GetInternalChannelId(service.Name, i.RecordingInfo.ChannelId).ToString("N"));
var channel = string.IsNullOrEmpty(i.RecordingInfo.ChannelId) ? null : GetInternalChannel(_tvDtoService.GetInternalChannelId(service.Name, i.RecordingInfo.ChannelId));
return _tvDtoService.GetRecordingInfoDto(i, channel, service, user);
})
.OrderByDescending(i => i.StartDate)
@ -504,7 +527,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
.Select(i =>
{
var program = string.IsNullOrEmpty(i.ProgramId) ? null : GetInternalProgram(_tvDtoService.GetInternalProgramId(service.Name, i.ProgramId).ToString("N"));
var channel = string.IsNullOrEmpty(i.ChannelId) ? null : GetInternalChannel(_tvDtoService.GetInternalChannelId(service.Name, i.ChannelId).ToString("N"));
var channel = string.IsNullOrEmpty(i.ChannelId) ? null : GetInternalChannel(_tvDtoService.GetInternalChannelId(service.Name, i.ChannelId));
return _tvDtoService.GetTimerInfoDto(i, service, program, channel);
})
@ -603,7 +626,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
if (!string.IsNullOrEmpty(i.ChannelId))
{
var internalChannelId = _tvDtoService.GetInternalChannelId(service.Name, i.ChannelId);
var channel = GetInternalChannel(internalChannelId.ToString("N"));
var channel = GetInternalChannel(internalChannelId);
channelName = channel == null ? null : channel.ChannelInfo.Name;
}

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common.Internal</id>
<version>3.0.290</version>
<version>3.0.292</version>
<title>MediaBrowser.Common.Internal</title>
<authors>Luke</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.290" />
<dependency id="MediaBrowser.Common" version="3.0.292" />
<dependency id="NLog" version="2.1.0" />
<dependency id="SimpleInjector" version="2.4.0" />
<dependency id="sharpcompress" version="0.10.2" />

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common</id>
<version>3.0.290</version>
<version>3.0.292</version>
<title>MediaBrowser.Common</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MediaBrowser.Server.Core</id>
<version>3.0.290</version>
<version>3.0.292</version>
<title>Media Browser.Server.Core</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains core components required to build plugins for Media Browser Server.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.290" />
<dependency id="MediaBrowser.Common" version="3.0.292" />
</dependencies>
</metadata>
<files>

Loading…
Cancel
Save