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