diff --git a/.gitignore b/.gitignore
index 673f15dfe..1598a7ac3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -210,7 +210,6 @@ $RECYCLE.BIN/
# Packages
*.egg
*.egg-info
-dist/
build/
eggs/
parts/
diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs
index 68087309b..54c28d390 100644
--- a/MediaBrowser.Api/ApiEntryPoint.cs
+++ b/MediaBrowser.Api/ApiEntryPoint.cs
@@ -340,7 +340,7 @@ namespace MediaBrowser.Api
// We can really reduce the timeout for apps that are using the newer api
if (!string.IsNullOrWhiteSpace(job.PlaySessionId))
{
- timerDuration = 120000;
+ timerDuration = 300000;
}
}
diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs
index 564cfa93a..7a14ace77 100644
--- a/MediaBrowser.Api/BaseApiService.cs
+++ b/MediaBrowser.Api/BaseApiService.cs
@@ -344,9 +344,7 @@ namespace MediaBrowser.Api
return name;
}
- return libraryManager.GetAllPeople()
- .Select(i => i.Name)
- .DistinctNames()
+ return libraryManager.GetPeopleNames(new InternalPeopleQuery())
.FirstOrDefault(i =>
{
i = _dashReplaceChars.Aggregate(i, (current, c) => current.Replace(c, SlugChar));
diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj
index 3beb33b04..249d10a12 100644
--- a/MediaBrowser.Api/MediaBrowser.Api.csproj
+++ b/MediaBrowser.Api/MediaBrowser.Api.csproj
@@ -109,6 +109,7 @@
+
diff --git a/MediaBrowser.Api/Movies/MoviesService.cs b/MediaBrowser.Api/Movies/MoviesService.cs
index 17eb448bc..97e9aa9c8 100644
--- a/MediaBrowser.Api/Movies/MoviesService.cs
+++ b/MediaBrowser.Api/Movies/MoviesService.cs
@@ -165,7 +165,7 @@ namespace MediaBrowser.Api.Movies
return ToOptimizedResult(result);
}
- private async Task GetSimilarItemsResult(BaseGetSimilarItemsFromItem request, Func includeInSearch, Func getSimilarityScore)
+ private async Task GetSimilarItemsResult(BaseGetSimilarItemsFromItem request, Func includeInSearch, Func, List, BaseItem, int> getSimilarityScore)
{
var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;
@@ -358,12 +358,15 @@ namespace MediaBrowser.Api.Movies
private IEnumerable GetWithActor(User user, List allMovies, IEnumerable names, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
{
- var userId = user.Id;
-
foreach (var name in names)
{
+ var itemsWithActor = _libraryManager.GetItemIds(new InternalItemsQuery
+ {
+ Person = name
+ });
+
var items = allMovies
- .Where(i => _libraryManager.GetPeople(i).Any(p => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase)))
+ .Where(i => itemsWithActor.Contains(i.Id))
.Take(itemLimit)
.ToList();
@@ -382,8 +385,6 @@ namespace MediaBrowser.Api.Movies
private IEnumerable GetSimilarTo(User user, List allMovies, IEnumerable baselineItems, int itemLimit, DtoOptions dtoOptions, RecommendationType type)
{
- var userId = user.Id;
-
foreach (var item in baselineItems)
{
var similar = SimilarItemsHelper
@@ -406,18 +407,37 @@ namespace MediaBrowser.Api.Movies
private IEnumerable GetActors(IEnumerable items)
{
- // Get the two leading actors for all movies
- return items
- .SelectMany(i => _libraryManager.GetPeople(i).Where(p => !string.Equals(PersonType.Director, p.Type, StringComparison.OrdinalIgnoreCase)).Take(2))
+ var people = _libraryManager.GetPeople(new InternalPeopleQuery
+ {
+ ExcludePersonTypes = new List
+ {
+ PersonType.Director
+ },
+ MaxListOrder = 3
+ });
+
+ var itemIds = items.Select(i => i.Id).ToList();
+
+ return people
+ .Where(i => itemIds.Contains(i.ItemId))
.Select(i => i.Name)
.DistinctNames();
}
private IEnumerable GetDirectors(IEnumerable items)
{
- return items
- .Select(i => _libraryManager.GetPeople(i).FirstOrDefault(p => string.Equals(PersonType.Director, p.Type, StringComparison.OrdinalIgnoreCase)))
- .Where(i => i != null)
+ var people = _libraryManager.GetPeople(new InternalPeopleQuery
+ {
+ PersonTypes = new List
+ {
+ PersonType.Director
+ }
+ });
+
+ var itemIds = items.Select(i => i.Id).ToList();
+
+ return people
+ .Where(i => itemIds.Contains(i.ItemId))
.Select(i => i.Name)
.DistinctNames();
}
diff --git a/MediaBrowser.Api/Music/AlbumsService.cs b/MediaBrowser.Api/Music/AlbumsService.cs
index 3dc459bd2..ea87c3ad3 100644
--- a/MediaBrowser.Api/Music/AlbumsService.cs
+++ b/MediaBrowser.Api/Music/AlbumsService.cs
@@ -6,6 +6,7 @@ using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence;
using ServiceStack;
using System;
+using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Api.Music
@@ -68,12 +69,13 @@ namespace MediaBrowser.Api.Music
/// Gets the album similarity score.
///
/// The item1.
+ /// The item1 people.
+ /// All people.
/// The item2.
- /// The library manager.
/// System.Int32.
- private int GetAlbumSimilarityScore(BaseItem item1, BaseItem item2, ILibraryManager libraryManager)
+ private int GetAlbumSimilarityScore(BaseItem item1, List item1People, List allPeople, BaseItem item2)
{
- var points = SimilarItemsHelper.GetSimiliarityScore(item1, item2, libraryManager);
+ var points = SimilarItemsHelper.GetSimiliarityScore(item1, item1People, allPeople, item2);
var album1 = (MusicAlbum)item1;
var album2 = (MusicAlbum)item2;
diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs
index 41d785a34..dc5858e86 100644
--- a/MediaBrowser.Api/Playback/BaseStreamingService.cs
+++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs
@@ -632,7 +632,7 @@ namespace MediaBrowser.Api.Playback
{
var maxHeightParam = request.MaxHeight.Value.ToString(UsCulture);
- filters.Add(string.Format("scale=trunc(oh*a*2)/2:min(ih\\,{0})", maxHeightParam));
+ filters.Add(string.Format("scale=trunc(oh*a/2)*2:min(ih\\,{0})", maxHeightParam));
}
if (string.Equals(outputVideoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase))
diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs
index ab57e561f..0a432a580 100644
--- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs
+++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs
@@ -313,16 +313,17 @@ namespace MediaBrowser.Api.Playback.Hls
{
var segmentPath = GetSegmentPath(state, playlist, i);
- double length;
- if (SegmentLengths.TryGetValue(Path.GetFileName(segmentPath), out length))
- {
- Logger.Debug("Found segment length of {0} for index {1}", length, i);
- startSeconds += length;
- }
- else
- {
- startSeconds += state.SegmentLength;
- }
+ //double length;
+ //if (SegmentLengths.TryGetValue(Path.GetFileName(segmentPath), out length))
+ //{
+ // Logger.Debug("Found segment length of {0} for index {1}", length, i);
+ // startSeconds += length;
+ //}
+ //else
+ //{
+ // startSeconds += state.SegmentLength;
+ //}
+ startSeconds += state.SegmentLength;
}
var position = TimeSpan.FromSeconds(startSeconds).Ticks;
@@ -441,7 +442,7 @@ namespace MediaBrowser.Api.Playback.Hls
CancellationToken cancellationToken)
{
// If all transcoding has completed, just return immediately
- if (transcodingJob != null && transcodingJob.HasExited)
+ if (transcodingJob != null && transcodingJob.HasExited && File.Exists(segmentPath))
{
return GetSegmentResult(segmentPath, segmentIndex, segmentLength, transcodingJob);
}
@@ -463,7 +464,11 @@ namespace MediaBrowser.Api.Playback.Hls
// If it appears in the playlist, it's done
if (text.IndexOf(segmentFilename, StringComparison.OrdinalIgnoreCase) != -1)
{
- return GetSegmentResult(segmentPath, segmentIndex, segmentLength, transcodingJob);
+ if (File.Exists(segmentPath))
+ {
+ return GetSegmentResult(segmentPath, segmentIndex, segmentLength, transcodingJob);
+ }
+ break;
}
}
}
@@ -564,11 +569,11 @@ namespace MediaBrowser.Api.Playback.Hls
builder.AppendLine("#EXTM3U");
+ var isLiveStream = (state.RunTimeTicks ?? 0) == 0;
+
var queryStringIndex = Request.RawUrl.IndexOf('?');
var queryString = queryStringIndex == -1 ? string.Empty : Request.RawUrl.Substring(queryStringIndex);
- var isLiveStream = (state.RunTimeTicks ?? 0) == 0;
-
// Main stream
var playlistUrl = isLiveStream ? "live.m3u8" : "main.m3u8";
playlistUrl += queryString;
@@ -798,7 +803,7 @@ namespace MediaBrowser.Api.Playback.Hls
var audioTranscodeParams = new List();
audioTranscodeParams.Add("-acodec " + codec);
-
+
if (state.OutputAudioBitrate.HasValue)
{
audioTranscodeParams.Add("-ab " + state.OutputAudioBitrate.Value.ToString(UsCulture));
diff --git a/MediaBrowser.Api/SimilarItemsHelper.cs b/MediaBrowser.Api/SimilarItemsHelper.cs
index 1e9b365db..d114446ee 100644
--- a/MediaBrowser.Api/SimilarItemsHelper.cs
+++ b/MediaBrowser.Api/SimilarItemsHelper.cs
@@ -68,7 +68,7 @@ namespace MediaBrowser.Api
/// The include in search.
/// The get similarity score.
/// ItemsResult.
- internal static ItemsResult GetSimilarItemsResult(DtoOptions dtoOptions, IUserManager userManager, IItemRepository itemRepository, ILibraryManager libraryManager, IUserDataManager userDataRepository, IDtoService dtoService, ILogger logger, BaseGetSimilarItemsFromItem request, Func includeInSearch, Func getSimilarityScore)
+ internal static ItemsResult GetSimilarItemsResult(DtoOptions dtoOptions, IUserManager userManager, IItemRepository itemRepository, ILibraryManager libraryManager, IUserDataManager userDataRepository, IDtoService dtoService, ILogger logger, BaseGetSimilarItemsFromItem request, Func includeInSearch, Func, List, BaseItem, int> getSimilarityScore)
{
var user = !string.IsNullOrWhiteSpace(request.UserId) ? userManager.GetUserById(request.UserId) : null;
@@ -110,12 +110,17 @@ namespace MediaBrowser.Api
/// The input items.
/// The get similarity score.
/// IEnumerable{BaseItem}.
- internal static IEnumerable GetSimilaritems(BaseItem item, ILibraryManager libraryManager, IEnumerable inputItems, Func getSimilarityScore)
+ internal static IEnumerable GetSimilaritems(BaseItem item, ILibraryManager libraryManager, IEnumerable inputItems, Func, List, BaseItem, int> getSimilarityScore)
{
var itemId = item.Id;
inputItems = inputItems.Where(i => i.Id != itemId);
+ var itemPeople = libraryManager.GetPeople(item);
+ var allPeople = libraryManager.GetPeople(new InternalPeopleQuery
+ {
+ AppearsInItemId = item.Id
+ });
- return inputItems.Select(i => new Tuple(i, getSimilarityScore(item, i, libraryManager)))
+ return inputItems.Select(i => new Tuple(i, getSimilarityScore(item, itemPeople, allPeople, i)))
.Where(i => i.Item2 > 2)
.OrderByDescending(i => i.Item2)
.Select(i => i.Item1);
@@ -147,9 +152,11 @@ namespace MediaBrowser.Api
/// Gets the similiarity score.
///
/// The item1.
+ /// The item1 people.
+ /// All people.
/// The item2.
/// System.Int32.
- internal static int GetSimiliarityScore(BaseItem item1, BaseItem item2, ILibraryManager libraryManager)
+ internal static int GetSimiliarityScore(BaseItem item1, List item1People, List allPeople, BaseItem item2)
{
var points = 0;
@@ -170,11 +177,13 @@ namespace MediaBrowser.Api
// Find common studios
points += item1.Studios.Where(i => item2.Studios.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 3);
- var item2PeopleNames = libraryManager.GetPeople(item2).Select(i => i.Name)
+ var item2PeopleNames = allPeople.Where(i => i.ItemId == item2.Id)
+ .Select(i => i.Name)
+ .Where(i => !string.IsNullOrWhiteSpace(i))
.DistinctNames()
.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
- points += libraryManager.GetPeople(item1).Where(i => item2PeopleNames.ContainsKey(i.Name)).Sum(i =>
+ points += item1People.Where(i => item2PeopleNames.ContainsKey(i.Name)).Sum(i =>
{
if (string.Equals(i.Type, PersonType.Director, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase))
{
diff --git a/MediaBrowser.Api/Social/SharingService.cs b/MediaBrowser.Api/Social/SharingService.cs
new file mode 100644
index 000000000..608008455
--- /dev/null
+++ b/MediaBrowser.Api/Social/SharingService.cs
@@ -0,0 +1,164 @@
+using MediaBrowser.Common.Extensions;
+using MediaBrowser.Controller.Dlna;
+using MediaBrowser.Controller.Dto;
+using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.Net;
+using MediaBrowser.Controller.Social;
+using MediaBrowser.Model.Entities;
+using MediaBrowser.Model.Social;
+using ServiceStack;
+using System;
+using System.IO;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.Social
+{
+ [Route("/Social/Shares/{Id}", "GET", Summary = "Gets a share")]
+ [Authenticated]
+ public class GetSocialShareInfo : IReturn
+ {
+ [ApiMember(Name = "Id", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
+ public string Id { get; set; }
+ }
+
+ [Route("/Social/Shares/Public/{Id}", "GET", Summary = "Gets a share")]
+ public class GetPublicSocialShareInfo : IReturn
+ {
+ [ApiMember(Name = "Id", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
+ public string Id { get; set; }
+ }
+
+ [Route("/Social/Shares/Public/{Id}/Image", "GET", Summary = "Gets a share")]
+ public class GetShareImage
+ {
+ [ApiMember(Name = "Id", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
+ public string Id { get; set; }
+ }
+
+ [Route("/Social/Shares", "POST", Summary = "Creates a share")]
+ [Authenticated]
+ public class CreateShare : IReturn
+ {
+ [ApiMember(Name = "ItemId", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
+ public string ItemId { get; set; }
+
+ [ApiMember(Name = "UserId", Description = "The user id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
+ public string UserId { get; set; }
+ }
+
+ [Route("/Social/Shares/{Id}", "DELETE", Summary = "Deletes a share")]
+ [Authenticated]
+ public class DeleteShare : IReturnVoid
+ {
+ [ApiMember(Name = "Id", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
+ public string Id { get; set; }
+ }
+
+ [Route("/Social/Shares/Public/{Id}/Item", "GET", Summary = "Gets a share")]
+ public class GetSharedLibraryItem
+ {
+ [ApiMember(Name = "Id", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
+ public string Id { get; set; }
+ }
+
+ public class SharingService : BaseApiService
+ {
+ private readonly ISharingManager _sharingManager;
+ private readonly ILibraryManager _libraryManager;
+ private readonly IDlnaManager _dlnaManager;
+ private readonly IDtoService _dtoService;
+
+ public SharingService(ISharingManager sharingManager, IDlnaManager dlnaManager, ILibraryManager libraryManager, IDtoService dtoService)
+ {
+ _sharingManager = sharingManager;
+ _dlnaManager = dlnaManager;
+ _libraryManager = libraryManager;
+ _dtoService = dtoService;
+ }
+
+ public object Get(GetSocialShareInfo request)
+ {
+ var info = _sharingManager.GetShareInfo(request.Id);
+
+ return ToOptimizedResult(info);
+ }
+
+ public object Get(GetSharedLibraryItem request)
+ {
+ var info = _sharingManager.GetShareInfo(request.Id);
+
+ if (info.ExpirationDate <= DateTime.UtcNow)
+ {
+ throw new ResourceNotFoundException();
+ }
+
+ var item = _libraryManager.GetItemById(info.ItemId);
+
+ var dto = _dtoService.GetBaseItemDto(item, new DtoOptions());
+
+ return ToOptimizedResult(dto);
+ }
+
+ public object Get(GetPublicSocialShareInfo request)
+ {
+ var info = _sharingManager.GetShareInfo(request.Id);
+
+ if (info.ExpirationDate <= DateTime.UtcNow)
+ {
+ throw new ResourceNotFoundException();
+ }
+
+ return ToOptimizedResult(info);
+ }
+
+ public async Task