Example #1
0
        private string CreateNewPlaylist(SmartPlaylistDto dto, User user)
        {
            var req = new PlaylistCreationRequest
            {
                Name   = dto.Name,
                UserId = user.Id,
            };
            var foo = _playlistManager.CreatePlaylist(req);

            return(foo.Result.Id);
        }
        private async Task CreateNewPlaylist(List<BaseItemDto> items)
        {
            var request = new PlaylistCreationRequest
            {
                UserId = AuthenticationService.Current.LoggedInUserId,
                MediaType = items.Any(x => x.IsAudio) ? "Audio" : "Video",
                ItemIdList = items.Select(x => x.Id).ToList(),
                Name = PlaylistName
            };

            try
            {
                SetProgressBar(AppResources.SysTrayAddingToPlaylist);

                var result = await ApiClient.CreatePlaylist(request);

                var playlist = new BaseItemDto
                {
                    Name = PlaylistName,
                    Id = result.Id,
                    MediaType = request.MediaType
                };

                Playlists.Add(playlist);

                PlaylistName = string.Empty;

                if (NavigationService.CanGoBack)
                {
                    NavigationService.GoBack();
                }
            }
            catch (HttpException ex)
            {
                Utils.HandleHttpException(ex, "CreateNewPlaylist()", NavigationService, Log);
                App.ShowMessage(AppResources.ErrorAddingToPlaylist);
            }

            SetProgressBar();
        }
Example #3
0
        public async Task <PlaylistCreationResult> CreatePlaylist(PlaylistCreationRequest options)
        {
            var name = options.Name;

            var folderName = _fileSystem.GetValidFilename(name) + " [playlist]";

            var parentFolder = GetPlaylistsFolder(null);

            if (parentFolder == null)
            {
                throw new ArgumentException();
            }

            if (string.IsNullOrWhiteSpace(options.MediaType))
            {
                foreach (var itemId in options.ItemIdList)
                {
                    var item = _libraryManager.GetItemById(itemId);

                    if (item == null)
                    {
                        throw new ArgumentException("No item exists with the supplied Id");
                    }

                    if (!string.IsNullOrWhiteSpace(item.MediaType))
                    {
                        options.MediaType = item.MediaType;
                    }
                    else if (item is MusicArtist || item is MusicAlbum || item is MusicGenre)
                    {
                        options.MediaType = MediaType.Audio;
                    }
                    else if (item is Genre)
                    {
                        options.MediaType = MediaType.Video;
                    }
                    else
                    {
                        var folder = item as Folder;
                        if (folder != null)
                        {
                            options.MediaType = folder.GetRecursiveChildren(i => !i.IsFolder && i.SupportsAddingToPlaylist)
                                                .Select(i => i.MediaType)
                                                .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i));
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(options.MediaType))
                    {
                        break;
                    }
                }
            }

            if (string.IsNullOrWhiteSpace(options.MediaType))
            {
                options.MediaType = "Audio";
            }

            var user = _userManager.GetUserById(options.UserId);

            var path = Path.Combine(parentFolder.Path, folderName);

            path = GetTargetPath(path);

            _iLibraryMonitor.ReportFileSystemChangeBeginning(path);

            try
            {
                _fileSystem.CreateDirectory(path);

                var playlist = new Playlist
                {
                    Name = name,
                    Path = path
                };

                playlist.Shares.Add(new Share
                {
                    UserId  = options.UserId,
                    CanEdit = true
                });

                playlist.SetMediaType(options.MediaType);

                parentFolder.AddChild(playlist, CancellationToken.None);

                await playlist.RefreshMetadata(new MetadataRefreshOptions(_fileSystem) { ForceSave = true }, CancellationToken.None)
                .ConfigureAwait(false);

                if (options.ItemIdList.Length > 0)
                {
                    await AddToPlaylistInternal(playlist.Id.ToString("N"), options.ItemIdList, user, new DtoOptions(false)
                    {
                        EnableImages = true
                    });
                }

                return(new PlaylistCreationResult
                {
                    Id = playlist.Id.ToString("N")
                });
            }
            finally
            {
                // Refresh handled internally
                _iLibraryMonitor.ReportFileSystemChangeComplete(path, false);
            }
        }
Example #4
0
        public async System.Threading.Tasks.Task Execute(CancellationToken cancellationToken, IProgress <double> progress)
        {
            if (VersionCheck.IsVersionValid(_appHost.ApplicationVersion, _appHost.SystemUpdateLevel) == false)
            {
                _logger.Info("ERROR : Plugin not compatible with this server version");
                return;
            }

            // query the user playback info for the most active movies
            ActivityRepository    repository = new ActivityRepository(_logger, _config.ApplicationPaths, _fileSystem);
            ReportPlaybackOptions config     = _config.GetReportPlaybackOptions();

            foreach (var activity_playlist in config.ActivityPlaylists)
            {
                string list_name = activity_playlist.Name;
                string list_type = activity_playlist.Type;
                int    list_days = activity_playlist.Days;
                int    list_size = activity_playlist.Size;

                _logger.Info("Activity Playlist - Name:" + list_name + " Type:" + list_type + " Days:" + list_days);

                string sql = "";
                sql += "SELECT ItemId, ";
                sql += "COUNT(DISTINCT(UserId)) as count, ";
                sql += "AVG(CAST(strftime('%Y%m%d%H%M', 'now', 'localtime') AS int) - CAST(strftime('%Y%m%d%H%M', DateCreated) AS int)) as av_age ";
                sql += "FROM PlaybackActivity ";
                sql += "WHERE ItemType = '" + list_type + "' ";
                sql += "AND DateCreated > datetime('now', '-" + list_days + " day', 'localtime') ";
                sql += "GROUP BY ItemId ";
                sql += "ORDER BY count DESC, av_age ASC ";
                sql += "LIMIT " + list_size;

                List <string>         cols          = new List <string>();
                List <List <Object> > query_results = new List <List <object> >();
                repository.RunCustomQuery(sql, cols, query_results);

                List <long> items = new List <long>();
                foreach (List <Object> row in query_results)
                {
                    long item_id = long.Parse((string)row[0]);
                    items.Add(item_id);
                }

                // create a playlist with the most active movies
                string             playlist_name = list_name;
                InternalItemsQuery query         = new InternalItemsQuery();
                query.IncludeItemTypes = new string[] { "Playlist" };
                query.Name             = playlist_name;

                BaseItem[] results = _libraryManager.GetItemList(query, false);
                foreach (BaseItem item in results)
                {
                    _logger.Info("Deleting Existing Movie Playlist : " + item.InternalId);
                    DeleteOptions delete_options = new DeleteOptions();
                    delete_options.DeleteFileLocation = true;
                    _libraryManager.DeleteItem(item, delete_options);
                }

                _logger.Info("Creating Movie Playlist");
                PlaylistCreationRequest create_options = new PlaylistCreationRequest();
                create_options.Name = playlist_name;

                if (list_type == "Movie")
                {
                    create_options.MediaType = "Movie";
                }
                else
                {
                    create_options.MediaType = "Episode";
                }

                create_options.ItemIdList = items.ToArray();
                await _playlistman.CreatePlaylist(create_options).ConfigureAwait(false);
            }
        }
Example #5
0
        public async Task <PlaylistCreationResult> CreatePlaylist(PlaylistCreationRequest options)
        {
            var name = options.Name;

            var folderName   = _fileSystem.GetValidFilename(name);
            var parentFolder = GetPlaylistsFolder(Guid.Empty);

            if (parentFolder == null)
            {
                throw new ArgumentException(nameof(parentFolder));
            }

            if (string.IsNullOrEmpty(options.MediaType))
            {
                foreach (var itemId in options.ItemIdList)
                {
                    var item = _libraryManager.GetItemById(itemId);

                    if (item == null)
                    {
                        throw new ArgumentException("No item exists with the supplied Id");
                    }

                    if (!string.IsNullOrEmpty(item.MediaType))
                    {
                        options.MediaType = item.MediaType;
                    }
                    else if (item is MusicArtist || item is MusicAlbum || item is MusicGenre)
                    {
                        options.MediaType = MediaType.Audio;
                    }
                    else if (item is Genre)
                    {
                        options.MediaType = MediaType.Video;
                    }
                    else
                    {
                        if (item is Folder folder)
                        {
                            options.MediaType = folder.GetRecursiveChildren(i => !i.IsFolder && i.SupportsAddingToPlaylist)
                                                .Select(i => i.MediaType)
                                                .FirstOrDefault(i => !string.IsNullOrEmpty(i));
                        }
                    }

                    if (!string.IsNullOrEmpty(options.MediaType))
                    {
                        break;
                    }
                }
            }

            if (string.IsNullOrEmpty(options.MediaType))
            {
                options.MediaType = "Audio";
            }

            var user = _userManager.GetUserById(options.UserId);

            var path = Path.Combine(parentFolder.Path, folderName);

            path = GetTargetPath(path);

            _iLibraryMonitor.ReportFileSystemChangeBeginning(path);

            try
            {
                Directory.CreateDirectory(path);

                var playlist = new Playlist
                {
                    Name   = name,
                    Path   = path,
                    Shares = new[]