fixes #296 - Prevent non-movie videos from appearing in Movies view

This commit is contained in:
Luke Pulverenti 2013-05-27 21:59:26 -04:00
parent 1f1eab209a
commit 657097ee15
20 changed files with 136 additions and 35 deletions

View File

@ -185,7 +185,8 @@ namespace MediaBrowser.Api
MovieCount = items.OfType<Movie>().Count(),
SeriesCount = items.OfType<Series>().Count(),
SongCount = items.OfType<Audio>().Count(),
TrailerCount = items.OfType<Trailer>().Count()
TrailerCount = items.OfType<Trailer>().Count(),
MusicVideoCount = items.OfType<MusicVideo>().Count()
};
return ToOptimizedResult(counts);

View File

@ -174,7 +174,9 @@ namespace MediaBrowser.Api.UserLibrary
SongCount = items.OfType<Audio>().Count(),
AlbumCount = items.OfType<MusicAlbum>().Count()
AlbumCount = items.OfType<MusicAlbum>().Count(),
MusicVideoCount = items.OfType<MusicVideo>().Count()
};
return ToOptimizedResult(counts);

View File

@ -165,7 +165,9 @@ namespace MediaBrowser.Api.UserLibrary
AlbumCount = items.OfType<MusicAlbum>().Count(),
EpisodeCount = items.OfType<Episode>().Count()
EpisodeCount = items.OfType<Episode>().Count(),
MusicVideoCount = items.OfType<MusicVideo>().Count()
};
return ToOptimizedResult(counts);

View File

@ -136,7 +136,9 @@ namespace MediaBrowser.Api.UserLibrary
SongCount = items.OfType<Audio>().Count(),
AlbumCount = items.OfType<MusicAlbum>().Count()
AlbumCount = items.OfType<MusicAlbum>().Count(),
MusicVideoCount = items.OfType<MusicVideo>().Count()
};
return ToOptimizedResult(counts);

View File

@ -1,6 +1,5 @@
using System;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

View File

@ -0,0 +1,42 @@
using MediaBrowser.Model.Entities;
using System.Runtime.Serialization;
namespace MediaBrowser.Controller.Entities
{
public class MusicVideo : Video
{
/// <summary>
/// Should be overridden to return the proper folder where metadata lives
/// </summary>
/// <value>The meta location.</value>
[IgnoreDataMember]
public override string MetaLocation
{
get
{
return VideoType == VideoType.VideoFile || VideoType == VideoType.Iso ? System.IO.Path.GetDirectoryName(Path) : Path;
}
}
/// <summary>
/// Gets the user data key.
/// </summary>
/// <returns>System.String.</returns>
public override string GetUserDataKey()
{
return this.GetProviderId(MetadataProviders.Tmdb) ?? this.GetProviderId(MetadataProviders.Imdb) ?? base.GetUserDataKey();
}
/// <summary>
/// Needed because the resolver stops at the movie folder and we find the video inside.
/// </summary>
/// <value><c>true</c> if [use parent path to create resolve args]; otherwise, <c>false</c>.</value>
protected override bool UseParentPathToCreateResolveArgs
{
get
{
return VideoType == VideoType.VideoFile || VideoType == VideoType.Iso;
}
}
}
}

View File

@ -73,6 +73,7 @@
<Compile Include="Configuration\IServerConfigurationManager.cs" />
<Compile Include="Dto\SessionInfoDtoBuilder.cs" />
<Compile Include="Entities\Audio\MusicAlbumDisc.cs" />
<Compile Include="Entities\MusicVideo.cs" />
<Compile Include="Library\ILibraryPostScanTask.cs" />
<Compile Include="Library\ILibraryPrescanTask.cs" />
<Compile Include="Providers\Movies\FanArtMovieUpdatesPrescanTask.cs" />

View File

@ -235,7 +235,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
/// <param name="video">The video.</param>
private void AddExternalSubtitles(Video video)
{
var useParent = (video.VideoType == VideoType.VideoFile || video.VideoType == VideoType.Iso) && !(video is Movie);
var useParent = (video.VideoType == VideoType.VideoFile || video.VideoType == VideoType.Iso) && !(video is Movie) && !(video is MusicVideo);
if (useParent && video.Parent == null)
{

View File

@ -103,7 +103,7 @@ namespace MediaBrowser.Controller.Providers.Movies
return !trailer.IsLocalTrailer;
}
return item is Movie || item is BoxSet;
return item is Movie || item is BoxSet || item is MusicVideo;
}
/// <summary>

View File

@ -82,7 +82,7 @@ namespace MediaBrowser.Controller.Providers.Movies
}
// Don't support local trailers
return item is Movie || item is BoxSet;
return item is Movie || item is BoxSet || item is MusicVideo;
}
/// <summary>

View File

@ -100,7 +100,7 @@ namespace MediaBrowser.Controller.Providers.Movies
}
// Don't support local trailers
return item is Movie || item is BoxSet;
return item is Movie || item is BoxSet || item is MusicVideo;
}
/// <summary>

View File

@ -23,7 +23,14 @@ namespace MediaBrowser.Controller.Providers.Movies
public override bool Supports(BaseItem item)
{
return item is Movie || item is BoxSet;
var trailer = item as Trailer;
if (trailer != null)
{
return !trailer.IsLocalTrailer;
}
return item is Movie || item is BoxSet || item is MusicVideo;
}
/// <summary>

View File

@ -25,7 +25,14 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
public override bool Supports(BaseItem item)
{
return item is Movie || item is BoxSet;
var trailer = item as Trailer;
if (trailer != null)
{
return !trailer.IsLocalTrailer;
}
return item is Movie || item is BoxSet || item is MusicVideo;
}
/// <summary>

View File

@ -87,7 +87,7 @@ namespace MediaBrowser.Controller.Providers.Movies
return !trailer.IsLocalTrailer;
}
return item is Movie;
return item is Movie || item is MusicVideo;
}
/// <summary>

View File

@ -19,6 +19,18 @@ namespace MediaBrowser.Controller.Resolvers
/// <param name="args">The args.</param>
/// <returns>`0.</returns>
protected override T Resolve(ItemResolveArgs args)
{
return ResolveVideo<T>(args);
}
/// <summary>
/// Resolves the video.
/// </summary>
/// <typeparam name="TVideoType">The type of the T video type.</typeparam>
/// <param name="args">The args.</param>
/// <returns>``0.</returns>
protected TVideoType ResolveVideo<TVideoType>(ItemResolveArgs args)
where TVideoType : Video, new()
{
// If the path is a file check for a matching extensions
if (!args.IsDirectory)
@ -30,7 +42,7 @@ namespace MediaBrowser.Controller.Resolvers
var type = string.Equals(extension, ".iso", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".img", StringComparison.OrdinalIgnoreCase) ?
VideoType.Iso : VideoType.VideoFile;
return new T
return new TVideoType
{
VideoType = type,
Path = args.Path

View File

@ -46,5 +46,10 @@ namespace MediaBrowser.Model.Dto
/// </summary>
/// <value>The album count.</value>
public int AlbumCount { get; set; }
/// <summary>
/// Gets or sets the music video count.
/// </summary>
/// <value>The music video count.</value>
public int MusicVideoCount { get; set; }
}
}

View File

@ -41,5 +41,10 @@ namespace MediaBrowser.Model.Dto
/// </summary>
/// <value>The album count.</value>
public int AlbumCount { get; set; }
/// <summary>
/// Gets or sets the music video count.
/// </summary>
/// <value>The music video count.</value>
public int MusicVideoCount { get; set; }
}
}

View File

@ -15,7 +15,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
/// <summary>
/// Class MovieResolver
/// </summary>
public class MovieResolver : BaseVideoResolver<Movie>
public class MovieResolver : BaseVideoResolver<Video>
{
private IServerApplicationPaths ApplicationPaths { get; set; }
@ -43,10 +43,10 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
/// Resolves the specified args.
/// </summary>
/// <param name="args">The args.</param>
/// <returns>Movie.</returns>
protected override Movie Resolve(ItemResolveArgs args)
/// <returns>Video.</returns>
protected override Video Resolve(ItemResolveArgs args)
{
// Must be a directory and under a 'Movies' VF
// Must be a directory
if (args.IsDirectory)
{
// Avoid expensive tests against VF's and all their children by not allowing this
@ -70,8 +70,22 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
return null;
}
// The movie must be a video file
return FindMovie(args);
// Since the looping is expensive, this is an optimization to help us avoid it
if (args.ContainsMetaFileByName("series.xml") || args.Path.IndexOf("[tvdbid", StringComparison.OrdinalIgnoreCase) != -1)
{
return null;
}
if (args.Path.IndexOf("[trailers]", StringComparison.OrdinalIgnoreCase) != -1)
{
return FindMovie<Trailer>(args);
}
if (args.Path.IndexOf("[musicvideos]", StringComparison.OrdinalIgnoreCase) != -1)
{
return FindMovie<MusicVideo>(args);
}
return FindMovie<Movie>(args);
}
return null;
@ -82,7 +96,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
/// </summary>
/// <param name="item">The item.</param>
/// <param name="args">The args.</param>
protected override void SetInitialItemValues(Movie item, ItemResolveArgs args)
protected override void SetInitialItemValues(Video item, ItemResolveArgs args)
{
base.SetInitialItemValues(item, args);
@ -93,7 +107,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
/// Sets the provider id from path.
/// </summary>
/// <param name="item">The item.</param>
private void SetProviderIdFromPath(Movie item)
private void SetProviderIdFromPath(Video item)
{
//we need to only look at the name of this actual item (not parents)
var justName = Path.GetFileName(item.Path);
@ -111,18 +125,13 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
/// </summary>
/// <param name="args">The args.</param>
/// <returns>Movie.</returns>
private Movie FindMovie(ItemResolveArgs args)
private T FindMovie<T>(ItemResolveArgs args)
where T : Video, new ()
{
// Since the looping is expensive, this is an optimization to help us avoid it
if (args.ContainsMetaFileByName("series.xml") || args.Path.IndexOf("[tvdbid", StringComparison.OrdinalIgnoreCase) != -1)
{
return null;
}
// Optimization to avoid having to resolve every file
bool? isKnownMovie = null;
var movies = new List<Movie>();
var movies = new List<T>();
// Loop through each child file/folder and see if we find a video
foreach (var child in args.FileSystemChildren)
@ -131,7 +140,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
{
if (IsDvdDirectory(child.Name))
{
return new Movie
return new T
{
Path = args.Path,
VideoType = VideoType.Dvd
@ -139,7 +148,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
}
if (IsBluRayDirectory(child.Name))
{
return new Movie
return new T
{
Path = args.Path,
VideoType = VideoType.BluRay
@ -147,7 +156,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
}
if (IsHdDvdDirectory(child.Name))
{
return new Movie
return new T
{
Path = args.Path,
VideoType = VideoType.HdDvd
@ -169,7 +178,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
Path = child.FullName
};
var item = base.Resolve(childArgs);
var item = ResolveVideo<T>(childArgs);
if (item != null)
{

View File

@ -489,6 +489,7 @@ namespace MediaBrowser.WebDashboard.Api
"musicartists.js",
"musicgenres.js",
"musicrecommended.js",
"musicvideos.js",
"playlist.js",
"plugincatalogpage.js",
"pluginspage.js",

View File

@ -324,6 +324,9 @@
<Content Include="dashboard-ui\musicrecommended.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\musicvideos.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\scripts\edititemimages.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@ -336,6 +339,9 @@
<Content Include="dashboard-ui\scripts\musicrecommended.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\scripts\musicvideos.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\scripts\search.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>