2013-03-06 22:34:00 -07:00
|
|
|
|
using MediaBrowser.Controller.Localization;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Globalization;
|
|
|
|
|
using MoreLinq;
|
|
|
|
|
using ServiceStack.ServiceHost;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetCultures
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Localization/Cultures", "GET")]
|
2013-04-10 08:32:09 -07:00
|
|
|
|
[Api(Description = "Gets known cultures")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public class GetCultures : IReturn<List<CultureDto>>
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetCountries
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Localization/Countries", "GET")]
|
2013-04-10 08:32:09 -07:00
|
|
|
|
[Api(Description = "Gets known countries")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public class GetCountries : IReturn<List<CountryInfo>>
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class ParentalRatings
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Localization/ParentalRatings", "GET")]
|
2013-04-10 08:32:09 -07:00
|
|
|
|
[Api(Description = "Gets known parental ratings")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public class GetParentalRatings : IReturn<List<ParentalRating>>
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class CulturesService
|
|
|
|
|
/// </summary>
|
2013-03-15 22:52:33 -07:00
|
|
|
|
public class LocalizationService : BaseApiService
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetParentalRatings request)
|
|
|
|
|
{
|
|
|
|
|
var ratings =
|
|
|
|
|
Ratings.RatingsDict.Select(k => new ParentalRating { Name = k.Key, Value = k.Value });
|
|
|
|
|
|
|
|
|
|
var result = ratings.OrderBy(p => p.Value).Where(p => p.Value > 0).ToList();
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetCountries request)
|
|
|
|
|
{
|
|
|
|
|
var result = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
|
|
|
|
|
|
|
|
|
|
.Select(c => new RegionInfo(c.LCID))
|
|
|
|
|
.OrderBy(c => c.DisplayName)
|
|
|
|
|
|
|
|
|
|
// Try to eliminate dupes
|
|
|
|
|
.DistinctBy(c => c.TwoLetterISORegionName)
|
|
|
|
|
|
|
|
|
|
.Select(c => new CountryInfo
|
|
|
|
|
{
|
|
|
|
|
Name = c.Name,
|
|
|
|
|
DisplayName = c.DisplayName,
|
|
|
|
|
TwoLetterISORegionName = c.TwoLetterISORegionName,
|
|
|
|
|
ThreeLetterISORegionName = c.ThreeLetterISORegionName
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetCultures request)
|
|
|
|
|
{
|
|
|
|
|
var result = CultureInfo.GetCultures(CultureTypes.AllCultures)
|
|
|
|
|
.OrderBy(c => c.DisplayName)
|
|
|
|
|
|
|
|
|
|
// Try to eliminate dupes
|
|
|
|
|
.DistinctBy(c => c.TwoLetterISOLanguageName + c.ThreeLetterISOLanguageName)
|
|
|
|
|
|
|
|
|
|
.Select(c => new CultureDto
|
|
|
|
|
{
|
|
|
|
|
Name = c.Name,
|
|
|
|
|
DisplayName = c.DisplayName,
|
|
|
|
|
ThreeLetterISOLanguageName = c.ThreeLetterISOLanguageName,
|
|
|
|
|
TwoLetterISOLanguageName = c.TwoLetterISOLanguageName
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|