Exemplo n.º 1
0
        //get tracks from vk user
        public override void DownloadTracks(string[] data)
        {
            var userId = data[0];
            var token = data[1];
            Uri uri = new Uri("https://api.vk.com/method/audio.get.xml?owner_id=" + userId + /*"&count=50" + */"&access_token=" + token);

            var x = new XmlDocument();
            x.Load(uri.ToString());
            var audioElements = x.GetElementsByTagName("response")[0];

            tracks.Clear();

            int length = audioElements.ChildNodes.Count;

            for (int i = 1; i < length; i++)
            {
                var audio = new AudioVK(audioElements.ChildNodes[i]);
                tracks.Add(audio);
            }
        }
Exemplo n.º 2
0
        private ListBoxItem CreateListItem(ListBox listbx, AudioVK elm, int count, bool allowAdding, bool allowDeleting, bool isMyAudioTab)
        {
            ListBoxItem lstItem = new ListBoxItem();
            lstItem.Height = 30;
            lstItem.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            lstItem.Margin = new Thickness(0, 0, 0, 3);
            lstItem.Style = this.FindResource("lstStyle") as Style;

            #region creating grid for listboxItem

            bool isAllowAddCurrTrack = allowAdding;
            bool isAllowDeletingCurrTrack = allowDeleting;
            if (allowAdding)
                isAllowAddCurrTrack = !elm.IsAdded;

            int sumSize = 0;
            sumSize += 40;
            if (isAllowAddCurrTrack)
                sumSize += 30;
            sumSize += 70;
            if (isAllowDeletingCurrTrack)
                sumSize += 80;
            if (isMyAudioTab)
                sumSize += 80;


            Grid grid = new Grid();
            grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(listbx.Width - sumSize - 30) });
            grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(40) });


            if (isAllowDeletingCurrTrack)
                grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(40) });

            if (isAllowAddCurrTrack)
                grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(30) });

            if (isMyAudioTab)
                grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(80) });

            grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(80) });

            if (isAllowDeletingCurrTrack)
                grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(40) });
            #endregion


            int colemn = 0;

            #region add elements in grid for listboxitem
            System.Windows.Controls.Label lbl = new System.Windows.Controls.Label();
            lbl.Content = (count>=0 ? count + ". " : "") + elm.artist + " - " + elm.title;
            Grid.SetColumn(lbl, colemn);
            colemn++;
            grid.Children.Add(lbl);

            lbl = new System.Windows.Controls.Label();
            lbl.Content = elm.DurationString;
            Grid.SetColumn(lbl, colemn);
            colemn++;
            grid.Children.Add(lbl);

            Button btn;


            if (isAllowDeletingCurrTrack)
            {
                Button editBtn = new Button();
                editBtn.Style = this.FindResource("roundedButton") as Style;

                Image img3 = new Image();
                img3.Height = 20;
                img3.Width = 40;
                bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.UriSource = new Uri("/images/Edit-icon.png", UriKind.Relative);
                bitmap.EndInit();
                img3.Source = bitmap;

                editBtn.Content = img3;

                editBtn.Click += (object send, RoutedEventArgs ee) =>
                {
                    editedTrack = elm;
                    trackNameTextBox.Text = elm.title;
                    artistNameTextBox.Text = elm.artist;
                    //popupTrack.Visibility = System.Windows.Visibility.Visible;
                    popupTrack.IsOpen = true;

                };

                Grid.SetColumn(editBtn, colemn);
                colemn++;
                grid.Children.Add(editBtn);
            }

            #region add button
            if (isAllowAddCurrTrack)
            {
                Button addBtn = new Button();
                addBtn.Style = this.FindResource("roundedButton") as Style;
                addBtn.Content = "+";

                addBtn.Click += (object send, RoutedEventArgs ee) =>
                {
                    Button currBtn = ((Button)send);
                    currBtn.Visibility = System.Windows.Visibility.Collapsed;
                    if (!elm.Add(sett.VKToken))
                    {
                        MessageBox.Show("Виникла помилка з додаваням треку");
                        currBtn.Visibility = System.Windows.Visibility.Visible;
                    }
                    ShowNotiff("Аудіозапис додано");
                    //add song to my list
                    playlistAll.AddToStart(elm);
                    var listItem = CreateListItem(listBox, elm, -1, true, true, true);
                    listBox.Items.Insert(0,listItem);
                };

                Grid.SetColumn(addBtn, colemn);
                colemn++;
                grid.Children.Add(addBtn);
            }
            #endregion

            #region album combobox
            if (isMyAudioTab)
            {
                ComboBox cbx = new ComboBox();
                cbx.Foreground = Brushes.White;
                cbx.Cursor = Cursors.Hand;
                cbx.IsEditable = false;
                cbx.IsTextSearchEnabled = false;
                cbx.IsTextSearchCaseSensitive = false;
                cbx.StaysOpenOnEdit = false;
                //cbx.IsReadOnly = true;
                var albms = albums.GetAlbums();
                cbx.Items.Add("Без альбому");
                cbx.ToolTip = "Без альбому";
                foreach (var alb in albms)
                    cbx.Items.Add(alb);
                cbx.SelectedIndex = 0;
                if (elm.album_id.Trim() != "")
                {
                    cbx.SelectedIndex = albums.GetIndexById(elm.album_id) + 1;
                }

                cbx.SelectionChanged += (object sender, SelectionChangedEventArgs e) =>
                {
                    string selected = cbx.SelectedItem.ToString();
                    ((ComboBox)sender).ToolTip = selected;
                    if (selected != "Без альбому")
                    {
                        elm.ChangeAlbum(id: albums.GetIdByName(selected), token: sett.VKToken);
                    }
                    else
                        elm.ChangeAlbum(id: "", token: sett.VKToken);
                };


                Grid.SetColumn(cbx, colemn);
                colemn++;
                grid.Children.Add(cbx);

            }
            #endregion

            btn = new Button();
            btn.Style = this.FindResource("roundedButton") as Style;
            btn.Content = "Скачати";

            btn.Click += (object send, RoutedEventArgs ee) =>
            {
                ((Button)send).IsEnabled = false;
                DownloadFile(elm, (Button)send);
            };

            Grid.SetColumn(btn, colemn);
            colemn++;
            grid.Children.Add(btn);



            #region add deleting button
            if (isAllowDeletingCurrTrack)
            {
                btn = new Button();
                btn.Style = this.FindResource("roundedButton") as Style;
                btn.Content = "X";

                btn.Click += (object send, RoutedEventArgs ee) =>
                {
                    DeleteTrack(listBox.Items.IndexOf(lstItem));
                };

                Grid.SetColumn(btn, colemn);
                colemn++;
                grid.Children.Add(btn);
            }
            #endregion
            #endregion

            lstItem.Content = grid;
            var cntMenu = new ContextMenu();
            MenuItem mi;
            if (elm.HasLyrics)
            {
                mi = new MenuItem();
                mi.Header = "Показати текст";
                mi.Click += new RoutedEventHandler((sender, e) =>
                {
                    Thread t = new Thread(() => MessageBox.Show(elm.GetLyrics(sett.VKToken), elm.Name + " lirycs"));
                    t.Start();
                });
                cntMenu.Items.Add(mi);
            }

            mi = new MenuItem();
            mi.Header = "Знайти інші треки " + elm.artist.Substring(0, elm.artist.Length > 20 ? 20 : elm.artist.Length);
            mi.Click += new RoutedEventHandler((sender, e) =>
            {
                searchQueryTextBox.Text = elm.artist;
                searchTab.Focus();
                SearchQueryButton_Click(null, null);
            });
            cntMenu.Items.Add(mi);

            mi = new MenuItem();
            mi.Header = "Рекомендовані треки " + elm.artist.Substring(0, elm.artist.Length > 20 ? 20 : elm.artist.Length);
            mi.Click += new RoutedEventHandler(async (sender, e) =>
            {
                reccomedTab.Focus();
                listRecommedTracksBox.SelectedIndex = -1;
                listRecommedTracksBox.SelectedIndex = 0;
                listRecommedTracksBox.SelectedIndex = -1;
                await Task.Factory.StartNew(() => recommendations.LoadReccomendationsByAudio(elm));
                if (recommendations.Playlist.Count() == 0)
                {
                    MessageBox.Show("Немає рекомендації до цього треку.");
                    recommendations.LoadReccomendations();
                }
                else
                {
                    recommedCountLabel.Content = recommendations.GetSearchedCount() + " треків за рекомендацію \"" + recommendations.Query + "\"";
                    FillListBox(recommendations.Playlist, listRecommedTracksBox, true, false, false);
                }
            });

            cntMenu.Items.Add(mi);
            lstItem.ContextMenu = cntMenu;

            if (listbx == listBox)
                lstItem.MouseDoubleClick += lstItem_MouseDoubleClick;
            if (listbx == listAlbumBox)
                lstItem.MouseDoubleClick += lstItemAlbum_MouseDoubleClick;
            if (listbx == listUserTracksBox)
                lstItem.MouseDoubleClick += lstItemUser_MouseDoubleClick;
            if (listbx == listSearchedTracksBox)
                lstItem.MouseDoubleClick += lstItemSearch_MouseDoubleClick;
            if (listbx == listRecommedTracksBox)
                lstItem.MouseDoubleClick += lstItemRecommed_MouseDoubleClick;
            //lstItem.MouseEnter += lstItem_MouseEnter;

            return lstItem;

        }
Exemplo n.º 3
0
        private void DownloadFile(AudioVK track, Button button)
        {
            string filepath = Directory.GetCurrentDirectory() + "\\" + player.FOLDER + "\\" + track.aid + ".mp3";
            string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile) + "\\Downloads\\Zeus\\";
            string name = track.artist + " - " + track.title;
            if (File.Exists(filepath))
                if (player.GetDuration(filepath) == track.duration)
                {
                    File.Copy(filepath, path + name + ".mp3", true);
                    MessageBox.Show(name + " завантажена до папки Downloads/Zeus");
                    button.IsEnabled = true;
                    return;
                }

            new Thread(() =>
                {
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    WebClient wb = new WebClient();
                    name.Replace("\"", "");
                    wb.DownloadFile(new Uri(track.GetLocation), path + name + ".mp3");
                    wb.Dispose();
                    this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new System.Windows.Threading.DispatcherOperationCallback(delegate
                    {
                        MessageBox.Show(name + " завантажена до папки Downloads/Zeus");
                        button.IsEnabled = true;
                        return null;
                    }), null);
                }).Start();
        }
Exemplo n.º 4
0
        //attach from internet
        private void AttachUrlSong(AudioVK track,bool needCache)
        {
            if (track != null)
            {
                isLocal = false;
                currTrack = track;
                _myDownloadProc = new DOWNLOADPROC(MyDownload);
                //destroy current playing stream
                Bass.BASS_Free();
                Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, System.IntPtr.Zero);
                if (needCache)
                stream = Bass.BASS_StreamCreateURL(track.GetLocation, 0, BASSFlag.BASS_DEFAULT, _myDownloadProc, IntPtr.Zero);
                else
                    stream = Bass.BASS_StreamCreateURL(track.GetLocation, 0, BASSFlag.BASS_DEFAULT, null, IntPtr.Zero);

                // pre-buffer
                Bass.BASS_ChannelUpdate(stream, 0);

                UpdateStatus(PLAYER_STATUS.PLAYER_STATUS_READY_STOPPED);
            }
        }
Exemplo n.º 5
0
 public void AttachTrack(AudioVK track,bool needCache)
 {
     Bass.BASS_Free();
     if (needCache)
     {
         Settings.CheckCurrFolder(FOLDER_PATH);
         if (_fs != null)
         {
             _fs.Close();
             _fs = null;
         }
         string filepath = Directory.GetCurrentDirectory() + "\\" + FOLDER_PATH + "\\" + track.aid + ".mp3";
         if (File.Exists(filepath))
             if (int.Parse(GetDuration(filepath)) >= (int.Parse(track.duration) - 1) && int.Parse(GetDuration(filepath)) <= (int.Parse(track.duration) + 1) && CheckSize(track.GetLocation, filepath))
                 AttachSong(filepath);
             else
                 AttachUrlSong(track,needCache);
         else
             AttachUrlSong(track,needCache);
     }
     else
         AttachUrlSong(track,needCache);
 }