Пример #1
0
        public IEnumerable <WebMusicArtistDetailed> GetAllArtistsDetailed()
        {
            // pre-load advanced info
            string infoSql = "SELECT strArtist, strStyles, strTones, strAMGBio FROM artistinfo";
            var    detInfo = ReadList <DetailedArtistInfo>(infoSql, delegate(SQLiteDataReader reader)
            {
                return(new DetailedArtistInfo()
                {
                    Name = reader.ReadString(0),
                    Styles = reader.ReadString(1),
                    Tones = reader.ReadString(2),
                    Biography = reader.ReadString(3),
                });
            }).ToDictionary(x => x.Name, x => x);

            // then load all artists
            string sql = "SELECT strArtist, 0 AS hasAlbums, GROUP_CONCAT(strGenre, '|') AS genres " +
                         "FROM tracks " +
                         "GROUP BY strArtist " +
                         "UNION " +
                         "SELECT strAlbumArtist, 1 AS hasAlbums, GROUP_CONCAT(strGenre, '|') AS genres " +
                         "FROM tracks " +
                         "GROUP BY strAlbumArtist";

            return(ReadList(sql, delegate(SQLiteDataReader reader)
            {
                var hasAlbums = reader.ReadBoolean(1);
                var genres = reader.ReadPipeList(2);
                return reader.ReadPipeList(0).Select(x => new {
                    Artist = x,
                    HasAlbums = hasAlbums,
                    Genres = genres
                });
            })
                   .SelectMany(x => x)
                   .GroupBy(x => x.Artist)
                   .Select(x =>
            {
                var artist = new WebMusicArtistDetailed();
                artist.Id = x.Key;
                artist.HasAlbums = x.Any(y => y.HasAlbums);
                artist.Title = x.Key;

                artist.Genres = x.SelectMany(y => y.Genres).ToList();
                artist.Artwork = GetArtworkForArtist(x.Key);

                if (detInfo.ContainsKey(x.Key))
                {
                    artist.Styles = detInfo[x.Key].Styles;
                    artist.Tones = detInfo[x.Key].Tones;
                    artist.Biography = detInfo[x.Key].Biography;
                }

                return artist;
            }));
        }
Пример #2
0
 private WebMusicArtistBasic ArtistDetailedToArtistBasic(WebMusicArtistDetailed det)
 {
     return(new WebMusicArtistBasic()
     {
         Artwork = det.Artwork,
         Id = det.Id,
         PID = det.PID,
         Title = det.Title
     });
 }
        public ActionResult Albums(string artist)
        {
            WebMusicArtistDetailed     artistObj = new WebMusicArtistDetailed();
            IList <WebMusicAlbumBasic> albumList;

            if (string.IsNullOrEmpty(artist))
            {
                albumList = Connections.Current.MAS.GetMusicAlbumsBasic(Settings.ActiveSettings.MusicProvider);
            }
            else
            {
                artistObj = Connections.Current.MAS.GetMusicArtistDetailedById(Settings.ActiveSettings.MusicProvider, artist);
                albumList = Connections.Current.MAS.GetMusicAlbumsBasicForArtist(Settings.ActiveSettings.MusicProvider, artist);
            }

            return(View(new ArtistViewModel()
            {
                Artist = artistObj,
                Albums = albumList.Where(x => !String.IsNullOrEmpty(x.Title))
            }));
        }
Пример #4
0
        public IEnumerable <WebMusicArtistDetailed> GetAllArtistsDetailed()
        {
            // pre-load advanced info
            string infoSql = "SELECT strArtist, strStyles, strTones, strAMGBio FROM artistinfo";
            var    detInfo = ReadList <DetailedArtistInfo>(infoSql, delegate(SQLiteDataReader reader)
            {
                return(new DetailedArtistInfo()
                {
                    Name = reader.ReadString(0),
                    Styles = reader.ReadString(1),
                    Tones = reader.ReadString(2),
                    Biography = reader.ReadString(3),
                });
            }).ToDictionary(x => x.Name, x => x);

            // then load all artists
            string sql = "SELECT DISTINCT strArtist FROM tracks " +
                         "UNION " +
                         "SELECT DISTINCT stralbumArtist FROM tracks ";

            return(ReadList <IEnumerable <string> >(sql, delegate(SQLiteDataReader reader)
            {
                return reader.ReadPipeList(0);
            })
                   .SelectMany(x => x)
                   .Distinct()
                   .OrderBy(x => x)
                   .Select(x =>
            {
                var artist = new WebMusicArtistDetailed();
                artist.Id = x;
                artist.Title = x;

                if (detInfo.ContainsKey(x))
                {
                    artist.Styles = detInfo[x].Styles;
                    artist.Tones = detInfo[x].Tones;
                    artist.Biography = detInfo[x].Biography;
                }

                int i = 0;
                string[] filenames = new string[] {
                    PathUtil.StripInvalidCharacters(x + "L.jpg", '_'),
                    PathUtil.StripInvalidCharacters(x + ".jpg", '_')
                };
                foreach (string file in filenames)
                {
                    string path = Path.Combine(configuration["cover"], "Artists", file);
                    if (File.Exists(path))
                    {
                        artist.Artwork.Add(new WebArtworkDetailed()
                        {
                            Type = WebFileType.Cover,
                            Offset = i++,
                            Path = path,
                            Rating = 1,
                            Id = path.GetHashCode().ToString(),
                            Filetype = Path.GetExtension(path).Substring(1)
                        });
                    }
                }

                return artist;
            }));
        }