Skip to content

Commit

Permalink
add MediaInfo to improve media analysis for video files
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed Sep 20, 2014
1 parent a14a4ed commit b83e580
Show file tree
Hide file tree
Showing 67 changed files with 801 additions and 264 deletions.
11 changes: 1 addition & 10 deletions MediaBrowser.Api/UserLibrary/ItemsService.cs
Expand Up @@ -1008,7 +1008,7 @@ private IEnumerable<BaseItem> ApplyAdditionalFilters(GetItems request, IEnumerab

items = items.Where(i =>
{
var movie = i as Movie;
var movie = i as IHasSpecialFeatures;
if (movie != null)
{
Expand All @@ -1017,15 +1017,6 @@ private IEnumerable<BaseItem> ApplyAdditionalFilters(GetItems request, IEnumerab
: movie.SpecialFeatureIds.Count == 0;
}
var series = i as Series;
if (series != null)
{
return filterValue
? series.SpecialFeatureIds.Count > 0
: series.SpecialFeatureIds.Count == 0;
}
return false;
});
}
Expand Down
29 changes: 13 additions & 16 deletions MediaBrowser.Api/UserLibrary/UserLibraryService.cs
Expand Up @@ -443,22 +443,6 @@ private List<BaseItemDto> GetAsync(GetSpecialFeatures request)
// Get everything
var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList();

var movie = item as Movie;

// Get them from the db
if (movie != null)
{
// Avoid implicitly captured closure
var movie1 = movie;

var dtos = movie.SpecialFeatureIds
.Select(_libraryManager.GetItemById)
.OrderBy(i => i.SortName)
.Select(i => _dtoService.GetBaseItemDto(i, fields, user, movie1));

return dtos.ToList();
}

var series = item as Series;

// Get them from the child tree
Expand Down Expand Up @@ -486,6 +470,19 @@ private List<BaseItemDto> GetAsync(GetSpecialFeatures request)
return dtos.ToList();
}

var movie = item as IHasSpecialFeatures;

// Get them from the db
if (movie != null)
{
var dtos = movie.SpecialFeatureIds
.Select(_libraryManager.GetItemById)
.OrderBy(i => i.SortName)
.Select(i => _dtoService.GetBaseItemDto(i, fields, user, item));

return dtos.ToList();
}

return new List<BaseItemDto>();
}

Expand Down
14 changes: 14 additions & 0 deletions MediaBrowser.Controller/Entities/IHasSpecialFeatures.cs
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;

namespace MediaBrowser.Controller.Entities
{
public interface IHasSpecialFeatures
{
/// <summary>
/// Gets or sets the special feature ids.
/// </summary>
/// <value>The special feature ids.</value>
List<Guid> SpecialFeatureIds { get; set; }
}
}
2 changes: 1 addition & 1 deletion MediaBrowser.Controller/Entities/Movies/Movie.cs
Expand Up @@ -14,7 +14,7 @@ namespace MediaBrowser.Controller.Entities.Movies
/// <summary>
/// Class Movie
/// </summary>
public class Movie : Video, IHasCriticRating, IHasSoundtracks, IHasProductionLocations, IHasBudget, IHasKeywords, IHasTrailers, IHasThemeMedia, IHasTaglines, IHasPreferredMetadataLanguage, IHasAwards, IHasMetascore, IHasLookupInfo<MovieInfo>, ISupportsBoxSetGrouping
public class Movie : Video, IHasCriticRating, IHasSoundtracks, IHasSpecialFeatures, IHasProductionLocations, IHasBudget, IHasKeywords, IHasTrailers, IHasThemeMedia, IHasTaglines, IHasPreferredMetadataLanguage, IHasAwards, IHasMetascore, IHasLookupInfo<MovieInfo>, ISupportsBoxSetGrouping
{
public List<Guid> SpecialFeatureIds { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion MediaBrowser.Controller/Entities/TV/Series.cs
Expand Up @@ -13,7 +13,7 @@ namespace MediaBrowser.Controller.Entities.TV
/// <summary>
/// Class Series
/// </summary>
public class Series : Folder, IHasSoundtracks, IHasTrailers, IHasPreferredMetadataLanguage, IHasDisplayOrder, IHasLookupInfo<SeriesInfo>
public class Series : Folder, IHasSoundtracks, IHasTrailers, IHasPreferredMetadataLanguage, IHasDisplayOrder, IHasLookupInfo<SeriesInfo>, IHasSpecialFeatures
{
public List<Guid> SpecialFeatureIds { get; set; }
public List<Guid> SoundtrackIds { get; set; }
Expand Down
1 change: 1 addition & 0 deletions MediaBrowser.Controller/MediaBrowser.Controller.csproj
Expand Up @@ -141,6 +141,7 @@
<Compile Include="Entities\IHasSeries.cs" />
<Compile Include="Entities\IHasShortOverview.cs" />
<Compile Include="Entities\IHasSoundtracks.cs" />
<Compile Include="Entities\IHasSpecialFeatures.cs" />
<Compile Include="Entities\IHasTaglines.cs" />
<Compile Include="Entities\IHasTags.cs" />
<Compile Include="Entities\IHasThemeMedia.cs" />
Expand Down
60 changes: 60 additions & 0 deletions MediaBrowser.MediaInfo/MediaBrowser.MediaInfo.csproj
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6E4145E4-C6D4-4E4D-94F2-87188DB6E239}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MediaBrowser.MediaInfo</RootNamespace>
<AssemblyName>MediaBrowser.MediaInfo</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MediaInfoLib.cs" />
<Compile Include="Native.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="..\ThirdParty\MediaInfo\windows\x86\MediaInfo.dll">
<Link>MediaInfo.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
58 changes: 58 additions & 0 deletions MediaBrowser.MediaInfo/MediaInfoLib.cs
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace MediaBrowser.MediaInfo
{
public class MediaInfoLib
{
public MediaInfoResult GetVideoInfo(string path)
{
var lib = new MediaInfo();

lib.Open(path);

var result = new MediaInfoResult();

// TODO: Don't hardcode
var videoStreamIndex = 0;

var text = GetValue(lib, videoStreamIndex, new[] { "ScanType", "Scan type", "ScanType/String" });
if (!string.IsNullOrWhiteSpace(text))
{
result.IsInterlaced = text.IndexOf("interlac", StringComparison.OrdinalIgnoreCase) != -1;
}

int bitDepth;
text = GetValue(lib, videoStreamIndex, new[] { "BitDepth", "BitDepth/String" });

if (!string.IsNullOrWhiteSpace(text) && int.TryParse(text.Split(' ').First(), NumberStyles.Any, CultureInfo.InvariantCulture, out bitDepth))
{
result.BitDepth = bitDepth;
}

int refFrames;
text = GetValue(lib, videoStreamIndex, new[] { "Format_Settings_RefFrames", "Format_Settings_RefFrames/String" });

if (!string.IsNullOrWhiteSpace(text) && int.TryParse(text.Split(' ').First(), NumberStyles.Any, CultureInfo.InvariantCulture, out refFrames))
{
result.RefFrames = refFrames;
}

return result;
}

private string GetValue(MediaInfo lib, int index, IEnumerable<string> names)
{
return names.Select(i => lib.Get(StreamKind.Video, index, i)).FirstOrDefault(i => !string.IsNullOrWhiteSpace(i));
}
}

public class MediaInfoResult
{
public bool? IsInterlaced { get; set; }
public int? BitDepth { get; set; }
public int? RefFrames { get; set; }
}
}

0 comments on commit b83e580

Please sign in to comment.