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