瀏覽代碼

Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser

Eric Reed 12 年之前
父節點
當前提交
c6de61d7bd

+ 82 - 9
MediaBrowser.Api/LibraryService.cs

@@ -11,6 +11,7 @@ using MediaBrowser.Model.Querying;
 using ServiceStack.ServiceHost;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Threading;
 using System.Threading.Tasks;
@@ -100,16 +101,24 @@ namespace MediaBrowser.Api
     [Api(Description = "Refreshes metadata for an item")]
     public class RefreshItem : IReturnVoid
     {
-        [ApiMember(Name = "Forced", Description = "Indicates if a normal or forced refresh should occur.", IsRequired = true, DataType = "bool", ParameterType = "query", Verb = "POST")]
+        [ApiMember(Name = "Forced", Description = "Indicates if a normal or forced refresh should occur.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")]
         public bool Forced { get; set; }
 
-        [ApiMember(Name = "Recursive", Description = "Indicates if the refresh should occur recursively.", IsRequired = true, DataType = "bool", ParameterType = "query", Verb = "POST")]
+        [ApiMember(Name = "Recursive", Description = "Indicates if the refresh should occur recursively.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")]
         public bool Recursive { get; set; }
         
         [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
         public string Id { get; set; }
     }
 
+    [Route("/Items/{Id}", "DELETE")]
+    [Api(Description = "Deletes an item from the library and file system")]
+    public class DeleteItem : IReturnVoid
+    {
+        [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
+        public string Id { get; set; }
+    }
+
     [Route("/Items/Counts", "GET")]
     [Api(Description = "Gets counts of various item types")]
     public class GetItemCounts : IReturn<ItemCounts>
@@ -223,9 +232,66 @@ namespace MediaBrowser.Api
         /// Posts the specified request.
         /// </summary>
         /// <param name="request">The request.</param>
-        public void Post(RefreshLibrary request)
+        public async void Post(RefreshLibrary request)
+        {
+            try
+            {
+                await _libraryManager.ValidateMediaLibrary(new Progress<double>(), CancellationToken.None).ConfigureAwait(false);
+            }
+            catch (Exception ex)
+            {
+                Logger.ErrorException("Error refreshing library", ex);
+            }
+        }
+
+        /// <summary>
+        /// Deletes the specified request.
+        /// </summary>
+        /// <param name="request">The request.</param>
+        public async void Delete(DeleteItem request)
         {
-            _libraryManager.ValidateMediaLibrary(new Progress<double>(), CancellationToken.None);
+            var item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager);
+
+            var parent = item.Parent;
+
+            if (item.LocationType == LocationType.FileSystem)
+            {
+                if (Directory.Exists(item.Path))
+                {
+                    Directory.Delete(item.Path, true);
+                }
+                else if (File.Exists(item.Path))
+                {
+                    File.Delete(item.Path);
+                }
+
+                if (parent != null)
+                {
+                    try
+                    {
+                        await parent.ValidateChildren(new Progress<double>(), CancellationToken.None).ConfigureAwait(false);
+                    }
+                    catch (Exception ex)
+                    {
+                        Logger.ErrorException("Error refreshing item", ex);
+                    }
+                }
+            }
+            else if (parent != null)
+            {
+                try
+                {
+                    await parent.RemoveChild(item, CancellationToken.None).ConfigureAwait(false);
+                }
+                catch (Exception ex)
+                {
+                    Logger.ErrorException("Error removing item", ex);
+                }
+            }
+            else
+            {
+                throw new InvalidOperationException("Don't know how to delete " + item.Name);
+            }
         }
 
         /// <summary>
@@ -322,19 +388,26 @@ namespace MediaBrowser.Api
         /// Posts the specified request.
         /// </summary>
         /// <param name="request">The request.</param>
-        public void Post(RefreshItem request)
+        public async void Post(RefreshItem request)
         {
             var item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager);
 
             var folder = item as Folder;
 
-            if (folder != null)
+            try
             {
-                folder.ValidateChildren(new Progress<double>(), CancellationToken.None, request.Recursive, request.Forced);
+                if (folder != null)
+                {
+                    await folder.ValidateChildren(new Progress<double>(), CancellationToken.None, request.Recursive, request.Forced).ConfigureAwait(false);
+                }
+                else
+                {
+                    await item.RefreshMetadata(CancellationToken.None, forceRefresh: request.Forced).ConfigureAwait(false);
+                }
             }
-            else
+            catch (Exception ex)
             {
-                item.RefreshMetadata(CancellationToken.None, forceRefresh: request.Forced);
+                Logger.ErrorException("Error refreshing library", ex);
             }
         }
 

+ 1 - 1
MediaBrowser.Api/Playback/BaseStreamingService.cs

@@ -211,7 +211,7 @@ namespace MediaBrowser.Api.Playback
         /// <returns>MediaStream.</returns>
         private MediaStream GetMediaStream(IEnumerable<MediaStream> allStream, int? desiredIndex, MediaStreamType type, bool returnFirstIfNoIndex = true)
         {
-            var streams = allStream.Where(s => s.Type == type).ToList();
+            var streams = allStream.Where(s => s.Type == type).OrderBy(i => i.Index).ToList();
 
             if (desiredIndex.HasValue)
             {

+ 65 - 63
MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs

@@ -161,91 +161,93 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
 
             options.CancellationToken.ThrowIfCancellationRequested();
 
-            var message = GetHttpRequestMessage(options);
-
-            //if (options.EnableResponseCache && cachedInfo != null)
-            //{
-            //    if (!string.IsNullOrEmpty(cachedInfo.Etag))
-            //    {
-            //        message.Headers.Add("If-None-Match", cachedInfo.Etag);
-            //    }
-            //    else if (cachedInfo.LastModified.HasValue)
-            //    {
-            //        message.Headers.IfModifiedSince = new DateTimeOffset(cachedInfo.LastModified.Value);
-            //    }
-            //}
-
-            if (options.ResourcePool != null)
+            using (var message = GetHttpRequestMessage(options))
             {
-                await options.ResourcePool.WaitAsync(options.CancellationToken).ConfigureAwait(false);
-            }
-
-            _logger.Info("HttpClientManager.Get url: {0}", options.Url);
-
-            try
-            {
-                options.CancellationToken.ThrowIfCancellationRequested();
-
-                var response = await GetHttpClient(GetHostFromUrl(options.Url), options.EnableHttpCompression).SendAsync(message, HttpCompletionOption.ResponseContentRead, options.CancellationToken).ConfigureAwait(false);
-
-                if (options.EnableResponseCache)
+                if (options.EnableResponseCache && cachedInfo != null)
                 {
-                    if (response.StatusCode != HttpStatusCode.NotModified)
+                    if (!string.IsNullOrEmpty(cachedInfo.Etag))
                     {
-                        EnsureSuccessStatusCode(response);
+                        message.Headers.Add("If-None-Match", cachedInfo.Etag);
+                    }
+                    else if (cachedInfo.LastModified.HasValue)
+                    {
+                        message.Headers.IfModifiedSince = new DateTimeOffset(cachedInfo.LastModified.Value);
                     }
+                }
 
+                if (options.ResourcePool != null)
+                {
+                    await options.ResourcePool.WaitAsync(options.CancellationToken).ConfigureAwait(false);
+                }
+
+                _logger.Info("HttpClientManager.Get url: {0}", options.Url);
+
+                try
+                {
                     options.CancellationToken.ThrowIfCancellationRequested();
 
-                    cachedInfo = UpdateInfoCache(cachedInfo, options.Url, cachedInfoPath, response);
+                    var response = await GetHttpClient(GetHostFromUrl(options.Url), options.EnableHttpCompression).SendAsync(message, HttpCompletionOption.ResponseContentRead, options.CancellationToken).ConfigureAwait(false);
 
-                    if (response.StatusCode == HttpStatusCode.NotModified)
+                    if (options.EnableResponseCache)
                     {
-                        _logger.Debug("Server indicates not modified for {0}. Returning cached result.", options.Url);
+                        if (response.StatusCode != HttpStatusCode.NotModified)
+                        {
+                            EnsureSuccessStatusCode(response);
+                        }
 
-                        return GetCachedResponse(cachedReponsePath);
-                    }
+                        options.CancellationToken.ThrowIfCancellationRequested();
+
+                        cachedInfo = UpdateInfoCache(cachedInfo, options.Url, cachedInfoPath, response);
+
+                        if (response.StatusCode == HttpStatusCode.NotModified)
+                        {
+                            _logger.Debug("Server indicates not modified for {0}. Returning cached result.", options.Url);
 
-                    if (!string.IsNullOrEmpty(cachedInfo.Etag) || cachedInfo.LastModified.HasValue ||
-                        (cachedInfo.Expires.HasValue && cachedInfo.Expires.Value > DateTime.UtcNow))
+                            return GetCachedResponse(cachedReponsePath);
+                        }
+
+                        if (!string.IsNullOrEmpty(cachedInfo.Etag) || cachedInfo.LastModified.HasValue ||
+                            (cachedInfo.Expires.HasValue && cachedInfo.Expires.Value > DateTime.UtcNow))
+                        {
+                            await UpdateResponseCache(response, cachedReponsePath).ConfigureAwait(false);
+
+                            return GetCachedResponse(cachedReponsePath);
+                        }
+                    }
+                    else
                     {
-                        await UpdateResponseCache(response, cachedReponsePath).ConfigureAwait(false);
+                        EnsureSuccessStatusCode(response);
 
-                        return GetCachedResponse(cachedReponsePath);
+                        options.CancellationToken.ThrowIfCancellationRequested();
                     }
+
+                    return await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
                 }
-                else
+                catch (OperationCanceledException ex)
                 {
-                    EnsureSuccessStatusCode(response);
-
-                    options.CancellationToken.ThrowIfCancellationRequested();
+                    throw GetCancellationException(options.Url, options.CancellationToken, ex);
                 }
+                catch (HttpRequestException ex)
+                {
+                    _logger.ErrorException("Error getting response from " + options.Url, ex);
 
-                return await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
-            }
-            catch (OperationCanceledException ex)
-            {
-                throw GetCancellationException(options.Url, options.CancellationToken, ex);
-            }
-            catch (HttpRequestException ex)
-            {
-                _logger.ErrorException("Error getting response from " + options.Url, ex);
-
-                throw new HttpException(ex.Message, ex);
-            }
-            catch (Exception ex)
-            {
-                _logger.ErrorException("Error getting response from " + options.Url, ex);
+                    throw new HttpException(ex.Message, ex);
+                }
+                catch (Exception ex)
+                {
+                    _logger.ErrorException("Error getting response from " + options.Url, ex);
 
-                throw;
-            }
-            finally
-            {
-                if (options.ResourcePool != null)
+                    throw;
+                }
+                finally
                 {
-                    options.ResourcePool.Release();
+                    if (options.ResourcePool != null)
+                    {
+                        options.ResourcePool.Release();
+                    }
                 }
             }
+
         }
 
         /// <summary>

+ 29 - 5
MediaBrowser.Controller/Providers/MediaInfo/AudioImageProvider.cs

@@ -56,6 +56,30 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
             ImageCache = new FileSystemRepository(Kernel.Instance.FFMpegManager.AudioImagesDataPath);
         }
 
+        /// <summary>
+        /// Gets a value indicating whether [refresh on version change].
+        /// </summary>
+        /// <value><c>true</c> if [refresh on version change]; otherwise, <c>false</c>.</value>
+        protected override bool RefreshOnVersionChange
+        {
+            get
+            {
+                return true;
+            }
+        }
+
+        /// <summary>
+        /// Gets the provider version.
+        /// </summary>
+        /// <value>The provider version.</value>
+        protected override string ProviderVersion
+        {
+            get
+            {
+                return "1";
+            }
+        }
+
         /// <summary>
         /// Supportses the specified item.
         /// </summary>
@@ -150,17 +174,17 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
                     {
                         semaphore.Release();
                     }
-
-                    // Image is already in the cache
-                    item.PrimaryImagePath = path;
-
-                    await _libraryManager.UpdateItem(item, cancellationToken).ConfigureAwait(false);
                 }
                 else
                 {
                     semaphore.Release();
                 }
             }
+
+            // Image is already in the cache
+            item.PrimaryImagePath = path;
+
+            await _libraryManager.UpdateItem(item, cancellationToken).ConfigureAwait(false);
         }
 
         /// <summary>

+ 0 - 13
MediaBrowser.Server.Implementations/Providers/ProviderManager.cs

@@ -423,19 +423,6 @@ namespace MediaBrowser.Server.Implementations.Providers
                 dataToSave.Position = 0;
             }
 
-            if (!(dataToSave is MemoryStream || dataToSave is FileStream))
-            {
-                var ms = new MemoryStream();
-
-                using (dataToSave)
-                {
-                    await dataToSave.CopyToAsync(ms).ConfigureAwait(false);
-                }
-
-                ms.Position = 0;
-                dataToSave = ms;
-            }
-
             try
             {
                 using (dataToSave)

+ 5 - 0
MediaBrowser.Server.Implementations/Session/SessionManager.cs

@@ -220,6 +220,11 @@ namespace MediaBrowser.Server.Implementations.Session
             data.PlayCount++;
             data.LastPlayedDate = DateTime.UtcNow;
 
+            if (!(item is Video))
+            {
+                data.Played = true;
+            }
+
             await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
             
             // Nothing to save here