public static Subsonic.Common.Classes.User ToSubsonicUser(this User user)
 {
     return(new Subsonic.Common.Classes.User
     {
         AdminRole = user.Roles.Contains(Role.Administrator),
         CommentRole = user.Roles.Contains(Role.Administrator),
         CoverArtRole = user.Roles.Contains(Role.Administrator),
         JukeboxRole = user.Roles.Contains(Role.Administrator),
         PlaylistRole = user.Roles.Contains(Role.Administrator),
         PodcastRole = user.Roles.Contains(Role.Administrator),
         ScrobblingEnabled = user.Roles.Contains(Role.Administrator),
         ShareRole = user.Roles.Contains(Role.Administrator),
         UploadRole = user.Roles.Contains(Role.Administrator),
         VideoConversionRole = user.Roles.Contains(Role.Administrator),
         DownloadRole = user.Roles.Contains(Role.Download) || user.Roles.Contains(Role.Administrator),
         Email = user.EmailAddress,
         SettingsRole = user.Roles.Contains(Role.Settings) || user.Roles.Contains(Role.Administrator),
         StreamRole = user.Roles.Contains(Role.Playback) || user.Roles.Contains(Role.Administrator),
         Username = user.Name
     });
 }
        public static NowPlayingEntry ToSubsonicNowPlayingEntry(this MediaBundle <Track> trackMediaBundle, MediaBundle <Album> albumMediaBundle, Disposition disposition, Playback playback, User user)
        {
            var nowPlayingEntry = new NowPlayingEntry();

            var track = trackMediaBundle.Media;

            if (albumMediaBundle != null)
            {
                nowPlayingEntry.Album = albumMediaBundle.Media.Name;
            }

            nowPlayingEntry.AlbumId = track.AlbumId.ToString("n");

            var artist = track.Artists.FirstOrDefault();

            if (artist != null)
            {
                nowPlayingEntry.ArtistId = artist.Media.Id.ToString("n");
                nowPlayingEntry.Artist   = string.Join(Separator, track.Artists.Select(a => a.Media.Name));
            }

            nowPlayingEntry.BitRate     = track.Bitrate;
            nowPlayingEntry.ContentType = track.ContentType;
            nowPlayingEntry.CoverArt    = track.Id.ToString("n");
            nowPlayingEntry.Created     = track.DateFileCreated;
            nowPlayingEntry.DiscNumber  = track.DiscNumber;
            nowPlayingEntry.Duration    = (int)track.Duration.TotalSeconds;

            if (track.Genres.Count > 0)
            {
                nowPlayingEntry.Genre = string.Join(Separator, track.Genres.Select(g => g.Name));
            }

            var parentDirectory      = Directory.GetParent(track.Path);
            var grandParentDirectory = Directory.GetParent(parentDirectory.FullName);

            nowPlayingEntry.Id      = track.Id.ToString("n");
            nowPlayingEntry.IsDir   = false;
            nowPlayingEntry.IsVideo = false;
            nowPlayingEntry.Parent  = track.AlbumId.ToString("n");
            nowPlayingEntry.Path    = Path.Combine(grandParentDirectory.Name, parentDirectory.Name, Path.GetFileName(track.Path)).Replace(Path.DirectorySeparatorChar, '/');
            nowPlayingEntry.Size    = track.Size;

            if (disposition != null)
            {
                nowPlayingEntry.AverageRating = disposition.AverageRating ?? 0.0;

                if (disposition.Favorited.HasValue)
                {
                    nowPlayingEntry.Starred = disposition.Favorited.Value;
                }

                nowPlayingEntry.UserRating = disposition.UserRating ?? 0;
            }

            nowPlayingEntry.Suffix = Path.GetExtension(track.Path);
            nowPlayingEntry.Title  = track.Name;
            nowPlayingEntry.Track  = track.Number;
            nowPlayingEntry.Type   = MediaType.Music;
            nowPlayingEntry.Year   = track.ReleaseDate;

            nowPlayingEntry.MinutesAgo = (DateTime.UtcNow - playback.PlaybackDateTime).Minutes;
            nowPlayingEntry.PlayerName = playback.ClientId;
            nowPlayingEntry.Username   = user.Name;

            return(nowPlayingEntry);
        }