| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.ComponentModel.DataAnnotations; |
| | | 4 | | using System.Globalization; |
| | | 5 | | using System.IO; |
| | | 6 | | using System.Linq; |
| | | 7 | | using System.Threading; |
| | | 8 | | using System.Threading.Tasks; |
| | | 9 | | using Jellyfin.Api.Attributes; |
| | | 10 | | using Jellyfin.Api.Extensions; |
| | | 11 | | using Jellyfin.Api.Helpers; |
| | | 12 | | using Jellyfin.Api.ModelBinders; |
| | | 13 | | using Jellyfin.Api.Models.LibraryDtos; |
| | | 14 | | using Jellyfin.Data.Enums; |
| | | 15 | | using Jellyfin.Database.Implementations.Entities; |
| | | 16 | | using Jellyfin.Database.Implementations.Enums; |
| | | 17 | | using Jellyfin.Extensions; |
| | | 18 | | using MediaBrowser.Common.Api; |
| | | 19 | | using MediaBrowser.Common.Extensions; |
| | | 20 | | using MediaBrowser.Controller.Configuration; |
| | | 21 | | using MediaBrowser.Controller.Dto; |
| | | 22 | | using MediaBrowser.Controller.Entities; |
| | | 23 | | using MediaBrowser.Controller.Entities.Audio; |
| | | 24 | | using MediaBrowser.Controller.Entities.Movies; |
| | | 25 | | using MediaBrowser.Controller.Entities.TV; |
| | | 26 | | using MediaBrowser.Controller.IO; |
| | | 27 | | using MediaBrowser.Controller.Library; |
| | | 28 | | using MediaBrowser.Controller.Providers; |
| | | 29 | | using MediaBrowser.Model.Activity; |
| | | 30 | | using MediaBrowser.Model.Configuration; |
| | | 31 | | using MediaBrowser.Model.Dto; |
| | | 32 | | using MediaBrowser.Model.Entities; |
| | | 33 | | using MediaBrowser.Model.Globalization; |
| | | 34 | | using MediaBrowser.Model.Net; |
| | | 35 | | using MediaBrowser.Model.Querying; |
| | | 36 | | using Microsoft.AspNetCore.Authorization; |
| | | 37 | | using Microsoft.AspNetCore.Http; |
| | | 38 | | using Microsoft.AspNetCore.Mvc; |
| | | 39 | | using Microsoft.Extensions.Logging; |
| | | 40 | | |
| | | 41 | | namespace Jellyfin.Api.Controllers; |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Library Controller. |
| | | 45 | | /// </summary> |
| | | 46 | | [Route("")] |
| | | 47 | | public class LibraryController : BaseJellyfinApiController |
| | | 48 | | { |
| | | 49 | | private readonly IProviderManager _providerManager; |
| | | 50 | | private readonly ISimilarItemsManager _similarItemsManager; |
| | | 51 | | private readonly ILibraryManager _libraryManager; |
| | | 52 | | private readonly IUserManager _userManager; |
| | | 53 | | private readonly IDtoService _dtoService; |
| | | 54 | | private readonly IActivityManager _activityManager; |
| | | 55 | | private readonly ILocalizationManager _localization; |
| | | 56 | | private readonly ILibraryMonitor _libraryMonitor; |
| | | 57 | | private readonly ILogger<LibraryController> _logger; |
| | | 58 | | private readonly IServerConfigurationManager _serverConfigurationManager; |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Initializes a new instance of the <see cref="LibraryController"/> class. |
| | | 62 | | /// </summary> |
| | | 63 | | /// <param name="providerManager">Instance of the <see cref="IProviderManager"/> interface.</param> |
| | | 64 | | /// <param name="similarItemsManager">Instance of the <see cref="ISimilarItemsManager"/> interface.</param> |
| | | 65 | | /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param> |
| | | 66 | | /// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param> |
| | | 67 | | /// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param> |
| | | 68 | | /// <param name="activityManager">Instance of the <see cref="IActivityManager"/> interface.</param> |
| | | 69 | | /// <param name="localization">Instance of the <see cref="ILocalizationManager"/> interface.</param> |
| | | 70 | | /// <param name="libraryMonitor">Instance of the <see cref="ILibraryMonitor"/> interface.</param> |
| | | 71 | | /// <param name="logger">Instance of the <see cref="ILogger{LibraryController}"/> interface.</param> |
| | | 72 | | /// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</p |
| | 14 | 73 | | public LibraryController( |
| | 14 | 74 | | IProviderManager providerManager, |
| | 14 | 75 | | ISimilarItemsManager similarItemsManager, |
| | 14 | 76 | | ILibraryManager libraryManager, |
| | 14 | 77 | | IUserManager userManager, |
| | 14 | 78 | | IDtoService dtoService, |
| | 14 | 79 | | IActivityManager activityManager, |
| | 14 | 80 | | ILocalizationManager localization, |
| | 14 | 81 | | ILibraryMonitor libraryMonitor, |
| | 14 | 82 | | ILogger<LibraryController> logger, |
| | 14 | 83 | | IServerConfigurationManager serverConfigurationManager) |
| | | 84 | | { |
| | 14 | 85 | | _providerManager = providerManager; |
| | 14 | 86 | | _similarItemsManager = similarItemsManager; |
| | 14 | 87 | | _libraryManager = libraryManager; |
| | 14 | 88 | | _userManager = userManager; |
| | 14 | 89 | | _dtoService = dtoService; |
| | 14 | 90 | | _activityManager = activityManager; |
| | 14 | 91 | | _localization = localization; |
| | 14 | 92 | | _libraryMonitor = libraryMonitor; |
| | 14 | 93 | | _logger = logger; |
| | 14 | 94 | | _serverConfigurationManager = serverConfigurationManager; |
| | 14 | 95 | | } |
| | | 96 | | |
| | | 97 | | /// <summary> |
| | | 98 | | /// Get the original file of an item. |
| | | 99 | | /// </summary> |
| | | 100 | | /// <param name="itemId">The item id.</param> |
| | | 101 | | /// <response code="200">File stream returned.</response> |
| | | 102 | | /// <response code="404">Item not found.</response> |
| | | 103 | | /// <returns>A <see cref="FileStreamResult"/> with the original file.</returns> |
| | | 104 | | [HttpGet("Items/{itemId}/File")] |
| | | 105 | | [Authorize] |
| | | 106 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 107 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | | 108 | | [ProducesFile("video/*", "audio/*")] |
| | | 109 | | public ActionResult GetFile([FromRoute, Required] Guid itemId) |
| | | 110 | | { |
| | 1 | 111 | | var item = _libraryManager.GetItemById<BaseItem>(itemId, User.GetUserId()); |
| | 1 | 112 | | if (item is null) |
| | | 113 | | { |
| | 1 | 114 | | return NotFound(); |
| | | 115 | | } |
| | | 116 | | |
| | 0 | 117 | | return PhysicalFile(item.Path, MimeTypes.GetMimeType(item.Path), true); |
| | | 118 | | } |
| | | 119 | | |
| | | 120 | | /// <summary> |
| | | 121 | | /// Get theme songs for an item. |
| | | 122 | | /// </summary> |
| | | 123 | | /// <param name="itemId">The item id.</param> |
| | | 124 | | /// <param name="userId">Optional. Filter by user id, and attach user data.</param> |
| | | 125 | | /// <param name="inheritFromParent">Optional. Determines whether or not parent items should be searched for theme me |
| | | 126 | | /// <param name="sortBy">Optional. Specify one or more sort orders, comma delimited. Options: Album, AlbumArtist, Ar |
| | | 127 | | /// <param name="sortOrder">Optional. Sort Order - Ascending, Descending.</param> |
| | | 128 | | /// <response code="200">Theme songs returned.</response> |
| | | 129 | | /// <response code="404">Item not found.</response> |
| | | 130 | | /// <returns>The item theme songs.</returns> |
| | | 131 | | [HttpGet("Items/{itemId}/ThemeSongs")] |
| | | 132 | | [Authorize] |
| | | 133 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 134 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | | 135 | | public ActionResult<ThemeMediaResult> GetThemeSongs( |
| | | 136 | | [FromRoute, Required] Guid itemId, |
| | | 137 | | [FromQuery] Guid? userId, |
| | | 138 | | [FromQuery] bool inheritFromParent = false, |
| | | 139 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemSortBy[]? sortBy = null, |
| | | 140 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] SortOrder[]? sortOrder = null) |
| | | 141 | | { |
| | 2 | 142 | | userId = RequestHelpers.GetUserId(User, userId); |
| | 2 | 143 | | var user = userId.IsNullOrEmpty() |
| | 2 | 144 | | ? null |
| | 2 | 145 | | : _userManager.GetUserById(userId.Value); |
| | | 146 | | |
| | 2 | 147 | | var item = itemId.IsEmpty() |
| | 2 | 148 | | ? (userId.IsNullOrEmpty() |
| | 2 | 149 | | ? _libraryManager.RootFolder |
| | 2 | 150 | | : _libraryManager.GetUserRootFolder()) |
| | 2 | 151 | | : _libraryManager.GetItemById<BaseItem>(itemId, user); |
| | 2 | 152 | | if (item is null) |
| | | 153 | | { |
| | 2 | 154 | | return NotFound(); |
| | | 155 | | } |
| | | 156 | | |
| | 0 | 157 | | sortOrder ??= []; |
| | 0 | 158 | | sortBy ??= []; |
| | 0 | 159 | | var orderBy = RequestHelpers.GetOrderBy(sortBy, sortOrder); |
| | | 160 | | |
| | | 161 | | IReadOnlyList<BaseItem> themeItems; |
| | | 162 | | |
| | 0 | 163 | | while (true) |
| | | 164 | | { |
| | 0 | 165 | | themeItems = item.GetThemeSongs(user, orderBy); |
| | | 166 | | |
| | 0 | 167 | | if (themeItems.Count > 0 || !inheritFromParent) |
| | | 168 | | { |
| | | 169 | | break; |
| | | 170 | | } |
| | | 171 | | |
| | 0 | 172 | | var parent = item.GetParent(); |
| | 0 | 173 | | if (parent is null) |
| | | 174 | | { |
| | | 175 | | break; |
| | | 176 | | } |
| | | 177 | | |
| | 0 | 178 | | item = parent; |
| | | 179 | | } |
| | | 180 | | |
| | 0 | 181 | | var dtoOptions = new DtoOptions(); |
| | 0 | 182 | | var items = themeItems |
| | 0 | 183 | | .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item)) |
| | 0 | 184 | | .ToArray(); |
| | | 185 | | |
| | 0 | 186 | | return new ThemeMediaResult |
| | 0 | 187 | | { |
| | 0 | 188 | | Items = items, |
| | 0 | 189 | | TotalRecordCount = items.Length, |
| | 0 | 190 | | OwnerId = item.Id |
| | 0 | 191 | | }; |
| | | 192 | | } |
| | | 193 | | |
| | | 194 | | /// <summary> |
| | | 195 | | /// Get theme videos for an item. |
| | | 196 | | /// </summary> |
| | | 197 | | /// <param name="itemId">The item id.</param> |
| | | 198 | | /// <param name="userId">Optional. Filter by user id, and attach user data.</param> |
| | | 199 | | /// <param name="inheritFromParent">Optional. Determines whether or not parent items should be searched for theme me |
| | | 200 | | /// <param name="sortBy">Optional. Specify one or more sort orders, comma delimited. Options: Album, AlbumArtist, Ar |
| | | 201 | | /// <param name="sortOrder">Optional. Sort Order - Ascending, Descending.</param> |
| | | 202 | | /// <response code="200">Theme videos returned.</response> |
| | | 203 | | /// <response code="404">Item not found.</response> |
| | | 204 | | /// <returns>The item theme videos.</returns> |
| | | 205 | | [HttpGet("Items/{itemId}/ThemeVideos")] |
| | | 206 | | [Authorize] |
| | | 207 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 208 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | | 209 | | public ActionResult<ThemeMediaResult> GetThemeVideos( |
| | | 210 | | [FromRoute, Required] Guid itemId, |
| | | 211 | | [FromQuery] Guid? userId, |
| | | 212 | | [FromQuery] bool inheritFromParent = false, |
| | | 213 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemSortBy[]? sortBy = null, |
| | | 214 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] SortOrder[]? sortOrder = null) |
| | | 215 | | { |
| | 2 | 216 | | userId = RequestHelpers.GetUserId(User, userId); |
| | 2 | 217 | | var user = userId.IsNullOrEmpty() |
| | 2 | 218 | | ? null |
| | 2 | 219 | | : _userManager.GetUserById(userId.Value); |
| | 2 | 220 | | var item = itemId.IsEmpty() |
| | 2 | 221 | | ? (userId.IsNullOrEmpty() |
| | 2 | 222 | | ? _libraryManager.RootFolder |
| | 2 | 223 | | : _libraryManager.GetUserRootFolder()) |
| | 2 | 224 | | : _libraryManager.GetItemById<BaseItem>(itemId, user); |
| | 2 | 225 | | if (item is null) |
| | | 226 | | { |
| | 2 | 227 | | return NotFound(); |
| | | 228 | | } |
| | | 229 | | |
| | 0 | 230 | | sortOrder ??= []; |
| | 0 | 231 | | sortBy ??= []; |
| | 0 | 232 | | var orderBy = RequestHelpers.GetOrderBy(sortBy, sortOrder); |
| | | 233 | | |
| | | 234 | | IEnumerable<BaseItem> themeItems; |
| | | 235 | | |
| | 0 | 236 | | while (true) |
| | | 237 | | { |
| | 0 | 238 | | themeItems = item.GetThemeVideos(user, orderBy); |
| | | 239 | | |
| | 0 | 240 | | if (themeItems.Any() || !inheritFromParent) |
| | | 241 | | { |
| | | 242 | | break; |
| | | 243 | | } |
| | | 244 | | |
| | 0 | 245 | | var parent = item.GetParent(); |
| | 0 | 246 | | if (parent is null) |
| | | 247 | | { |
| | | 248 | | break; |
| | | 249 | | } |
| | | 250 | | |
| | 0 | 251 | | item = parent; |
| | | 252 | | } |
| | | 253 | | |
| | 0 | 254 | | var dtoOptions = new DtoOptions(); |
| | 0 | 255 | | var items = themeItems |
| | 0 | 256 | | .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item)) |
| | 0 | 257 | | .ToArray(); |
| | | 258 | | |
| | 0 | 259 | | return new ThemeMediaResult |
| | 0 | 260 | | { |
| | 0 | 261 | | Items = items, |
| | 0 | 262 | | TotalRecordCount = items.Length, |
| | 0 | 263 | | OwnerId = item.Id |
| | 0 | 264 | | }; |
| | | 265 | | } |
| | | 266 | | |
| | | 267 | | /// <summary> |
| | | 268 | | /// Get theme songs and videos for an item. |
| | | 269 | | /// </summary> |
| | | 270 | | /// <param name="itemId">The item id.</param> |
| | | 271 | | /// <param name="userId">Optional. Filter by user id, and attach user data.</param> |
| | | 272 | | /// <param name="inheritFromParent">Optional. Determines whether or not parent items should be searched for theme me |
| | | 273 | | /// <param name="sortBy">Optional. Specify one or more sort orders, comma delimited. Options: Album, AlbumArtist, Ar |
| | | 274 | | /// <param name="sortOrder">Optional. Sort Order - Ascending, Descending.</param> |
| | | 275 | | /// <response code="200">Theme songs and videos returned.</response> |
| | | 276 | | /// <response code="404">Item not found.</response> |
| | | 277 | | /// <returns>The item theme videos.</returns> |
| | | 278 | | [HttpGet("Items/{itemId}/ThemeMedia")] |
| | | 279 | | [Authorize] |
| | | 280 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 281 | | public ActionResult<AllThemeMediaResult> GetThemeMedia( |
| | | 282 | | [FromRoute, Required] Guid itemId, |
| | | 283 | | [FromQuery] Guid? userId, |
| | | 284 | | [FromQuery] bool inheritFromParent = false, |
| | | 285 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemSortBy[]? sortBy = null, |
| | | 286 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] SortOrder[]? sortOrder = null) |
| | | 287 | | { |
| | 1 | 288 | | var themeSongs = GetThemeSongs( |
| | 1 | 289 | | itemId, |
| | 1 | 290 | | userId, |
| | 1 | 291 | | inheritFromParent, |
| | 1 | 292 | | sortBy, |
| | 1 | 293 | | sortOrder); |
| | | 294 | | |
| | 1 | 295 | | var themeVideos = GetThemeVideos( |
| | 1 | 296 | | itemId, |
| | 1 | 297 | | userId, |
| | 1 | 298 | | inheritFromParent, |
| | 1 | 299 | | sortBy, |
| | 1 | 300 | | sortOrder); |
| | | 301 | | |
| | 1 | 302 | | if (themeSongs.Result is StatusCodeResult { StatusCode: StatusCodes.Status404NotFound } |
| | 1 | 303 | | || themeVideos.Result is StatusCodeResult { StatusCode: StatusCodes.Status404NotFound }) |
| | | 304 | | { |
| | 1 | 305 | | return NotFound(); |
| | | 306 | | } |
| | | 307 | | |
| | 0 | 308 | | return new AllThemeMediaResult |
| | 0 | 309 | | { |
| | 0 | 310 | | ThemeSongsResult = themeSongs.Value, |
| | 0 | 311 | | ThemeVideosResult = themeVideos.Value, |
| | 0 | 312 | | SoundtrackSongsResult = new ThemeMediaResult() |
| | 0 | 313 | | }; |
| | | 314 | | } |
| | | 315 | | |
| | | 316 | | /// <summary> |
| | | 317 | | /// Starts a library scan. |
| | | 318 | | /// </summary> |
| | | 319 | | /// <response code="204">Library scan started.</response> |
| | | 320 | | /// <returns>A <see cref="NoContentResult"/>.</returns> |
| | | 321 | | [HttpPost("Library/Refresh")] |
| | | 322 | | [Authorize(Policy = Policies.RequiresElevation)] |
| | | 323 | | [ProducesResponseType(StatusCodes.Status204NoContent)] |
| | | 324 | | public async Task<ActionResult> RefreshLibrary() |
| | | 325 | | { |
| | | 326 | | try |
| | | 327 | | { |
| | 0 | 328 | | await _libraryManager.ValidateMediaLibrary(new Progress<double>(), CancellationToken.None).ConfigureAwait(fa |
| | 0 | 329 | | } |
| | 0 | 330 | | catch (Exception ex) |
| | | 331 | | { |
| | 0 | 332 | | _logger.LogError(ex, "Error refreshing library"); |
| | 0 | 333 | | } |
| | | 334 | | |
| | 0 | 335 | | return NoContent(); |
| | 0 | 336 | | } |
| | | 337 | | |
| | | 338 | | /// <summary> |
| | | 339 | | /// Deletes an item from the library and filesystem. |
| | | 340 | | /// </summary> |
| | | 341 | | /// <param name="itemId">The item id.</param> |
| | | 342 | | /// <response code="204">Item deleted.</response> |
| | | 343 | | /// <response code="401">Unauthorized access.</response> |
| | | 344 | | /// <response code="404">Item not found.</response> |
| | | 345 | | /// <returns>A <see cref="NoContentResult"/>.</returns> |
| | | 346 | | [HttpDelete("Items/{itemId}")] |
| | | 347 | | [Authorize] |
| | | 348 | | [ProducesResponseType(StatusCodes.Status204NoContent)] |
| | | 349 | | [ProducesResponseType(StatusCodes.Status401Unauthorized)] |
| | | 350 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | | 351 | | public ActionResult DeleteItem(Guid itemId) |
| | | 352 | | { |
| | 1 | 353 | | var userId = User.GetUserId(); |
| | 1 | 354 | | var isApiKey = User.GetIsApiKey(); |
| | 1 | 355 | | var user = userId.IsEmpty() && isApiKey |
| | 1 | 356 | | ? null |
| | 1 | 357 | | : _userManager.GetUserById(userId); |
| | | 358 | | |
| | 1 | 359 | | if (user is null && !isApiKey) |
| | | 360 | | { |
| | 0 | 361 | | return NotFound(); |
| | | 362 | | } |
| | | 363 | | |
| | 1 | 364 | | var item = _libraryManager.GetItemById<BaseItem>(itemId, user); |
| | 1 | 365 | | if (item is null) |
| | | 366 | | { |
| | 1 | 367 | | return NotFound(); |
| | | 368 | | } |
| | | 369 | | |
| | 0 | 370 | | if (user is not null && !item.CanDelete(user)) |
| | | 371 | | { |
| | 0 | 372 | | return Unauthorized("Unauthorized access"); |
| | | 373 | | } |
| | | 374 | | |
| | 0 | 375 | | _libraryManager.DeleteItem( |
| | 0 | 376 | | item, |
| | 0 | 377 | | new DeleteOptions { DeleteFileLocation = true }, |
| | 0 | 378 | | true); |
| | | 379 | | |
| | 0 | 380 | | return NoContent(); |
| | | 381 | | } |
| | | 382 | | |
| | | 383 | | /// <summary> |
| | | 384 | | /// Deletes items from the library and filesystem. |
| | | 385 | | /// </summary> |
| | | 386 | | /// <param name="ids">The item ids.</param> |
| | | 387 | | /// <response code="204">Items deleted.</response> |
| | | 388 | | /// <response code="401">Unauthorized access.</response> |
| | | 389 | | /// <returns>A <see cref="NoContentResult"/>.</returns> |
| | | 390 | | [HttpDelete("Items")] |
| | | 391 | | [Authorize] |
| | | 392 | | [ProducesResponseType(StatusCodes.Status204NoContent)] |
| | | 393 | | [ProducesResponseType(StatusCodes.Status401Unauthorized)] |
| | | 394 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | | 395 | | public ActionResult DeleteItems([FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] Guid[] ids) |
| | | 396 | | { |
| | 1 | 397 | | var isApiKey = User.GetIsApiKey(); |
| | 1 | 398 | | var userId = User.GetUserId(); |
| | 1 | 399 | | var user = !isApiKey && !userId.IsEmpty() |
| | 1 | 400 | | ? _userManager.GetUserById(userId) ?? throw new ResourceNotFoundException() |
| | 1 | 401 | | : null; |
| | | 402 | | |
| | 1 | 403 | | if (!isApiKey && user is null) |
| | | 404 | | { |
| | 0 | 405 | | return Unauthorized("Unauthorized access"); |
| | | 406 | | } |
| | | 407 | | |
| | 3 | 408 | | foreach (var i in ids) |
| | | 409 | | { |
| | 1 | 410 | | var item = _libraryManager.GetItemById<BaseItem>(i, user); |
| | 1 | 411 | | if (item is null) |
| | | 412 | | { |
| | 1 | 413 | | return NotFound(); |
| | | 414 | | } |
| | | 415 | | |
| | 0 | 416 | | if (user is not null && !item.CanDelete(user)) |
| | | 417 | | { |
| | 0 | 418 | | return Unauthorized("Unauthorized access"); |
| | | 419 | | } |
| | | 420 | | |
| | 0 | 421 | | _libraryManager.DeleteItem( |
| | 0 | 422 | | item, |
| | 0 | 423 | | new DeleteOptions { DeleteFileLocation = true }, |
| | 0 | 424 | | true); |
| | | 425 | | } |
| | | 426 | | |
| | 0 | 427 | | return NoContent(); |
| | | 428 | | } |
| | | 429 | | |
| | | 430 | | /// <summary> |
| | | 431 | | /// Get item counts. |
| | | 432 | | /// </summary> |
| | | 433 | | /// <param name="userId">Optional. Get counts from a specific user's library.</param> |
| | | 434 | | /// <param name="isFavorite">Optional. Get counts of favorite items.</param> |
| | | 435 | | /// <response code="200">Item counts returned.</response> |
| | | 436 | | /// <returns>Item counts.</returns> |
| | | 437 | | [HttpGet("Items/Counts")] |
| | | 438 | | [Authorize] |
| | | 439 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 440 | | public ActionResult<ItemCounts> GetItemCounts( |
| | | 441 | | [FromQuery] Guid? userId, |
| | | 442 | | [FromQuery] bool? isFavorite) |
| | | 443 | | { |
| | 0 | 444 | | userId = RequestHelpers.GetUserId(User, userId); |
| | 0 | 445 | | var user = userId.IsNullOrEmpty() |
| | 0 | 446 | | ? null |
| | 0 | 447 | | : _userManager.GetUserById(userId.Value); |
| | | 448 | | |
| | 0 | 449 | | var query = new InternalItemsQuery(user) |
| | 0 | 450 | | { |
| | 0 | 451 | | Recursive = true, |
| | 0 | 452 | | IsVirtualItem = false, |
| | 0 | 453 | | IsFavorite = isFavorite, |
| | 0 | 454 | | DtoOptions = new DtoOptions(false) |
| | 0 | 455 | | { |
| | 0 | 456 | | EnableImages = false |
| | 0 | 457 | | } |
| | 0 | 458 | | }; |
| | | 459 | | |
| | 0 | 460 | | return _libraryManager.GetItemCounts(query); |
| | | 461 | | } |
| | | 462 | | |
| | | 463 | | /// <summary> |
| | | 464 | | /// Gets all parents of an item. |
| | | 465 | | /// </summary> |
| | | 466 | | /// <param name="itemId">The item id.</param> |
| | | 467 | | /// <param name="userId">Optional. Filter by user id, and attach user data.</param> |
| | | 468 | | /// <response code="200">Item parents returned.</response> |
| | | 469 | | /// <response code="404">Item not found.</response> |
| | | 470 | | /// <returns>Item parents.</returns> |
| | | 471 | | [HttpGet("Items/{itemId}/Ancestors")] |
| | | 472 | | [Authorize] |
| | | 473 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 474 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | | 475 | | public ActionResult<IEnumerable<BaseItemDto>> GetAncestors([FromRoute, Required] Guid itemId, [FromQuery] Guid? user |
| | | 476 | | { |
| | 1 | 477 | | userId = RequestHelpers.GetUserId(User, userId); |
| | 1 | 478 | | var user = userId.IsNullOrEmpty() |
| | 1 | 479 | | ? null |
| | 1 | 480 | | : _userManager.GetUserById(userId.Value); |
| | 1 | 481 | | var item = _libraryManager.GetItemById<BaseItem>(itemId, user); |
| | 1 | 482 | | if (item is null) |
| | | 483 | | { |
| | 1 | 484 | | return NotFound(); |
| | | 485 | | } |
| | | 486 | | |
| | 0 | 487 | | var baseItemDtos = new List<BaseItemDto>(); |
| | | 488 | | |
| | 0 | 489 | | var dtoOptions = new DtoOptions(); |
| | 0 | 490 | | BaseItem? parent = item.GetParent(); |
| | | 491 | | |
| | 0 | 492 | | while (parent is not null) |
| | | 493 | | { |
| | 0 | 494 | | if (user is not null) |
| | | 495 | | { |
| | 0 | 496 | | parent = TranslateParentItem(parent, user); |
| | 0 | 497 | | if (parent is null) |
| | | 498 | | { |
| | | 499 | | break; |
| | | 500 | | } |
| | | 501 | | } |
| | | 502 | | |
| | 0 | 503 | | baseItemDtos.Add(_dtoService.GetBaseItemDto(parent, dtoOptions, user)); |
| | | 504 | | |
| | 0 | 505 | | parent = parent.GetParent(); |
| | | 506 | | } |
| | | 507 | | |
| | 0 | 508 | | return baseItemDtos; |
| | | 509 | | } |
| | | 510 | | |
| | | 511 | | /// <summary> |
| | | 512 | | /// Gets a list of physical paths from virtual folders. |
| | | 513 | | /// </summary> |
| | | 514 | | /// <response code="200">Physical paths returned.</response> |
| | | 515 | | /// <returns>List of physical paths.</returns> |
| | | 516 | | [HttpGet("Library/PhysicalPaths")] |
| | | 517 | | [Authorize(Policy = Policies.RequiresElevation)] |
| | | 518 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 519 | | public ActionResult<IEnumerable<string>> GetPhysicalPaths() |
| | | 520 | | { |
| | 0 | 521 | | return Ok(_libraryManager.RootFolder.Children |
| | 0 | 522 | | .SelectMany(c => c.PhysicalLocations)); |
| | | 523 | | } |
| | | 524 | | |
| | | 525 | | /// <summary> |
| | | 526 | | /// Gets all user media folders. |
| | | 527 | | /// </summary> |
| | | 528 | | /// <param name="isHidden">Optional. Filter by folders that are marked hidden, or not.</param> |
| | | 529 | | /// <response code="200">Media folders returned.</response> |
| | | 530 | | /// <returns>List of user media folders.</returns> |
| | | 531 | | [HttpGet("Library/MediaFolders")] |
| | | 532 | | [Authorize(Policy = Policies.RequiresElevation)] |
| | | 533 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 534 | | public ActionResult<QueryResult<BaseItemDto>> GetMediaFolders([FromQuery] bool? isHidden) |
| | | 535 | | { |
| | 0 | 536 | | var items = _libraryManager.GetUserRootFolder().Children |
| | 0 | 537 | | .Concat(_libraryManager.RootFolder.VirtualChildren) |
| | 0 | 538 | | .Where(i => _libraryManager.GetLibraryOptions(i).Enabled) |
| | 0 | 539 | | .OrderBy(i => i.SortName) |
| | 0 | 540 | | .ToList(); |
| | | 541 | | |
| | 0 | 542 | | if (isHidden.HasValue) |
| | | 543 | | { |
| | 0 | 544 | | var val = isHidden.Value; |
| | | 545 | | |
| | 0 | 546 | | items = items.Where(i => i.IsHidden == val).ToList(); |
| | | 547 | | } |
| | | 548 | | |
| | 0 | 549 | | var dtoOptions = new DtoOptions(); |
| | 0 | 550 | | var resultArray = _dtoService.GetBaseItemDtos(items, dtoOptions); |
| | 0 | 551 | | return new QueryResult<BaseItemDto>(resultArray); |
| | | 552 | | } |
| | | 553 | | |
| | | 554 | | /// <summary> |
| | | 555 | | /// Reports that new episodes of a series have been added by an external source. |
| | | 556 | | /// </summary> |
| | | 557 | | /// <param name="tvdbId">The tvdbId.</param> |
| | | 558 | | /// <response code="204">Report success.</response> |
| | | 559 | | /// <returns>A <see cref="NoContentResult"/>.</returns> |
| | | 560 | | [HttpPost("Library/Series/Added", Name = "PostAddedSeries")] |
| | | 561 | | [HttpPost("Library/Series/Updated")] |
| | | 562 | | [Authorize] |
| | | 563 | | [ProducesResponseType(StatusCodes.Status204NoContent)] |
| | | 564 | | public ActionResult PostUpdatedSeries([FromQuery] string? tvdbId) |
| | | 565 | | { |
| | 0 | 566 | | var series = _libraryManager.GetItemList(new InternalItemsQuery |
| | 0 | 567 | | { |
| | 0 | 568 | | IncludeItemTypes = new[] { BaseItemKind.Series }, |
| | 0 | 569 | | DtoOptions = new DtoOptions(false) |
| | 0 | 570 | | { |
| | 0 | 571 | | EnableImages = false |
| | 0 | 572 | | } |
| | 0 | 573 | | }).Where(i => string.Equals(tvdbId, i.GetProviderId(MediaBrowser.Model.Entities.MetadataProvider.Tvdb), StringCo |
| | | 574 | | |
| | 0 | 575 | | foreach (var item in series) |
| | | 576 | | { |
| | 0 | 577 | | _libraryMonitor.ReportFileSystemChanged(item.Path); |
| | | 578 | | } |
| | | 579 | | |
| | 0 | 580 | | return NoContent(); |
| | | 581 | | } |
| | | 582 | | |
| | | 583 | | /// <summary> |
| | | 584 | | /// Reports that new movies have been added by an external source. |
| | | 585 | | /// </summary> |
| | | 586 | | /// <param name="tmdbId">The tmdbId.</param> |
| | | 587 | | /// <param name="imdbId">The imdbId.</param> |
| | | 588 | | /// <response code="204">Report success.</response> |
| | | 589 | | /// <returns>A <see cref="NoContentResult"/>.</returns> |
| | | 590 | | [HttpPost("Library/Movies/Added", Name = "PostAddedMovies")] |
| | | 591 | | [HttpPost("Library/Movies/Updated")] |
| | | 592 | | [Authorize] |
| | | 593 | | [ProducesResponseType(StatusCodes.Status204NoContent)] |
| | | 594 | | public ActionResult PostUpdatedMovies([FromQuery] string? tmdbId, [FromQuery] string? imdbId) |
| | | 595 | | { |
| | 0 | 596 | | var movies = _libraryManager.GetItemList(new InternalItemsQuery |
| | 0 | 597 | | { |
| | 0 | 598 | | IncludeItemTypes = new[] { BaseItemKind.Movie }, |
| | 0 | 599 | | DtoOptions = new DtoOptions(false) |
| | 0 | 600 | | { |
| | 0 | 601 | | EnableImages = false |
| | 0 | 602 | | } |
| | 0 | 603 | | }); |
| | | 604 | | |
| | 0 | 605 | | if (!string.IsNullOrWhiteSpace(imdbId)) |
| | | 606 | | { |
| | 0 | 607 | | movies = movies.Where(i => string.Equals(imdbId, i.GetProviderId(MediaBrowser.Model.Entities.MetadataProvide |
| | | 608 | | } |
| | 0 | 609 | | else if (!string.IsNullOrWhiteSpace(tmdbId)) |
| | | 610 | | { |
| | 0 | 611 | | movies = movies.Where(i => string.Equals(tmdbId, i.GetProviderId(MediaBrowser.Model.Entities.MetadataProvide |
| | | 612 | | } |
| | | 613 | | else |
| | | 614 | | { |
| | 0 | 615 | | movies = new List<BaseItem>(); |
| | | 616 | | } |
| | | 617 | | |
| | 0 | 618 | | foreach (var item in movies) |
| | | 619 | | { |
| | 0 | 620 | | _libraryMonitor.ReportFileSystemChanged(item.Path); |
| | | 621 | | } |
| | | 622 | | |
| | 0 | 623 | | return NoContent(); |
| | | 624 | | } |
| | | 625 | | |
| | | 626 | | /// <summary> |
| | | 627 | | /// Reports that new movies have been added by an external source. |
| | | 628 | | /// </summary> |
| | | 629 | | /// <param name="dto">The update paths.</param> |
| | | 630 | | /// <response code="204">Report success.</response> |
| | | 631 | | /// <returns>A <see cref="NoContentResult"/>.</returns> |
| | | 632 | | [HttpPost("Library/Media/Updated")] |
| | | 633 | | [Authorize] |
| | | 634 | | [ProducesResponseType(StatusCodes.Status204NoContent)] |
| | | 635 | | public ActionResult PostUpdatedMedia([FromBody, Required] MediaUpdateInfoDto dto) |
| | | 636 | | { |
| | 0 | 637 | | foreach (var item in dto.Updates) |
| | | 638 | | { |
| | 0 | 639 | | _libraryMonitor.ReportFileSystemChanged(item.Path ?? throw new ArgumentException("Item path can't be null.") |
| | | 640 | | } |
| | | 641 | | |
| | 0 | 642 | | return NoContent(); |
| | | 643 | | } |
| | | 644 | | |
| | | 645 | | /// <summary> |
| | | 646 | | /// Downloads item media. |
| | | 647 | | /// </summary> |
| | | 648 | | /// <param name="itemId">The item id.</param> |
| | | 649 | | /// <response code="200">Media downloaded.</response> |
| | | 650 | | /// <response code="404">Item not found.</response> |
| | | 651 | | /// <returns>A <see cref="FileResult"/> containing the media stream.</returns> |
| | | 652 | | /// <exception cref="ArgumentException">User can't download or item can't be downloaded.</exception> |
| | | 653 | | [HttpGet("Items/{itemId}/Download")] |
| | | 654 | | [Authorize(Policy = Policies.Download)] |
| | | 655 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 656 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | | 657 | | [ProducesFile("video/*", "audio/*")] |
| | | 658 | | public async Task<ActionResult> GetDownload([FromRoute, Required] Guid itemId) |
| | | 659 | | { |
| | 1 | 660 | | var userId = User.GetUserId(); |
| | 1 | 661 | | var user = userId.IsEmpty() |
| | 1 | 662 | | ? null |
| | 1 | 663 | | : _userManager.GetUserById(userId); |
| | 1 | 664 | | var item = _libraryManager.GetItemById<BaseItem>(itemId, user); |
| | 1 | 665 | | if (item is null) |
| | | 666 | | { |
| | 1 | 667 | | return NotFound(); |
| | | 668 | | } |
| | | 669 | | |
| | 0 | 670 | | if (user is not null) |
| | | 671 | | { |
| | 0 | 672 | | if (!item.CanDownload(user)) |
| | | 673 | | { |
| | 0 | 674 | | throw new ArgumentException("Item does not support downloading"); |
| | | 675 | | } |
| | | 676 | | } |
| | | 677 | | else |
| | | 678 | | { |
| | 0 | 679 | | if (!item.CanDownload()) |
| | | 680 | | { |
| | 0 | 681 | | throw new ArgumentException("Item does not support downloading"); |
| | | 682 | | } |
| | | 683 | | } |
| | | 684 | | |
| | 0 | 685 | | if (user is not null) |
| | | 686 | | { |
| | 0 | 687 | | await LogDownloadAsync(item, user).ConfigureAwait(false); |
| | | 688 | | } |
| | | 689 | | |
| | | 690 | | // Quotes are valid in linux. They'll possibly cause issues here. |
| | 0 | 691 | | var filename = Path.GetFileName(item.Path)?.Replace("\"", string.Empty, StringComparison.Ordinal); |
| | | 692 | | |
| | 0 | 693 | | var filePath = item.Path; |
| | 0 | 694 | | if (item.IsFileProtocol) |
| | | 695 | | { |
| | | 696 | | // PhysicalFile does not work well with symlinks at the moment. |
| | 0 | 697 | | var resolved = FileSystemHelper.ResolveLinkTarget(filePath, returnFinalTarget: true); |
| | 0 | 698 | | if (resolved is not null && resolved.Exists) |
| | | 699 | | { |
| | 0 | 700 | | filePath = resolved.FullName; |
| | | 701 | | } |
| | | 702 | | } |
| | | 703 | | |
| | 0 | 704 | | return PhysicalFile(filePath, MimeTypes.GetMimeType(filePath), filename, true); |
| | 1 | 705 | | } |
| | | 706 | | |
| | | 707 | | /// <summary> |
| | | 708 | | /// Gets similar items. |
| | | 709 | | /// </summary> |
| | | 710 | | /// <param name="itemId">The item id.</param> |
| | | 711 | | /// <param name="excludeArtistIds">Exclude artist ids.</param> |
| | | 712 | | /// <param name="userId">Optional. Filter by user id, and attach user data.</param> |
| | | 713 | | /// <param name="limit">Optional. The maximum number of records to return.</param> |
| | | 714 | | /// <param name="fields">Optional. Specify additional fields of information to return in the output. This allows mul |
| | | 715 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | | 716 | | /// <response code="200">Similar items returned.</response> |
| | | 717 | | /// <returns>A <see cref="QueryResult{BaseItemDto}"/> containing the similar items.</returns> |
| | | 718 | | [HttpGet("Artists/{itemId}/Similar", Name = "GetSimilarArtists")] |
| | | 719 | | [HttpGet("Items/{itemId}/Similar")] |
| | | 720 | | [HttpGet("Albums/{itemId}/Similar", Name = "GetSimilarAlbums")] |
| | | 721 | | [HttpGet("Shows/{itemId}/Similar", Name = "GetSimilarShows")] |
| | | 722 | | [HttpGet("Movies/{itemId}/Similar", Name = "GetSimilarMovies")] |
| | | 723 | | [HttpGet("Trailers/{itemId}/Similar", Name = "GetSimilarTrailers")] |
| | | 724 | | [Authorize] |
| | | 725 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 726 | | public async Task<ActionResult<QueryResult<BaseItemDto>>> GetSimilarItems( |
| | | 727 | | [FromRoute, Required] Guid itemId, |
| | | 728 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] Guid[] excludeArtistIds, |
| | | 729 | | [FromQuery] Guid? userId, |
| | | 730 | | [FromQuery] int? limit, |
| | | 731 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFields[] fields, |
| | | 732 | | CancellationToken cancellationToken) |
| | | 733 | | { |
| | 6 | 734 | | userId = RequestHelpers.GetUserId(User, userId); |
| | 6 | 735 | | var user = userId.IsNullOrEmpty() |
| | 6 | 736 | | ? null |
| | 6 | 737 | | : _userManager.GetUserById(userId.Value); |
| | 6 | 738 | | var item = itemId.IsEmpty() |
| | 6 | 739 | | ? (user is null |
| | 6 | 740 | | ? _libraryManager.RootFolder |
| | 6 | 741 | | : _libraryManager.GetUserRootFolder()) |
| | 6 | 742 | | : _libraryManager.GetItemById<BaseItem>(itemId, user); |
| | 6 | 743 | | if (item is null) |
| | | 744 | | { |
| | 6 | 745 | | return NotFound(); |
| | | 746 | | } |
| | | 747 | | |
| | 0 | 748 | | if (item is Episode || (item is IItemByName && item is not MusicArtist)) |
| | | 749 | | { |
| | 0 | 750 | | return new QueryResult<BaseItemDto>(); |
| | | 751 | | } |
| | | 752 | | |
| | 0 | 753 | | var dtoOptions = new DtoOptions { Fields = fields }; |
| | | 754 | | |
| | | 755 | | // Get library options for provider configuration |
| | 0 | 756 | | var libraryOptions = _libraryManager.GetLibraryOptions(item); |
| | | 757 | | |
| | 0 | 758 | | var itemsResult = await _similarItemsManager.GetSimilarItemsAsync( |
| | 0 | 759 | | item, |
| | 0 | 760 | | excludeArtistIds, |
| | 0 | 761 | | user, |
| | 0 | 762 | | dtoOptions, |
| | 0 | 763 | | limit, |
| | 0 | 764 | | libraryOptions, |
| | 0 | 765 | | cancellationToken).ConfigureAwait(false); |
| | | 766 | | |
| | 0 | 767 | | var returnList = _dtoService.GetBaseItemDtos(itemsResult, dtoOptions, user); |
| | | 768 | | |
| | 0 | 769 | | return new QueryResult<BaseItemDto>( |
| | 0 | 770 | | 0, |
| | 0 | 771 | | itemsResult.Count, |
| | 0 | 772 | | returnList); |
| | 6 | 773 | | } |
| | | 774 | | |
| | | 775 | | /// <summary> |
| | | 776 | | /// Gets the library options info. |
| | | 777 | | /// </summary> |
| | | 778 | | /// <param name="libraryContentType">Library content type.</param> |
| | | 779 | | /// <param name="isNewLibrary">Whether this is a new library.</param> |
| | | 780 | | /// <response code="200">Library options info returned.</response> |
| | | 781 | | /// <returns>Library options info.</returns> |
| | | 782 | | [HttpGet("Libraries/AvailableOptions")] |
| | | 783 | | [Authorize(Policy = Policies.FirstTimeSetupOrDefault)] |
| | | 784 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 785 | | public ActionResult<LibraryOptionsResultDto> GetLibraryOptionsInfo( |
| | | 786 | | [FromQuery] CollectionType? libraryContentType, |
| | | 787 | | [FromQuery] bool isNewLibrary = false) |
| | | 788 | | { |
| | 0 | 789 | | var result = new LibraryOptionsResultDto(); |
| | | 790 | | |
| | 0 | 791 | | var types = GetRepresentativeItemTypes(libraryContentType); |
| | 0 | 792 | | var typesList = types.ToList(); |
| | | 793 | | |
| | 0 | 794 | | var plugins = _providerManager.GetAllMetadataPlugins() |
| | 0 | 795 | | .Where(i => types.Contains(i.ItemType, StringComparison.OrdinalIgnoreCase)) |
| | 0 | 796 | | .OrderBy(i => typesList.IndexOf(i.ItemType)) |
| | 0 | 797 | | .ToList(); |
| | | 798 | | |
| | 0 | 799 | | result.MetadataSavers = plugins |
| | 0 | 800 | | .SelectMany(i => i.Plugins.Where(p => p.Type == MetadataPluginType.MetadataSaver)) |
| | 0 | 801 | | .Select(i => new LibraryOptionInfoDto |
| | 0 | 802 | | { |
| | 0 | 803 | | Name = i.Name, |
| | 0 | 804 | | DefaultEnabled = IsSaverEnabledByDefault(i.Name, types, isNewLibrary) |
| | 0 | 805 | | }) |
| | 0 | 806 | | .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) |
| | 0 | 807 | | .ToArray(); |
| | | 808 | | |
| | 0 | 809 | | result.MetadataReaders = plugins |
| | 0 | 810 | | .SelectMany(i => i.Plugins.Where(p => p.Type == MetadataPluginType.LocalMetadataProvider)) |
| | 0 | 811 | | .Select(i => new LibraryOptionInfoDto |
| | 0 | 812 | | { |
| | 0 | 813 | | Name = i.Name, |
| | 0 | 814 | | DefaultEnabled = true |
| | 0 | 815 | | }) |
| | 0 | 816 | | .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) |
| | 0 | 817 | | .ToArray(); |
| | | 818 | | |
| | 0 | 819 | | result.SubtitleFetchers = plugins |
| | 0 | 820 | | .SelectMany(i => i.Plugins.Where(p => p.Type == MetadataPluginType.SubtitleFetcher)) |
| | 0 | 821 | | .Select(i => new LibraryOptionInfoDto |
| | 0 | 822 | | { |
| | 0 | 823 | | Name = i.Name, |
| | 0 | 824 | | DefaultEnabled = true |
| | 0 | 825 | | }) |
| | 0 | 826 | | .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) |
| | 0 | 827 | | .ToArray(); |
| | | 828 | | |
| | 0 | 829 | | result.LyricFetchers = plugins |
| | 0 | 830 | | .SelectMany(i => i.Plugins.Where(p => p.Type == MetadataPluginType.LyricFetcher)) |
| | 0 | 831 | | .Select(i => new LibraryOptionInfoDto |
| | 0 | 832 | | { |
| | 0 | 833 | | Name = i.Name, |
| | 0 | 834 | | DefaultEnabled = true |
| | 0 | 835 | | }) |
| | 0 | 836 | | .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) |
| | 0 | 837 | | .ToArray(); |
| | | 838 | | |
| | 0 | 839 | | result.MediaSegmentProviders = plugins |
| | 0 | 840 | | .SelectMany(i => i.Plugins.Where(p => p.Type == MetadataPluginType.MediaSegmentProvider)) |
| | 0 | 841 | | .Select(i => new LibraryOptionInfoDto |
| | 0 | 842 | | { |
| | 0 | 843 | | Name = i.Name, |
| | 0 | 844 | | DefaultEnabled = true |
| | 0 | 845 | | }) |
| | 0 | 846 | | .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) |
| | 0 | 847 | | .ToArray(); |
| | | 848 | | |
| | 0 | 849 | | var typeOptions = new List<LibraryTypeOptionsDto>(); |
| | | 850 | | |
| | 0 | 851 | | foreach (var type in types) |
| | | 852 | | { |
| | 0 | 853 | | TypeOptions.DefaultImageOptions.TryGetValue(type, out var defaultImageOptions); |
| | | 854 | | |
| | 0 | 855 | | typeOptions.Add(new LibraryTypeOptionsDto |
| | 0 | 856 | | { |
| | 0 | 857 | | Type = type, |
| | 0 | 858 | | |
| | 0 | 859 | | MetadataFetchers = plugins |
| | 0 | 860 | | .Where(i => string.Equals(i.ItemType, type, StringComparison.OrdinalIgnoreCase)) |
| | 0 | 861 | | .SelectMany(i => i.Plugins.Where(p => p.Type == MetadataPluginType.MetadataFetcher)) |
| | 0 | 862 | | .Select(i => new LibraryOptionInfoDto |
| | 0 | 863 | | { |
| | 0 | 864 | | Name = i.Name, |
| | 0 | 865 | | DefaultEnabled = IsMetadataFetcherEnabledByDefault(i.Name, type, isNewLibrary) |
| | 0 | 866 | | }) |
| | 0 | 867 | | .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) |
| | 0 | 868 | | .ToArray(), |
| | 0 | 869 | | |
| | 0 | 870 | | ImageFetchers = plugins |
| | 0 | 871 | | .Where(i => string.Equals(i.ItemType, type, StringComparison.OrdinalIgnoreCase)) |
| | 0 | 872 | | .SelectMany(i => i.Plugins.Where(p => p.Type == MetadataPluginType.ImageFetcher)) |
| | 0 | 873 | | .Select(i => new LibraryOptionInfoDto |
| | 0 | 874 | | { |
| | 0 | 875 | | Name = i.Name, |
| | 0 | 876 | | DefaultEnabled = IsImageFetcherEnabledByDefault(i.Name, type, isNewLibrary) |
| | 0 | 877 | | }) |
| | 0 | 878 | | .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) |
| | 0 | 879 | | .ToArray(), |
| | 0 | 880 | | |
| | 0 | 881 | | SimilarItemProviders = plugins |
| | 0 | 882 | | .Where(i => string.Equals(i.ItemType, type, StringComparison.OrdinalIgnoreCase)) |
| | 0 | 883 | | .SelectMany(i => i.Plugins.Where(p => p.Type == MetadataPluginType.LocalSimilarityProvider || p.Type |
| | 0 | 884 | | .Select(i => new LibraryOptionInfoDto |
| | 0 | 885 | | { |
| | 0 | 886 | | Name = i.Name, |
| | 0 | 887 | | DefaultEnabled = i.Type == MetadataPluginType.LocalSimilarityProvider |
| | 0 | 888 | | }) |
| | 0 | 889 | | .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) |
| | 0 | 890 | | .ToArray(), |
| | 0 | 891 | | |
| | 0 | 892 | | SupportedImageTypes = plugins |
| | 0 | 893 | | .Where(i => string.Equals(i.ItemType, type, StringComparison.OrdinalIgnoreCase)) |
| | 0 | 894 | | .SelectMany(i => i.SupportedImageTypes ?? Array.Empty<ImageType>()) |
| | 0 | 895 | | .Distinct() |
| | 0 | 896 | | .ToArray(), |
| | 0 | 897 | | |
| | 0 | 898 | | DefaultImageOptions = defaultImageOptions ?? Array.Empty<ImageOption>() |
| | 0 | 899 | | }); |
| | | 900 | | } |
| | | 901 | | |
| | 0 | 902 | | result.TypeOptions = typeOptions.ToArray(); |
| | | 903 | | |
| | 0 | 904 | | return result; |
| | | 905 | | } |
| | | 906 | | |
| | | 907 | | private BaseItem? TranslateParentItem(BaseItem item, User user) |
| | | 908 | | { |
| | 0 | 909 | | return item.GetParent() is AggregateFolder |
| | 0 | 910 | | ? _libraryManager.GetUserRootFolder().GetChildren(user, true) |
| | 0 | 911 | | .FirstOrDefault(i => i.PhysicalLocations.Contains(item.Path)) |
| | 0 | 912 | | : item; |
| | | 913 | | } |
| | | 914 | | |
| | | 915 | | private async Task LogDownloadAsync(BaseItem item, User user) |
| | | 916 | | { |
| | | 917 | | try |
| | | 918 | | { |
| | 0 | 919 | | await _activityManager.CreateAsync(new ActivityLog( |
| | 0 | 920 | | string.Format(CultureInfo.InvariantCulture, _localization.GetServerLocalizedString("UserDownloadingItemW |
| | 0 | 921 | | "UserDownloadingContent", |
| | 0 | 922 | | User.GetUserId()) |
| | 0 | 923 | | { |
| | 0 | 924 | | ShortOverview = string.Format(CultureInfo.InvariantCulture, _localization.GetServerLocalizedString("AppD |
| | 0 | 925 | | ItemId = item.Id.ToString("N", CultureInfo.InvariantCulture) |
| | 0 | 926 | | }).ConfigureAwait(false); |
| | 0 | 927 | | } |
| | 0 | 928 | | catch |
| | | 929 | | { |
| | | 930 | | // Logged at lower levels |
| | 0 | 931 | | } |
| | 0 | 932 | | } |
| | | 933 | | |
| | | 934 | | private static string[] GetRepresentativeItemTypes(CollectionType? contentType) |
| | | 935 | | { |
| | 0 | 936 | | return contentType switch |
| | 0 | 937 | | { |
| | 0 | 938 | | CollectionType.boxsets => new[] { "BoxSet" }, |
| | 0 | 939 | | CollectionType.playlists => new[] { "Playlist" }, |
| | 0 | 940 | | CollectionType.movies => new[] { "Movie" }, |
| | 0 | 941 | | CollectionType.tvshows => new[] { "Series", "Season", "Episode" }, |
| | 0 | 942 | | CollectionType.books => new[] { "Book", "AudioBook" }, |
| | 0 | 943 | | CollectionType.music => new[] { "MusicArtist", "MusicAlbum", "Audio", "MusicVideo" }, |
| | 0 | 944 | | CollectionType.homevideos => new[] { "Video", "Photo" }, |
| | 0 | 945 | | CollectionType.photos => new[] { "Video", "Photo" }, |
| | 0 | 946 | | CollectionType.musicvideos => new[] { "MusicVideo" }, |
| | 0 | 947 | | _ => new[] { "Series", "Season", "Episode", "Movie" } |
| | 0 | 948 | | }; |
| | | 949 | | } |
| | | 950 | | |
| | | 951 | | private bool IsSaverEnabledByDefault(string name, string[] itemTypes, bool isNewLibrary) |
| | | 952 | | { |
| | 0 | 953 | | if (isNewLibrary) |
| | | 954 | | { |
| | 0 | 955 | | return false; |
| | | 956 | | } |
| | | 957 | | |
| | 0 | 958 | | var metadataOptions = _serverConfigurationManager.Configuration.MetadataOptions |
| | 0 | 959 | | .Where(i => itemTypes.Contains(i.ItemType ?? string.Empty, StringComparison.OrdinalIgnoreCase)) |
| | 0 | 960 | | .ToArray(); |
| | | 961 | | |
| | 0 | 962 | | return metadataOptions.Length == 0 || metadataOptions.Any(i => !i.DisabledMetadataSavers.Contains(name, StringCo |
| | | 963 | | } |
| | | 964 | | |
| | | 965 | | private bool IsMetadataFetcherEnabledByDefault(string name, string type, bool isNewLibrary) |
| | | 966 | | { |
| | 0 | 967 | | if (isNewLibrary) |
| | | 968 | | { |
| | 0 | 969 | | if (string.Equals(name, "TheMovieDb", StringComparison.OrdinalIgnoreCase)) |
| | | 970 | | { |
| | 0 | 971 | | return !(string.Equals(type, "Season", StringComparison.OrdinalIgnoreCase) |
| | 0 | 972 | | || string.Equals(type, "Episode", StringComparison.OrdinalIgnoreCase) |
| | 0 | 973 | | || string.Equals(type, "MusicVideo", StringComparison.OrdinalIgnoreCase)); |
| | | 974 | | } |
| | | 975 | | |
| | 0 | 976 | | return string.Equals(name, "TheTVDB", StringComparison.OrdinalIgnoreCase) |
| | 0 | 977 | | || string.Equals(name, "TheAudioDB", StringComparison.OrdinalIgnoreCase) |
| | 0 | 978 | | || string.Equals(name, "MusicBrainz", StringComparison.OrdinalIgnoreCase); |
| | | 979 | | } |
| | | 980 | | |
| | 0 | 981 | | var metadataOptions = _serverConfigurationManager.GetMetadataOptionsForType(type); |
| | 0 | 982 | | return metadataOptions is null || !metadataOptions.DisabledMetadataFetchers.Contains(name, StringComparison.Ordi |
| | | 983 | | } |
| | | 984 | | |
| | | 985 | | private bool IsImageFetcherEnabledByDefault(string name, string type, bool isNewLibrary) |
| | | 986 | | { |
| | 0 | 987 | | if (isNewLibrary) |
| | | 988 | | { |
| | 0 | 989 | | if (string.Equals(name, "TheMovieDb", StringComparison.OrdinalIgnoreCase)) |
| | | 990 | | { |
| | 0 | 991 | | return !string.Equals(type, "Series", StringComparison.OrdinalIgnoreCase) |
| | 0 | 992 | | && !string.Equals(type, "Season", StringComparison.OrdinalIgnoreCase) |
| | 0 | 993 | | && !string.Equals(type, "Episode", StringComparison.OrdinalIgnoreCase) |
| | 0 | 994 | | && !string.Equals(type, "MusicVideo", StringComparison.OrdinalIgnoreCase); |
| | | 995 | | } |
| | | 996 | | |
| | 0 | 997 | | return string.Equals(name, "TheTVDB", StringComparison.OrdinalIgnoreCase) |
| | 0 | 998 | | || string.Equals(name, "Screen Grabber", StringComparison.OrdinalIgnoreCase) |
| | 0 | 999 | | || string.Equals(name, "TheAudioDB", StringComparison.OrdinalIgnoreCase) |
| | 0 | 1000 | | || string.Equals(name, "Image Extractor", StringComparison.OrdinalIgnoreCase); |
| | | 1001 | | } |
| | | 1002 | | |
| | 0 | 1003 | | var metadataOptions = _serverConfigurationManager.GetMetadataOptionsForType(type); |
| | 0 | 1004 | | return metadataOptions is null || !metadataOptions.DisabledImageFetchers.Contains(name, StringComparison.Ordinal |
| | | 1005 | | } |
| | | 1006 | | } |