| | 1 | | #nullable disable |
| | 2 | |
|
| | 3 | | using System; |
| | 4 | | using System.IO; |
| | 5 | | using MediaBrowser.Controller.Entities; |
| | 6 | | using MediaBrowser.Controller.Entities.Movies; |
| | 7 | | using MediaBrowser.Controller.Library; |
| | 8 | | using MediaBrowser.Model.Entities; |
| | 9 | |
|
| | 10 | | namespace Emby.Server.Implementations.Library.Resolvers.Movies |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// Class BoxSetResolver. |
| | 14 | | /// </summary> |
| | 15 | | public class BoxSetResolver : GenericFolderResolver<BoxSet> |
| | 16 | | { |
| | 17 | | /// <summary> |
| | 18 | | /// Resolves the specified args. |
| | 19 | | /// </summary> |
| | 20 | | /// <param name="args">The args.</param> |
| | 21 | | /// <returns>BoxSet.</returns> |
| | 22 | | protected override BoxSet Resolve(ItemResolveArgs args) |
| | 23 | | { |
| | 24 | | // It's a boxset if all of the following conditions are met: |
| | 25 | | // Is a Directory |
| | 26 | | // Contains [boxset] in the path |
| 12 | 27 | | if (args.IsDirectory) |
| | 28 | | { |
| 0 | 29 | | var filename = Path.GetFileName(args.Path); |
| | 30 | |
|
| 0 | 31 | | if (string.IsNullOrEmpty(filename)) |
| | 32 | | { |
| 0 | 33 | | return null; |
| | 34 | | } |
| | 35 | |
|
| 0 | 36 | | if (filename.Contains("[boxset]", StringComparison.OrdinalIgnoreCase) || args.ContainsFileSystemEntryByN |
| | 37 | | { |
| 0 | 38 | | return new BoxSet |
| 0 | 39 | | { |
| 0 | 40 | | Path = args.Path, |
| 0 | 41 | | Name = Path.GetFileName(args.Path).Replace("[boxset]", string.Empty, StringComparison.OrdinalIgn |
| 0 | 42 | | }; |
| | 43 | | } |
| | 44 | | } |
| | 45 | |
|
| 12 | 46 | | return null; |
| | 47 | | } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Sets the initial item values. |
| | 51 | | /// </summary> |
| | 52 | | /// <param name="item">The item.</param> |
| | 53 | | /// <param name="args">The args.</param> |
| | 54 | | protected override void SetInitialItemValues(BoxSet item, ItemResolveArgs args) |
| | 55 | | { |
| 0 | 56 | | base.SetInitialItemValues(item, args); |
| | 57 | |
|
| 0 | 58 | | SetProviderIdFromPath(item); |
| 0 | 59 | | } |
| | 60 | |
|
| | 61 | | /// <summary> |
| | 62 | | /// Sets the provider id from path. |
| | 63 | | /// </summary> |
| | 64 | | /// <param name="item">The item.</param> |
| | 65 | | private static void SetProviderIdFromPath(BaseItem item) |
| | 66 | | { |
| | 67 | | // we need to only look at the name of this actual item (not parents) |
| 0 | 68 | | var justName = Path.GetFileName(item.Path.AsSpan()); |
| | 69 | |
|
| 0 | 70 | | var id = justName.GetAttributeValue("tmdbid"); |
| 0 | 71 | | item.TrySetProviderId(MetadataProvider.Tmdb, id); |
| 0 | 72 | | } |
| | 73 | | } |
| | 74 | | } |