浏览代码

update direct stream url for improved caching

Luke Pulverenti 9 年之前
父节点
当前提交
6164049919

+ 1 - 3
MediaBrowser.Api/Images/ImageService.cs

@@ -573,11 +573,9 @@ namespace MediaBrowser.Api.Images
 
 
             var outputFormats = GetOutputFormats(request, imageInfo, cropwhitespace, supportedImageEnhancers);
             var outputFormats = GetOutputFormats(request, imageInfo, cropwhitespace, supportedImageEnhancers);
 
 
-            var cacheGuid = new Guid(_imageProcessor.GetImageCacheTag(item, imageInfo, supportedImageEnhancers));
-
             TimeSpan? cacheDuration = null;
             TimeSpan? cacheDuration = null;
 
 
-            if (!string.IsNullOrEmpty(request.Tag) && cacheGuid == new Guid(request.Tag))
+            if (!string.IsNullOrEmpty(request.Tag))
             {
             {
                 cacheDuration = TimeSpan.FromDays(365);
                 cacheDuration = TimeSpan.FromDays(365);
             }
             }

+ 4 - 0
MediaBrowser.Api/Playback/BaseStreamingService.cs

@@ -1589,6 +1589,10 @@ namespace MediaBrowser.Api.Playback
                         videoRequest.EnableSubtitlesInManifest = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
                         videoRequest.EnableSubtitlesInManifest = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
                     }
                     }
                 }
                 }
+                else if (i == 29)
+                {
+                    request.Tag = val;
+                }
             }
             }
         }
         }
 
 

+ 9 - 1
MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs

@@ -154,12 +154,20 @@ namespace MediaBrowser.Api.Playback.Progressive
 
 
                 using (state)
                 using (state)
                 {
                 {
+                    TimeSpan? cacheDuration = null;
+
+                    if (!string.IsNullOrEmpty(request.Tag))
+                    {
+                        cacheDuration = TimeSpan.FromDays(365);
+                    }
+
                     return await ResultFactory.GetStaticFileResult(Request, new StaticFileResultOptions
                     return await ResultFactory.GetStaticFileResult(Request, new StaticFileResultOptions
                     {
                     {
                         ResponseHeaders = responseHeaders,
                         ResponseHeaders = responseHeaders,
                         ContentType = contentType,
                         ContentType = contentType,
                         IsHeadRequest = isHeadRequest,
                         IsHeadRequest = isHeadRequest,
-                        Path = state.MediaPath
+                        Path = state.MediaPath,
+                        CacheDuration = cacheDuration
 
 
                     }).ConfigureAwait(false);
                     }).ConfigureAwait(false);
                 }
                 }

+ 1 - 0
MediaBrowser.Api/Playback/StreamRequest.cs

@@ -74,6 +74,7 @@ namespace MediaBrowser.Api.Playback
         public string Params { get; set; }
         public string Params { get; set; }
         public string PlaySessionId { get; set; }
         public string PlaySessionId { get; set; }
         public string LiveStreamId { get; set; }
         public string LiveStreamId { get; set; }
+        public string Tag { get; set; }
     }
     }
 
 
     public class VideoStreamRequest : StreamRequest
     public class VideoStreamRequest : StreamRequest

+ 7 - 0
MediaBrowser.Controller/Entities/Audio/Audio.cs

@@ -5,9 +5,11 @@ using MediaBrowser.Model.Entities;
 using MediaBrowser.Model.MediaInfo;
 using MediaBrowser.Model.MediaInfo;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
+using System.Globalization;
 using System.Linq;
 using System.Linq;
 using System.Runtime.Serialization;
 using System.Runtime.Serialization;
 using System.Threading;
 using System.Threading;
+using MediaBrowser.Common.Extensions;
 using MediaBrowser.Controller.Channels;
 using MediaBrowser.Controller.Channels;
 
 
 namespace MediaBrowser.Controller.Entities.Audio
 namespace MediaBrowser.Controller.Entities.Audio
@@ -266,6 +268,11 @@ namespace MediaBrowser.Controller.Entities.Audio
                 Size = i.Size
                 Size = i.Size
             };
             };
 
 
+            if (info.Protocol == MediaProtocol.File)
+            {
+                info.ETag = i.DateModified.Ticks.ToString(CultureInfo.InvariantCulture).GetMD5().ToString("N");
+            }
+
             if (string.IsNullOrEmpty(info.Container))
             if (string.IsNullOrEmpty(info.Container))
             {
             {
                 if (!string.IsNullOrWhiteSpace(i.Path) && locationType != LocationType.Remote && locationType != LocationType.Virtual)
                 if (!string.IsNullOrWhiteSpace(i.Path) && locationType != LocationType.Remote && locationType != LocationType.Virtual)

+ 6 - 0
MediaBrowser.Controller/Entities/Video.cs

@@ -12,6 +12,7 @@ using System.Runtime.Serialization;
 using System.Threading;
 using System.Threading;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using CommonIO;
 using CommonIO;
+using MediaBrowser.Common.Extensions;
 using MediaBrowser.Controller.Channels;
 using MediaBrowser.Controller.Channels;
 
 
 namespace MediaBrowser.Controller.Entities
 namespace MediaBrowser.Controller.Entities
@@ -611,6 +612,11 @@ namespace MediaBrowser.Controller.Entities
                 SupportsDirectStream = i.VideoType == VideoType.VideoFile
                 SupportsDirectStream = i.VideoType == VideoType.VideoFile
             };
             };
 
 
+            if (info.Protocol == MediaProtocol.File)
+            {
+                info.ETag = i.DateModified.Ticks.ToString(CultureInfo.InvariantCulture).GetMD5().ToString("N");
+            }
+
             if (i.IsShortcut)
             if (i.IsShortcut)
             {
             {
                 info.Path = i.ShortcutPath;
                 info.Path = i.ShortcutPath;

+ 2 - 0
MediaBrowser.Model/Dlna/StreamInfo.cs

@@ -252,6 +252,8 @@ namespace MediaBrowser.Model.Dlna
             list.Add(new NameValuePair("TranscodingMaxAudioChannels", item.TranscodingMaxAudioChannels.HasValue ? StringHelper.ToStringCultureInvariant(item.TranscodingMaxAudioChannels.Value) : string.Empty));
             list.Add(new NameValuePair("TranscodingMaxAudioChannels", item.TranscodingMaxAudioChannels.HasValue ? StringHelper.ToStringCultureInvariant(item.TranscodingMaxAudioChannels.Value) : string.Empty));
             list.Add(new NameValuePair("EnableSubtitlesInManifest", item.EnableSubtitlesInManifest.ToString().ToLower()));
             list.Add(new NameValuePair("EnableSubtitlesInManifest", item.EnableSubtitlesInManifest.ToString().ToLower()));
 
 
+            list.Add(new NameValuePair("Tag", item.MediaSource.ETag ?? string.Empty));
+
             return list;
             return list;
         }
         }
 
 

+ 1 - 0
MediaBrowser.Model/Dto/MediaSourceInfo.cs

@@ -20,6 +20,7 @@ namespace MediaBrowser.Model.Dto
 
 
         public string Name { get; set; }
         public string Name { get; set; }
 
 
+        public string ETag { get; set; }
         public long? RunTimeTicks { get; set; }
         public long? RunTimeTicks { get; set; }
         public bool ReadAtNativeFramerate { get; set; }
         public bool ReadAtNativeFramerate { get; set; }
         public bool SupportsTranscoding { get; set; }
         public bool SupportsTranscoding { get; set; }