Esempio n. 1
0
        public Task Execute(CancellationToken cancellationToken, IProgress <double> progress)
        {
            var dtos = _plStore.GetAllSmartPlaylistsAsync();

            dtos.Wait();
            foreach (var dto in dtos.Result)
            {
                SmartPlaylist smart_playlist = new SmartPlaylist(dto);

                var             user = _userManager.GetUserByName(smart_playlist.User);
                List <Playlist> p;
                try
                {
                    var playlists = _playlistManager.GetPlaylists(user.Id);
                    p = playlists.Where(x => x.Id.ToString().Replace("-", "") == dto.Id).ToList();
                }
                catch (NullReferenceException ex)
                {
                    _logger.LogError(ex, "No user named {0} found, please fix playlist {1}", dto.User, dto.Name);
                    continue;
                }


                if (dto.Id == null | p.Count() == 0)
                {
                    _logger.LogInformation("Playlist ID not set, creating new playlist");
                    var plid = CreateNewPlaylist(dto, user);
                    dto.Id = plid;
                    _plStore.Save(dto);
                    var playlists = _playlistManager.GetPlaylists(user.Id);
                    p = playlists.Where(x => x.Id.ToString().Replace("-", "") == dto.Id).ToList();
                }

                var new_items = smart_playlist.FilterPlaylistItems(GetAllUserMedia(user), _libraryManager, user);

                var playlist = p.First();
                var query    = new InternalItemsQuery(user)
                {
                    IncludeItemTypes = SupportedItemTypeNames,
                    Recursive        = true,
                };
                var plitems = playlist.GetChildren(user, false, query).ToList();

                var toremove = plitems.Select(x => x.Id.ToString()).ToList();
                RemoveFromPlaylist(playlist.Id.ToString(), toremove);
                _playlistManager.AddToPlaylistAsync(playlist.Id, new_items.ToArray(), user.Id);
            }
            return(Task.CompletedTask);
        }
Esempio n. 2
0
        //[Authorize(Roles = "User")]
        public async Task <IActionResult> GetPlaylists()
        {
            if (!ModelState.IsValid)
            {
                return(StatusCode(400));
            }

            var dto = await _manager.GetPlaylists();

            var response = _mapper.Map <IEnumerable <PlaylistGetListItemResponse> >(dto);

            return(Ok(response)); //Handle Exceptions
        }
Esempio n. 3
0
 /// <inheritdoc/>
 public void InitializePlaylists()
 {
     Playlists = _playlistManager.GetPlaylists();
 }