| | 1 | | #nullable disable |
| | 2 | |
|
| | 3 | | #pragma warning disable CS1591 |
| | 4 | |
|
| | 5 | | using System; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using System.Text.Json.Serialization; |
| | 8 | | using Jellyfin.Extensions; |
| | 9 | | using Microsoft.Extensions.Logging; |
| | 10 | |
|
| | 11 | | namespace MediaBrowser.Controller.Entities |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// Class Studio. |
| | 15 | | /// </summary> |
| | 16 | | public class Studio : BaseItem, IItemByName |
| | 17 | | { |
| | 18 | | /// <summary> |
| | 19 | | /// Gets the folder containing the item. |
| | 20 | | /// If the item is a folder, it returns the folder itself. |
| | 21 | | /// </summary> |
| | 22 | | /// <value>The containing folder path.</value> |
| | 23 | | [JsonIgnore] |
| 0 | 24 | | public override string ContainingFolderPath => Path; |
| | 25 | |
|
| | 26 | | [JsonIgnore] |
| 0 | 27 | | public override bool IsDisplayedAsFolder => true; |
| | 28 | |
|
| | 29 | | [JsonIgnore] |
| 0 | 30 | | public override bool SupportsAncestors => false; |
| | 31 | |
|
| | 32 | | [JsonIgnore] |
| 0 | 33 | | public override bool SupportsPeople => false; |
| | 34 | |
|
| | 35 | | public override List<string> GetUserDataKeys() |
| | 36 | | { |
| 0 | 37 | | var list = base.GetUserDataKeys(); |
| | 38 | |
|
| 0 | 39 | | list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics()); |
| 0 | 40 | | return list; |
| | 41 | | } |
| | 42 | |
|
| | 43 | | public override string CreatePresentationUniqueKey() |
| | 44 | | { |
| 0 | 45 | | return GetUserDataKeys()[0]; |
| | 46 | | } |
| | 47 | |
|
| | 48 | | public override double GetDefaultPrimaryImageAspectRatio() |
| | 49 | | { |
| 0 | 50 | | double value = 16; |
| 0 | 51 | | value /= 9; |
| | 52 | |
|
| 0 | 53 | | return value; |
| | 54 | | } |
| | 55 | |
|
| | 56 | | public override bool CanDelete() |
| | 57 | | { |
| 0 | 58 | | return false; |
| | 59 | | } |
| | 60 | |
|
| | 61 | | public override bool IsSaveLocalMetadataEnabled() |
| | 62 | | { |
| 0 | 63 | | return true; |
| | 64 | | } |
| | 65 | |
|
| | 66 | | public IList<BaseItem> GetTaggedItems(InternalItemsQuery query) |
| | 67 | | { |
| 0 | 68 | | query.StudioIds = new[] { Id }; |
| | 69 | |
|
| 0 | 70 | | return LibraryManager.GetItemList(query); |
| | 71 | | } |
| | 72 | |
|
| | 73 | | public static string GetPath(string name) |
| | 74 | | { |
| 0 | 75 | | return GetPath(name, true); |
| | 76 | | } |
| | 77 | |
|
| | 78 | | public static string GetPath(string name, bool normalizeName) |
| | 79 | | { |
| | 80 | | // Trim the period at the end because windows will have a hard time with that |
| 0 | 81 | | var validName = normalizeName ? |
| 0 | 82 | | FileSystem.GetValidFilename(name).Trim().TrimEnd('.') : |
| 0 | 83 | | name; |
| | 84 | |
|
| 0 | 85 | | return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.StudioPath, validName); |
| | 86 | | } |
| | 87 | |
|
| | 88 | | private string GetRebasedPath() |
| | 89 | | { |
| 0 | 90 | | return GetPath(System.IO.Path.GetFileName(Path), false); |
| | 91 | | } |
| | 92 | |
|
| | 93 | | public override bool RequiresRefresh() |
| | 94 | | { |
| 0 | 95 | | var newPath = GetRebasedPath(); |
| 0 | 96 | | if (!string.Equals(Path, newPath, StringComparison.Ordinal)) |
| | 97 | | { |
| 0 | 98 | | Logger.LogDebug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath); |
| 0 | 99 | | return true; |
| | 100 | | } |
| | 101 | |
|
| 0 | 102 | | return base.RequiresRefresh(); |
| | 103 | | } |
| | 104 | |
|
| | 105 | | /// <summary> |
| | 106 | | /// This is called before any metadata refresh and returns true or false indicating if changes were made. |
| | 107 | | /// </summary> |
| | 108 | | /// <param name="replaceAllMetadata"><c>true</c> to replace all metadata, <c>false</c> to not.</param> |
| | 109 | | /// <returns><c>true</c> if changes were made, <c>false</c> if not.</returns> |
| | 110 | | public override bool BeforeMetadataRefresh(bool replaceAllMetadata) |
| | 111 | | { |
| 0 | 112 | | var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata); |
| | 113 | |
|
| 0 | 114 | | var newPath = GetRebasedPath(); |
| 0 | 115 | | if (!string.Equals(Path, newPath, StringComparison.Ordinal)) |
| | 116 | | { |
| 0 | 117 | | Path = newPath; |
| 0 | 118 | | hasChanges = true; |
| | 119 | | } |
| | 120 | |
|
| 0 | 121 | | return hasChanges; |
| | 122 | | } |
| | 123 | | } |
| | 124 | | } |