aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-06-02 22:01:30 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-06-02 22:01:30 -0400
commitc91ea99016ce9594a9918259ed1f5e0b7bc0ce6c (patch)
tree1775d2b1a11e6f9151e5e095bb6470c01ee14917 /MediaBrowser.Controller
parent858c37b8607ff0698a94b9e7bfff6190d3bca56d (diff)
more work on channel downloading
Diffstat (limited to 'MediaBrowser.Controller')
-rw-r--r--MediaBrowser.Controller/Channels/ChannelVideoItem.cs12
-rw-r--r--MediaBrowser.Controller/Channels/IChannelManager.cs9
-rw-r--r--MediaBrowser.Controller/Entities/Audio/Audio.cs63
-rw-r--r--MediaBrowser.Controller/Entities/BaseItem.cs13
-rw-r--r--MediaBrowser.Controller/Entities/IHasMediaSources.cs15
-rw-r--r--MediaBrowser.Controller/Entities/Video.cs184
-rw-r--r--MediaBrowser.Controller/MediaBrowser.Controller.csproj1
7 files changed, 293 insertions, 4 deletions
diff --git a/MediaBrowser.Controller/Channels/ChannelVideoItem.cs b/MediaBrowser.Controller/Channels/ChannelVideoItem.cs
index 2f207c4201..7a261bc58c 100644
--- a/MediaBrowser.Controller/Channels/ChannelVideoItem.cs
+++ b/MediaBrowser.Controller/Channels/ChannelVideoItem.cs
@@ -1,6 +1,7 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Channels;
using MediaBrowser.Model.Configuration;
+using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using System.Collections.Generic;
using System.Globalization;
@@ -10,6 +11,8 @@ namespace MediaBrowser.Controller.Channels
{
public class ChannelVideoItem : Video, IChannelMediaItem
{
+ public static IChannelManager ChannelManager { get; set; }
+
public string ExternalId { get; set; }
public string ChannelId { get; set; }
@@ -77,5 +80,14 @@ namespace MediaBrowser.Controller.Channels
return base.LocationType;
}
}
+
+ public override IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
+ {
+ var list = base.GetMediaSources(enablePathSubstitution).ToList();
+
+ list.InsertRange(0, ChannelManager.GetCachedChannelItemMediaSources(Id.ToString("N")));
+
+ return list;
+ }
}
}
diff --git a/MediaBrowser.Controller/Channels/IChannelManager.cs b/MediaBrowser.Controller/Channels/IChannelManager.cs
index 4be38870b8..180ac4a392 100644
--- a/MediaBrowser.Controller/Channels/IChannelManager.cs
+++ b/MediaBrowser.Controller/Channels/IChannelManager.cs
@@ -67,11 +67,18 @@ namespace MediaBrowser.Controller.Channels
Task<QueryResult<BaseItemDto>> GetChannelItems(ChannelItemQuery query, CancellationToken cancellationToken);
/// <summary>
+ /// Gets the cached channel item media sources.
+ /// </summary>
+ /// <param name="id">The identifier.</param>
+ /// <returns>IEnumerable{MediaSourceInfo}.</returns>
+ IEnumerable<MediaSourceInfo> GetCachedChannelItemMediaSources(string id);
+
+ /// <summary>
/// Gets the channel item media sources.
/// </summary>
/// <param name="id">The identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task{IEnumerable{ChannelMediaInfo}}.</returns>
+ /// <returns>Task{IEnumerable{MediaSourceInfo}}.</returns>
Task<IEnumerable<MediaSourceInfo>> GetChannelItemMediaSources(string id, CancellationToken cancellationToken);
}
}
diff --git a/MediaBrowser.Controller/Entities/Audio/Audio.cs b/MediaBrowser.Controller/Entities/Audio/Audio.cs
index dca645a750..43de1f5b0d 100644
--- a/MediaBrowser.Controller/Entities/Audio/Audio.cs
+++ b/MediaBrowser.Controller/Entities/Audio/Audio.cs
@@ -1,16 +1,27 @@
-using MediaBrowser.Controller.Providers;
+using MediaBrowser.Controller.Persistence;
+using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
+using MediaBrowser.Model.Dto;
+using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
+using System.Threading;
namespace MediaBrowser.Controller.Entities.Audio
{
/// <summary>
/// Class Audio
/// </summary>
- public class Audio : BaseItem, IHasMediaStreams, IHasAlbumArtist, IHasArtist, IHasMusicGenres, IHasLookupInfo<SongInfo>, IHasTags
+ public class Audio : BaseItem,
+ IHasMediaStreams,
+ IHasAlbumArtist,
+ IHasArtist,
+ IHasMusicGenres,
+ IHasLookupInfo<SongInfo>,
+ IHasTags,
+ IHasMediaSources
{
public string FormatName { get; set; }
public long? Size { get; set; }
@@ -164,5 +175,53 @@ namespace MediaBrowser.Controller.Entities.Audio
return info;
}
+
+ public virtual IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
+ {
+ var result = new List<MediaSourceInfo>
+ {
+ GetVersionInfo(this, enablePathSubstitution)
+ };
+
+ return result;
+ }
+
+ private static MediaSourceInfo GetVersionInfo(Audio i, bool enablePathSubstituion)
+ {
+ var locationType = i.LocationType;
+
+ var info = new MediaSourceInfo
+ {
+ Id = i.Id.ToString("N"),
+ LocationType = locationType,
+ MediaStreams = ItemRepository.GetMediaStreams(new MediaStreamQuery { ItemId = i.Id }).ToList(),
+ Name = i.Name,
+ Path = enablePathSubstituion ? GetMappedPath(i.Path, locationType) : i.Path,
+ RunTimeTicks = i.RunTimeTicks,
+ Container = i.Container,
+ Size = i.Size,
+ Formats = (i.FormatName ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList()
+ };
+
+ if (string.IsNullOrEmpty(info.Container))
+ {
+ if (!string.IsNullOrWhiteSpace(i.Path) && locationType != LocationType.Remote && locationType != LocationType.Virtual)
+ {
+ info.Container = System.IO.Path.GetExtension(i.Path).TrimStart('.');
+ }
+ }
+
+ var bitrate = i.TotalBitrate ??
+ info.MediaStreams.Where(m => m.Type == MediaStreamType.Audio)
+ .Select(m => m.BitRate ?? 0)
+ .Sum();
+
+ if (bitrate > 0)
+ {
+ info.Bitrate = bitrate;
+ }
+
+ return info;
+ }
}
}
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs
index 52c6e951ee..b7edbfc60a 100644
--- a/MediaBrowser.Controller/Entities/BaseItem.cs
+++ b/MediaBrowser.Controller/Entities/BaseItem.cs
@@ -1549,5 +1549,18 @@ namespace MediaBrowser.Controller.Entities
return hasChanges;
}
+
+ protected static string GetMappedPath(string path, LocationType locationType)
+ {
+ if (locationType == LocationType.FileSystem || locationType == LocationType.Offline)
+ {
+ foreach (var map in ConfigurationManager.Configuration.PathSubstitutions)
+ {
+ path = FileSystem.SubstitutePath(path, map.From, map.To);
+ }
+ }
+
+ return path;
+ }
}
}
diff --git a/MediaBrowser.Controller/Entities/IHasMediaSources.cs b/MediaBrowser.Controller/Entities/IHasMediaSources.cs
new file mode 100644
index 0000000000..0b0dd1bf83
--- /dev/null
+++ b/MediaBrowser.Controller/Entities/IHasMediaSources.cs
@@ -0,0 +1,15 @@
+using MediaBrowser.Model.Dto;
+using System.Collections.Generic;
+
+namespace MediaBrowser.Controller.Entities
+{
+ public interface IHasMediaSources
+ {
+ /// <summary>
+ /// Gets the media sources.
+ /// </summary>
+ /// <param name="enablePathSubstitution">if set to <c>true</c> [enable path substitution].</param>
+ /// <returns>Task{IEnumerable{MediaSourceInfo}}.</returns>
+ IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution);
+ }
+}
diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs
index 9570faa735..3bc08506ef 100644
--- a/MediaBrowser.Controller/Entities/Video.cs
+++ b/MediaBrowser.Controller/Entities/Video.cs
@@ -2,6 +2,7 @@
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Resolvers;
+using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.MediaInfo;
using System;
@@ -18,7 +19,12 @@ namespace MediaBrowser.Controller.Entities
/// <summary>
/// Class Video
/// </summary>
- public class Video : BaseItem, IHasMediaStreams, IHasAspectRatio, IHasTags, ISupportsPlaceHolders
+ public class Video : BaseItem,
+ IHasMediaStreams,
+ IHasAspectRatio,
+ IHasTags,
+ ISupportsPlaceHolders,
+ IHasMediaSources
{
public bool IsMultiPart { get; set; }
public bool HasLocalAlternateVersions { get; set; }
@@ -504,5 +510,181 @@ namespace MediaBrowser.Controller.Entities
}).FirstOrDefault();
}
+
+ public virtual IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
+ {
+ var item = this;
+
+ var result = item.GetAlternateVersions()
+ .Select(i => GetVersionInfo(enablePathSubstitution, i, MediaSourceType.Grouping))
+ .ToList();
+
+ result.Add(GetVersionInfo(enablePathSubstitution, item, MediaSourceType.Default));
+
+ return result.OrderBy(i =>
+ {
+ if (item.VideoType == VideoType.VideoFile)
+ {
+ return 0;
+ }
+
+ return 1;
+
+ }).ThenBy(i => i.Video3DFormat.HasValue ? 1 : 0)
+ .ThenByDescending(i =>
+ {
+ var stream = i.VideoStream;
+
+ return stream == null || stream.Width == null ? 0 : stream.Width.Value;
+ })
+ .ToList();
+ }
+
+ private static MediaSourceInfo GetVersionInfo(bool enablePathSubstitution, Video i, MediaSourceType type)
+ {
+ var mediaStreams = ItemRepository.GetMediaStreams(new MediaStreamQuery { ItemId = i.Id }).ToList();
+
+ var locationType = i.LocationType;
+
+ var info = new MediaSourceInfo
+ {
+ Id = i.Id.ToString("N"),
+ IsoType = i.IsoType,
+ LocationType = locationType,
+ MediaStreams = mediaStreams,
+ Name = GetMediaSourceName(i, mediaStreams),
+ Path = enablePathSubstitution ? GetMappedPath(i.Path, locationType) : i.Path,
+ RunTimeTicks = i.RunTimeTicks,
+ Video3DFormat = i.Video3DFormat,
+ VideoType = i.VideoType,
+ Container = i.Container,
+ Size = i.Size,
+ Formats = (i.FormatName ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(),
+ Timestamp = i.Timestamp,
+ Type = type
+ };
+
+ if (string.IsNullOrEmpty(info.Container))
+ {
+ if (i.VideoType == VideoType.VideoFile || i.VideoType == VideoType.Iso)
+ {
+ if (!string.IsNullOrWhiteSpace(i.Path) && locationType != LocationType.Remote && locationType != LocationType.Virtual)
+ {
+ info.Container = System.IO.Path.GetExtension(i.Path).TrimStart('.');
+ }
+ }
+ }
+
+ try
+ {
+ var bitrate = i.TotalBitrate ??
+ info.MediaStreams.Where(m => m.Type != MediaStreamType.Subtitle && !string.Equals(m.Codec, "mjpeg", StringComparison.OrdinalIgnoreCase))
+ .Select(m => m.BitRate ?? 0)
+ .Sum();
+
+ if (bitrate > 0)
+ {
+ info.Bitrate = bitrate;
+ }
+ }
+ catch (OverflowException ex)
+ {
+ Logger.ErrorException("Error calculating total bitrate", ex);
+ }
+
+ return info;
+ }
+
+
+ private static string GetMediaSourceName(Video video, List<MediaStream> mediaStreams)
+ {
+ var terms = new List<string>();
+
+ var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video);
+ var audioStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio);
+
+ if (video.Video3DFormat.HasValue)
+ {
+ terms.Add("3D");
+ }
+
+ if (video.VideoType == VideoType.BluRay)
+ {
+ terms.Add("Bluray");
+ }
+ else if (video.VideoType == VideoType.Dvd)
+ {
+ terms.Add("DVD");
+ }
+ else if (video.VideoType == VideoType.HdDvd)
+ {
+ terms.Add("HD-DVD");
+ }
+ else if (video.VideoType == VideoType.Iso)
+ {
+ if (video.IsoType.HasValue)
+ {
+ if (video.IsoType.Value == Model.Entities.IsoType.BluRay)
+ {
+ terms.Add("Bluray");
+ }
+ else if (video.IsoType.Value == Model.Entities.IsoType.Dvd)
+ {
+ terms.Add("DVD");
+ }
+ }
+ else
+ {
+ terms.Add("ISO");
+ }
+ }
+
+ if (videoStream != null)
+ {
+ if (videoStream.Width.HasValue)
+ {
+ if (videoStream.Width.Value >= 3800)
+ {
+ terms.Add("4K");
+ }
+ else if (videoStream.Width.Value >= 1900)
+ {
+ terms.Add("1080P");
+ }
+ else if (videoStream.Width.Value >= 1270)
+ {
+ terms.Add("720P");
+ }
+ else if (videoStream.Width.Value >= 700)
+ {
+ terms.Add("480P");
+ }
+ else
+ {
+ terms.Add("SD");
+ }
+ }
+ }
+
+ if (videoStream != null && !string.IsNullOrWhiteSpace(videoStream.Codec))
+ {
+ terms.Add(videoStream.Codec.ToUpper());
+ }
+
+ if (audioStream != null)
+ {
+ var audioCodec = string.Equals(audioStream.Codec, "dca", StringComparison.OrdinalIgnoreCase)
+ ? audioStream.Profile
+ : audioStream.Codec;
+
+ if (!string.IsNullOrEmpty(audioCodec))
+ {
+ terms.Add(audioCodec.ToUpper());
+ }
+ }
+
+ return string.Join("/", terms.ToArray());
+ }
+
}
}
diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj
index 435eb9c0cf..1d3c007a70 100644
--- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj
+++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj
@@ -120,6 +120,7 @@
<Compile Include="Entities\IHasDisplayOrder.cs" />
<Compile Include="Entities\IHasImages.cs" />
<Compile Include="Entities\IHasKeywords.cs" />
+ <Compile Include="Entities\IHasMediaSources.cs" />
<Compile Include="Entities\IHasMediaStreams.cs" />
<Compile Include="Entities\IHasMetascore.cs" />
<Compile Include="Entities\IHasPreferredMetadataLanguage.cs" />