예제 #1
0
        internal static VkAudio FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentException("Json can not be null.");
            }

            var result = new VkAudio();

            result.Id       = json["id"].Value <long>();
            result.OwnerId  = json["owner_id"].Value <long>();
            result.Duration = TimeSpan.FromSeconds(json["duration"].Value <double>());
            result.Url      = json["url"].Value <string>();

            try
            {
                result.Title  = WebUtility.HtmlDecode(json["title"].Value <string>()).Trim();
                result.Artist = WebUtility.HtmlDecode(json["artist"].Value <string>()).Trim();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);

                result.Title  = json["title"].Value <string>().Trim();
                result.Artist = json["artist"].Value <string>().Trim();
            }

            if (json["album_id"] != null)
            {
                result.AlbumId = json["album_id"].Value <long>();
            }

            if (json["lyrics_id"] != null)
            {
                result.LyricsId = json["lyrics_id"].Value <long>();
            }

            if (json["genre_id"] != null)
            {
                result.GenreId = json["genre_id"].Value <long>();
            }

            if (json["is_licensed"] != null)
            {
                result.IsLicensed = json["is_licensed"].Value <bool>();
            }

            if (json["access_key"] != null)
            {
                result.AccessKey = json["access_key"].Value <string>();
            }

            if (json["album"] != null)
            {
                result.Album = VkAudioAlbum.FromJson(json["album"]);
            }

            return(result);
        }
예제 #2
0
        public EditAlbumView(VkAudioAlbum album)
        {
            InitializeComponent();

            _album = album;

            TitleTextBox.Text = _album.Title;

            if (album.Id != 0)
                Title.Text = MainResources.EditAlbumTitle;
        }
예제 #3
0
        public static VkAudioAlbum FromJson(JToken json)
        {
            if (json == null)
                throw new ArgumentException("Json can not be null.");

            var result = new VkAudioAlbum();

            result.Id = json["id"].Value<long>();
            result.OwnerId = Math.Abs(json["owner_id"].Value<long>());
            result.Title = WebUtility.HtmlDecode(json["title"].Value<string>());
            return result;
        }
예제 #4
0
        public static VkAudioAlbum FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentException("Json can not be null.");
            }

            var result = new VkAudioAlbum();

            result.Id      = json["id"].Value <long>();
            result.OwnerId = Math.Abs(json["owner_id"].Value <long>());
            result.Title   = WebUtility.HtmlDecode(json["title"].Value <string>());
            return(result);
        }
예제 #5
0
        public static VkAudioAlbum FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentException("Json can not be null.");
            }

            var result = new VkAudioAlbum();

            result.Id        = json["id"].Value <long>();
            result.OwnerId   = Math.Abs(json["owner_id"].Value <long>());
            result.Title     = WebUtility.HtmlDecode(json["title"].Value <string>());
            result.AccessKey = json["access_key"].Value <string>();
            if (json["thumb"] != null)
            {
                result.Thumb = json["thumb"].ToObject <VkThumb>();
            }
            return(result);
        }
        private async Task<VkAudioAlbum> AddNewAlbum(string title)
        {
            try
            {
                var newAlbumId = await ViewModelLocator.Vkontakte.Audio.AddAlbum(title);
                if (newAlbumId != 0)
                {
                    var album = new VkAudioAlbum();
                    album.Id = newAlbumId;
                    album.OwnerId = ViewModelLocator.Vkontakte.AccessToken.UserId;
                    album.Title = title;
                    return album;
                }
            }
            catch (Exception ex)
            {
                LoggingService.Log(ex);
            }

            return null;
        }
예제 #7
0
 private async void AddAlbumToNowPlaying(VkAudioAlbum album)
 {
     try
     {
         var audio = await DataService.GetUserTracks(albumId: album.Id, ownerId: album.OwnerId);
         if (audio.Items != null && audio.Items.Count > 0)
         {
             foreach (var track in audio.Items)
             {
                 AudioService.Playlist.Add(track);
             }
         }
     }
     catch (Exception ex)
     {
         LoggingService.Log(ex);
     }
 }
예제 #8
0
 private async void PlayAlbum(VkAudioAlbum album)
 {
     try
     {
         var audio = await DataService.GetUserTracks(albumId: album.Id, ownerId: album.OwnerId);
         if (audio.Items != null && audio.Items.Count > 0)
         {
             AudioService.Play(audio.Items.First());
             AudioService.SetCurrentPlaylist(audio.Items);
         }
     }
     catch (Exception ex)
     {
         LoggingService.Log(ex);
     }
 }
예제 #9
0
        private async void RemoveAlbum(VkAudioAlbum album)
        {
            try
            {
                var result = await ViewModelLocator.Vkontakte.Audio.DeleteAlbum(album.Id);
                if (result)
                {
                    Albums.Remove(Albums.FirstOrDefault(a => a.Id == album.Id));

                    SelectedAlbum = Albums.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                LoggingService.Log(ex);
            }
        }
예제 #10
0
        private async void EditAlbum(VkAudioAlbum album)
        {
            var flyout = new FlyoutControl();
            flyout.FlyoutContent = new EditAlbumView(album);

            var result = await flyout.ShowAsync();
            if (result != null && (bool)result)
            {
                try
                {
                    if (await ViewModelLocator.Vkontakte.Audio.EditAlbum(album.Id.ToString(), album.Title))
                    {
                        Albums[Albums.IndexOf(album)].Title = album.Title;
                    }
                }
                catch (Exception ex)
                {
                    LoggingService.Log(ex);
                }
            }
        }
예제 #11
0
        private async void AddNewAlbum()
        {
            var album = new VkAudioAlbum() { Title = "New album" };

            var flyout = new FlyoutControl();
            flyout.FlyoutContent = new EditAlbumView(album);
            var result = await flyout.ShowAsync();
            if ((bool)result)
            {
                try
                {
                    var newAlbumId = await ViewModelLocator.Vkontakte.Audio.AddAlbum(album.Title);
                    if (newAlbumId != 0)
                    {
                        album.Id = newAlbumId;
                        album.OwnerId = ViewModelLocator.Vkontakte.AccessToken.UserId;
                        Albums.Insert(5, album);
                    }
                }
                catch (Exception ex)
                {
                    LoggingService.Log(ex);
                }
            }
        }
예제 #12
0
        private async void Save()
        {
            var album = new VkAudioAlbum() { Title = _album.Artist + " - " + _album.Name };

            var flyout = new FlyoutControl();
            flyout.FlyoutContent = new EditAlbumView(album);
            var result = await flyout.ShowAsync();
            if ((bool)result)
            {
                try
                {
                    Debug.WriteLine("Creating new album...");


                    NotificationService.NotifyProgressStarted(MainResources.NotificationSaving);

                    var newAlbumId = await ViewModelLocator.Vkontakte.Audio.AddAlbum(album.Title);

                    Debug.WriteLine("Album created. Id: " + newAlbumId);
                    Debug.WriteLine("Gettings audios...");

                    var progress = new Progress<int>(p => NotificationService.NotifyProgressChanged((int)(p / 2.0f)));

                    var audios = await GetAudioList(progress);

                    Debug.WriteLine("Got audios. Count: " + audios.Count);
                    Debug.WriteLine("Saving audios.");

                    int requestsCount = 0;
                    var audioIds = new List<long>();

                    bool captchaNeeded = false;
                    string captchaImg = string.Empty;
                    string captchaSid = string.Empty;
                    string captchaKey = string.Empty;

                    int progressStep = (int)(100.0f / (audios.Count + 1));

                    for (var i = audios.Count - 1; i > 0; i--)
                    {
                        var vkAudio = audios[i];

                        try
                        {
                            var newAudioId = await ViewModelLocator.Vkontakte.Audio.Add(vkAudio.Id, vkAudio.OwnerId, captchaSid: captchaSid, captchaKey: captchaKey);
                            if (newAudioId != 0)
                            {
                                audioIds.Add(newAudioId);

                                captchaNeeded = false;
                                captchaKey = null;
                                captchaSid = null;
                            }
                        }
                        catch (VkCaptchaNeededException ex)
                        {
                            captchaNeeded = true;
                            captchaImg = ex.CaptchaImg;
                            captchaSid = ex.CaptchaSid;
                        }

                        if (captchaNeeded)
                        {
                            flyout = new FlyoutControl();
                            flyout.FlyoutContent = new CaptchaRequestView(captchaSid, captchaImg);
                            result = await flyout.ShowAsync();
                            if (!string.IsNullOrEmpty((string)result))
                            {
                                captchaKey = (string)result;
                                i = i - 1;
                                continue;
                            }
                            else
                            {
                                NotificationService.NotifyProgressFinished();
                                return;
                            }
                        }

                        NotificationService.NotifyProgressChanged((int)(progressStep / 2.0f));

                        requestsCount++;

                        if (requestsCount >= 2) //не больше 2-х запросов в секунду
                        {
                            requestsCount = 0;
                            await Task.Delay(1000);
                        }
                    }

                    Debug.WriteLine("Audios saved. Moving to album...");

                    if (audioIds.Count > 0)
                    {
                        if (await ViewModelLocator.Vkontakte.Audio.MoveToAlbum(newAlbumId, audioIds))
                        {
                            Debug.WriteLine("Album saved!");

                            NotificationService.NotifyProgressFinished(MainResources.NotificationSaved);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LoggingService.Log(ex);
                }
            }
        }
        private async Task LoadAlbums()
        {
            OnTaskStarted("albums");

            try
            {
                var response = await DataService.GetUserAlbums(0, 0, -SelectedSociety.Id);

                var albums = response.Items;

                _totalAlbumsCount = response.TotalCount;

                if (albums == null)
                    albums = new List<VkAudioAlbum>();

                albums.Insert(0, new VkAudioAlbum() { Id = -1, Title = MainResources.MyMusicAllTracks });
                albums.Insert(1, new VkAudioAlbum() { Id = -101, Title = MainResources.MyMusicWall });
                albums.Insert(2, new VkAudioAlbum() { Id = int.MinValue }); //separator

                Albums = new ObservableCollection<VkAudioAlbum>(albums);

                SelectedAlbum = albums.First();
            }
            catch (Exception ex)
            {
                LoggingService.Log(ex);

                OnTaskError("albums", ErrorResources.LoadAlbumsErrorCommon);
            }

            OnTaskFinished("albums");
        }
예제 #14
0
 private async void CopyAlbum(VkAudioAlbum album)
 {
     try
     {
         await DataService.CopyAlbum(album.Title, album.Id, -album.OwnerId);
     }
     catch (Exception ex)
     {
         LoggingService.Log(ex);
     }
 }