public async Task <AlbumTracksDto> GetAlbumAsync(string albumId)
        {
            String url  = $"https://music.yandex.ru/handlers/album.jsx?album={albumId}&lang=ru&external-domain=music.yandex.ru&overembed=false&ncrnd=0.3792734650109968";
            JToken data = await RequestJsonAsync(url);

            String title = (String)data["title"];
            int    year  = (int)data["year"];

            var result = new AlbumTracksDto()
            {
                Image  = GetImageUrl((String)data["coverUri"]),
                Title  = title,
                Artist = String.Join(" & ", from a in data["artists"] select a["name"]),
                Year   = year,
                Tracks = (
                    from volume in data["volumes"]
                    from track in volume
                    let version = track["version"]
                                  select new TrackDto()
                {
                    Id = Convert.ToInt32(track["id"]),
                    Title = version == null ? (String)track["title"] : $"{track["title"]} ({version})",
                    Artist = String.Join(" & ", from a in track["artists"] select a["name"]),
                    AlbumTitle = title,
                    AlbumYear = year,
                    FileSize = (int)track["fileSize"],
                }
                    ).ToList(),
            };

            int i = 1;

            foreach (TrackDto t in result.Tracks)
            {
                t.Position = new TrackPosition()
                {
                    Volume = 0, Index = i
                };
                ++i;
            }

            return(result);
        }
Exemple #2
0
        public async Task <PageInfo> GetPageInfoAsync(String url)
        {
            UrlParams urlParams = urlParser.Parse(url);

            if (urlParams == null)
            {
                return(null);
            }

            PageInfo pageInfo = null;

            switch (urlParams.Type)
            {
            case PageType.Album:
                UrlParamsAlbum urlParamsAlbum = urlParams as UrlParamsAlbum;
                AlbumTracksDto albumDto       = await apiClient.GetAlbumAsync(urlParamsAlbum.AlbumId);

                pageInfo = new PageInfo()
                {
                    Type           = PageType.Album,
                    TracklistOwner = albumDto.Artist,
                    TracklistTitle = albumDto.Title,
                    Image          = albumDto.Image,
                    Tracks         = TrackListFactory.Create(albumDto.Tracks),
                };
                break;

            case PageType.Playlist:
                UrlParamsPlaylist urlParamsPlaylist = urlParams as UrlParamsPlaylist;
                PlaylistTracksDto playlistDto       = await apiClient.GetPlaylistAsync(urlParamsPlaylist.UserId, urlParamsPlaylist.PlaylistId);

                pageInfo = new PageInfo()
                {
                    Type           = PageType.Playlist,
                    TracklistOwner = playlistDto.Owner,
                    TracklistTitle = playlistDto.Title,
                    Image          = playlistDto.Image,
                    Tracks         = TrackListFactory.Create(playlistDto.TrackIds, playlistDto.Tracks, apiClient),
                };
                break;

            case PageType.Artist:
                UrlParamsArtist urlParamsArtist = urlParams as UrlParamsArtist;
                ArtistTracksDto artistDto       = await apiClient.GetArtistAsync(urlParamsArtist.ArtistId);

                pageInfo = new PageInfo()
                {
                    Type           = PageType.Artist,
                    TracklistOwner = artistDto.Name,
                    TracklistTitle = "All tracks",
                    Image          = artistDto.Image,
                    Tracks         = TrackListFactory.Create(artistDto.TrackIds, artistDto.Tracks, apiClient),
                };
                break;

            case PageType.User:
                UrlParamsUser urlParamsUser = urlParams as UrlParamsUser;
                UserTracksDto userDto       = await apiClient.GetUserAsync(urlParamsUser.UserId);

                pageInfo = new PageInfo()
                {
                    Type           = PageType.User,
                    TracklistOwner = $"{userDto.Name} / {userDto.Login}",
                    TracklistTitle = "All user tracks",
                    Image          = userDto.Image,
                    Tracks         = TrackListFactory.Create(userDto.TrackIds, userDto.Tracks, apiClient),
                };
                break;
            }

            return(pageInfo);
        }