Skip to content

Commit

Permalink
added collection type
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed Jul 12, 2013
1 parent 4d3578e commit 681fea5
Show file tree
Hide file tree
Showing 25 changed files with 324 additions and 57 deletions.
10 changes: 9 additions & 1 deletion MediaBrowser.Api/Library/LibraryHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ public static class LibraryHelpers
/// Adds the virtual folder.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="collectionType">Type of the collection.</param>
/// <param name="user">The user.</param>
/// <param name="appPaths">The app paths.</param>
/// <exception cref="System.ArgumentException">There is already a media collection with the name + name + .</exception>
public static void AddVirtualFolder(string name, User user, IServerApplicationPaths appPaths)
public static void AddVirtualFolder(string name, string collectionType, User user, IServerApplicationPaths appPaths)
{
name = FileSystem.GetValidFilename(name);

Expand All @@ -32,6 +33,13 @@ public static void AddVirtualFolder(string name, User user, IServerApplicationPa
}

Directory.CreateDirectory(virtualFolderPath);

if (!string.IsNullOrEmpty(collectionType))
{
var path = Path.Combine(virtualFolderPath, collectionType + ".collection");

File.Create(path);
}
}

/// <summary>
Expand Down
10 changes: 8 additions & 2 deletions MediaBrowser.Api/Library/LibraryStructureService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public class AddVirtualFolder : IReturnVoid
/// </summary>
/// <value>The name.</value>
public string Name { get; set; }

/// <summary>
/// Gets or sets the type of the collection.
/// </summary>
/// <value>The type of the collection.</value>
public string CollectionType { get; set; }
}

[Route("/Library/VirtualFolders/{Name}", "DELETE")]
Expand Down Expand Up @@ -196,13 +202,13 @@ public void Post(AddVirtualFolder request)
{
if (string.IsNullOrEmpty(request.UserId))
{
LibraryHelpers.AddVirtualFolder(request.Name, null, _appPaths);
LibraryHelpers.AddVirtualFolder(request.Name, request.CollectionType, null, _appPaths);
}
else
{
var user = _userManager.GetUserById(new Guid(request.UserId));

LibraryHelpers.AddVirtualFolder(request.Name, user, _appPaths);
LibraryHelpers.AddVirtualFolder(request.Name, request.CollectionType, user, _appPaths);
}

_libraryManager.ValidateMediaLibrary(new Progress<double>(), CancellationToken.None);
Expand Down
26 changes: 23 additions & 3 deletions MediaBrowser.Api/UserLibrary/ArtistsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,35 @@ public object Get(GetArtistsItemCounts request)
{
var name = DeSlugArtistName(request.Name, LibraryManager);

var items = GetItems(request.UserId).OfType<Audio>().Where(i => i.HasArtist(name)).ToList();
var items = GetItems(request.UserId).Where(i =>
{
var song = i as Audio;

if (song != null)
{
return song.HasArtist(name);
}

var musicVideo = i as MusicVideo;

if (musicVideo != null)
{
return musicVideo.HasArtist(name);
}

return false;

}).ToList();

var counts = new ItemByNameCounts
{
TotalCount = items.Count,

SongCount = items.Count(),
SongCount = items.OfType<Audio>().Count(),

AlbumCount = items.Select(i => i.Parent).OfType<MusicAlbum>().Distinct().Count(),

AlbumCount = items.Select(i => i.Parent).OfType<MusicAlbum>().Distinct().Count()
MusicVideoCount = items.OfType<MusicVideo>().Count(i => i.HasArtist(name))
};

return ToOptimizedResult(counts);
Expand Down
13 changes: 13 additions & 0 deletions MediaBrowser.Controller/Dto/DtoBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,19 @@ private void AttachBasicFields(BaseItemDto dto, BaseItem item, List<ItemFields>
{
SetGameProperties(dto, game);
}

var musicVideo = item as MusicVideo;

if (musicVideo != null)
{
SetMusicVideoProperties(dto, musicVideo);
}
}

private void SetMusicVideoProperties(BaseItemDto dto, MusicVideo item)
{
dto.Album = item.Album;
dto.Artists = string.IsNullOrEmpty(item.Artist) ? new string[] { } : new[] { item.Artist };
}

private void SetGameProperties(BaseItemDto dto, Game item)
Expand Down
20 changes: 19 additions & 1 deletion MediaBrowser.Controller/Entities/BaseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ protected internal virtual ItemResolveArgs CreateResolveArgs(FileSystemInfo path
// When resolving the root, we need it's grandchildren (children of user views)
var flattenFolderDepth = isPhysicalRoot ? 2 : 0;

args.FileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, Logger, flattenFolderDepth: flattenFolderDepth, args: args, resolveShortcuts: isPhysicalRoot || args.IsVf);
args.FileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, Logger, args, flattenFolderDepth: flattenFolderDepth, resolveShortcuts: isPhysicalRoot || args.IsVf);

// Need to remove subpaths that may have been resolved from shortcuts
// Example: if \\server\movies exists, then strip out \\server\movies\action
Expand Down Expand Up @@ -1111,6 +1111,24 @@ public void AddPerson(PersonInfo person)
throw new ArgumentNullException();
}

// Normalize
if (string.Equals(person.Role, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))
{
person.Type = PersonType.GuestStar;
}
else if (string.Equals(person.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase))
{
person.Type = PersonType.Director;
}
else if (string.Equals(person.Role, PersonType.Producer, StringComparison.OrdinalIgnoreCase))
{
person.Type = PersonType.Producer;
}
else if (string.Equals(person.Role, PersonType.Writer, StringComparison.OrdinalIgnoreCase))
{
person.Type = PersonType.Writer;
}

// If the type is GuestStar and there's already an Actor entry, then update it to avoid dupes
if (string.Equals(person.Type, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))
{
Expand Down
10 changes: 6 additions & 4 deletions MediaBrowser.Controller/Entities/CollectionFolder.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using MediaBrowser.Controller.Library;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.Library;

namespace MediaBrowser.Controller.Entities
{
Expand All @@ -29,6 +29,8 @@ public override bool IsVirtualFolder
}
}

public string CollectionType { get; set; }

/// <summary>
/// Allow different display preferences for each collection folder
/// </summary>
Expand Down Expand Up @@ -69,7 +71,7 @@ protected override Task ValidateChildrenInternal(IProgress<double> progress, Can
/// Our children are actually just references to the ones in the physical root...
/// </summary>
/// <value>The actual children.</value>
protected override ConcurrentDictionary<Guid,BaseItem> ActualChildren
protected override ConcurrentDictionary<Guid, BaseItem> ActualChildren
{
get
{
Expand All @@ -91,7 +93,7 @@ protected override ConcurrentDictionary<Guid,BaseItem> ActualChildren
.Where(i => i.Path != null && resolveArgs.PhysicalLocations.Contains(i.Path, StringComparer.OrdinalIgnoreCase))
.SelectMany(c => c.Children);

return new ConcurrentDictionary<Guid,BaseItem>(ourChildren.ToDictionary(i => i.Id));
return new ConcurrentDictionary<Guid, BaseItem>(ourChildren.ToDictionary(i => i.Id));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions MediaBrowser.Controller/Entities/Folder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Progress;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
Expand All @@ -8,6 +7,7 @@
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
Expand Down
15 changes: 8 additions & 7 deletions MediaBrowser.Controller/IO/FileData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ public static class FileData
/// </summary>
/// <param name="path">The path.</param>
/// <param name="logger">The logger.</param>
/// <param name="args">The args.</param>
/// <param name="searchPattern">The search pattern.</param>
/// <param name="flattenFolderDepth">The flatten folder depth.</param>
/// <param name="resolveShortcuts">if set to <c>true</c> [resolve shortcuts].</param>
/// <param name="args">The args.</param>
/// <returns>Dictionary{System.StringFileSystemInfo}.</returns>
/// <exception cref="System.ArgumentNullException">path</exception>
public static Dictionary<string, FileSystemInfo> GetFilteredFileSystemEntries(string path, ILogger logger, string searchPattern = "*", int flattenFolderDepth = 0, bool resolveShortcuts = true, ItemResolveArgs args = null)
public static Dictionary<string, FileSystemInfo> GetFilteredFileSystemEntries(string path, ILogger logger, ItemResolveArgs args, string searchPattern = "*", int flattenFolderDepth = 0, bool resolveShortcuts = true)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path");
}
if (args == null)
{
throw new ArgumentNullException("args");
}

var entries = new DirectoryInfo(path).EnumerateFileSystemInfos(searchPattern, SearchOption.TopDirectoryOnly);

Expand Down Expand Up @@ -60,16 +64,13 @@ public static Dictionary<string, FileSystemInfo> GetFilteredFileSystemEntries(st
var data = new DirectoryInfo(newPath);

// add to our physical locations
if (args != null)
{
args.AddAdditionalLocation(newPath);
}
args.AddAdditionalLocation(newPath);

dict[newPath] = data;
}
else if (flattenFolderDepth > 0 && isDirectory)
{
foreach (var child in GetFilteredFileSystemEntries(fullName, logger, flattenFolderDepth: flattenFolderDepth - 1, resolveShortcuts: resolveShortcuts))
foreach (var child in GetFilteredFileSystemEntries(fullName, logger, args, flattenFolderDepth: flattenFolderDepth - 1, resolveShortcuts: resolveShortcuts))
{
dict[child.Key] = child.Value;
}
Expand Down
7 changes: 7 additions & 0 deletions MediaBrowser.Controller/Library/ILibraryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,12 @@ IEnumerable<BaseItem> Sort(IEnumerable<BaseItem> items, User user, IEnumerable<s
/// </summary>
/// <param name="item">The item.</param>
void ReportItemRemoved(BaseItem item);

/// <summary>
/// Finds the type of the collection.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>System.String.</returns>
string FindCollectionType(BaseItem item);
}
}
7 changes: 7 additions & 0 deletions MediaBrowser.Model/ApiClient/IApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ public interface IApiClient : IDisposable
/// <returns>Task{ItemsResult}.</returns>
Task<ItemsResult> GetSimilarMoviesAsync(SimilarItemsQuery query);

/// <summary>
/// Gets the similar trailers async.
/// </summary>
/// <param name="query">The query.</param>
/// <returns>Task{ItemsResult}.</returns>
Task<ItemsResult> GetSimilarTrailersAsync(SimilarItemsQuery query);

/// <summary>
/// Gets the similar series async.
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions MediaBrowser.Model/Entities/CollectionType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

namespace MediaBrowser.Model.Entities
{
public static class CollectionType
{
public const string Movies = "movies";

public const string TvShows = "tvshows";

public const string Music = "music";

public const string MusicVideos = "musicvideos";

public const string Trailers = "trailers";

public const string HomeVideos = "homevideos";

public const string BoxSets = "boxsets";
}
}
6 changes: 6 additions & 0 deletions MediaBrowser.Model/Entities/VirtualFolderInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public class VirtualFolderInfo
/// <value>The locations.</value>
public List<string> Locations { get; set; }

/// <summary>
/// Gets or sets the type of the collection.
/// </summary>
/// <value>The type of the collection.</value>
public string CollectionType { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="VirtualFolderInfo"/> class.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions MediaBrowser.Model/MediaBrowser.Model.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Compile Include="Dto\ItemByNameCounts.cs" />
<Compile Include="Dto\ItemCounts.cs" />
<Compile Include="Dto\StudioDto.cs" />
<Compile Include="Entities\CollectionType.cs" />
<Compile Include="Entities\ItemReview.cs" />
<Compile Include="Entities\MediaUrl.cs" />
<Compile Include="Entities\MetadataFields.cs" />
Expand Down
4 changes: 3 additions & 1 deletion MediaBrowser.Providers/Savers/MovieXmlSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public void Save(BaseItem item, CancellationToken cancellationToken)
XmlSaverHelpers.Save(builder, xmlFilePath, new[]
{
"IMDBrating",
"Description"
"Description",
"Artist",
"Album"
});

// Set last refreshed so that the provider doesn't trigger after the file save
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void TemporarilyIgnore(string path)
public async void RemoveTempIgnore(string path)
{
// This is an arbitraty amount of time, but delay it because file system writes often trigger events after RemoveTempIgnore has been called.
await Task.Delay(500).ConfigureAwait(false);
await Task.Delay(1000).ConfigureAwait(false);

string val;
_tempIgnoredPaths.TryRemove(path, out val);
Expand Down
Loading

0 comments on commit 681fea5

Please sign in to comment.