示例#1
0
        public static SongViewModel ToSongFromVk(SongInfo song)
        {
            Mapper.CreateMap<SongInfo, SongViewModel>();
            var result = Mapper.Map<SongInfo, SongViewModel>(song);
            if (result.Duration != default(TimeSpan))
            {
                result.DurationFormatted = result.Duration.ToString(@"mm\:ss");

            }
            return result;
        }
示例#2
0
        //public SongInfo GetSongInfo(string songTitle)
        //{
        //    int totalCount;
        //    var audios = _vkApi.Audio.Search(songTitle, out totalCount, true, findLyrics: true);
        //    var foundAudio = audios.FirstOrDefault();
        //    var info = new SongInfo();
        //    if (foundAudio != null)
        //    {
        //        info.Artist = foundAudio.Artist;
        //        info.Genre = foundAudio.Genre.ToString();
        //        info.Lyrics = GetSongLyrics(foundAudio.LyricsId);
        //        info.SongPath = foundAudio.Url.AbsoluteUri;
        //        info.Title = foundAudio.Title;
        //        GetLyricsFromAllAudios(audios, info);
        //        return info;
        //    }
        //    return null;
        //}
        public List<SongInfo> GetSongs(bool findLyrics)
        {
            List<SongInfo> songs = new List<SongInfo>();
            if (_vkApi == null)
            {
                return songs;
            }

            var userId = _vkApi.UserId;

            var lyricGetter = new VkAudioService(_vkApi);
            if (userId != null)
            {
                var vkSongs = _vkApi.Audio.Get((long)userId);
                //vkSongs = vkSongs.Take(5);
                foreach (var vkSong in vkSongs)
                {
                    var songInfo = new SongInfo
                    {
                        Artist = vkSong.Artist,
                        Genre = vkSong.Genre.ToString(),
                        SongId = Guid.NewGuid().ToString(),
                        SongPath = vkSong.Url.AbsoluteUri,

                        Title = vkSong.Title,
                    };
                    songInfo.Duration = TimeSpan.FromSeconds(vkSong.Duration);
                    if (findLyrics)
                    {
                        songInfo.Lyrics = lyricGetter.GetSongLyrics(vkSong.LyricsId);
                    }

                    songs.Add(songInfo);
                }
            }
            return songs;
        }