Пример #1
0
        private async Task AddDownload(string link)
        {
            try
            {
                EnableControls(false);

                //Validate pasted URI
                if (link.Length > 0 && !link.ToLower().StartsWith("spotify:") && !link.Contains("play.spotify.com"))
                {
                    MessageBox.Show(lang.GetString("download/invalid_uri"));
                    textBoxLink.Clear();
                    return;
                }
                else if (link.Contains("play.spotify.com"))
                {
                    link = BuildSpotifyURI(link);
                }

                if (link.ToLower().Contains("playlist"))
                {
                    var playlist = await downloader.FetchPlaylist(link);

                    for (int i = 0; i < playlist.NumTracks(); i++)
                    {
                        listBoxTracks.Items.Add(new TrackItem(playlist.Track(i)));
                    }
                    textBoxLink.Clear();
                }
                else if (link.ToLower().Contains("track"))
                {
                    var track = await downloader.FetchTrack(link);

                    listBoxTracks.Items.Add(new TrackItem(track));
                    textBoxLink.Clear();
                }
                else if (link.ToLower().Contains("album"))
                {
                    var album = await downloader.FetchAlbum(link);

                    for (int i = 0; i < album.NumTracks(); i++)
                    {
                        listBoxTracks.Items.Add(new TrackItem(album.Track(i)));
                    }
                    textBoxLink.Clear();
                }
            }
            catch (NullReferenceException)
            {
            }
            finally
            {
                EnableControls(true);
            }
        }
Пример #2
0
        private async Task FetchSongsFromUrl(string text)
        {
            string[] urls = text.Split('\n');

            foreach (string url in urls)
            {
                var link = SpotifyDownloader.SpotifyUrlToUri(url);

                try
                {
                    EnableControls(false);

                    //Validate pasted URI
                    //                if((link.Length > 0 && !link.ToLower().StartsWith("spotify:")))
                    //                {
                    //                    MessageBox.Show(lang.GetString("download/invalid_uri"));
                    //                    textBoxLink.Clear();
                    //                    SetStatusStripLabelText(StatusTextInvalidLink);
                    //                    return;
                    //                }

                    SetStatusStripLabelText(StatusTextReady);

                    if (link.ToLower().Contains("playlist"))
                    {
                        var playlist = await downloader.FetchPlaylist(link);

                        for (int i = 0; i < playlist.NumTracks(); i++)
                        {
                            listBoxTracks.Items.Add(new TrackItem(playlist.Track(i)));
                        }
                        int a = playlist.NumTracks();
                        textBoxLink.Clear();
                    }
                    else if (link.ToLower().Contains("track"))
                    {
                        var track = await downloader.FetchTrack(link);

                        listBoxTracks.Items.Add(new TrackItem(track));
                        textBoxLink.Clear();
                    }
                    else if (link.ToLower().Contains("album"))
                    {
                        var album = await downloader.FetchAlbum(link);

                        for (int i = 0; i < album.NumTracks(); i++)
                        {
                            listBoxTracks.Items.Add(new TrackItem(album.Track(i)));
                        }
                        textBoxLink.Clear();
                    }
                    else if (link.ToLower().Contains("artist"))
                    {
                        var artist = await downloader.FetchArtist(link);

                        for (int i = 0; i < artist.NumAlbums(); i++)
                        {
                            var album = await downloader.FetchAlbum(artist.Album(i));

                            for (int j = 0; j < album.NumTracks(); j++)
                            {
                                listBoxTracks.Items.Add(new TrackItem(album.Track(j)));
                            }
                        }
                        for (int i = 0; i < artist.NumTracks(); i++)
                        {
                            listBoxTracks.Items.Add(new TrackItem(artist.Track(i)));
                        }
                        textBoxLink.Clear();
                    }
                    else
                    {
                        SetStatusStripLabelText(StatusTextInvalidLink);
                    }
                }
                catch (NullReferenceException)
                {
                    SetStatusStripLabelText(StatusTextInvalidLink);
                }
                finally
                {
                    EnableControls(true);
                }
            }
        }
Пример #3
0
        private async void textBoxLink_TextChanged(object sender, EventArgs e)
        {
            var link = string.Empty;

            if (textBoxLink.Text.Contains("spotify.com"))
            {
                link = ConvertToURI(textBoxLink.Text);
            }
            else
            {
                link = textBoxLink.Text;
            }

            try
            {
                EnableControls(false);

                //Validate pasted URI
                if (link.Length > 0 && !link.ToLower().StartsWith("spotify:"))
                {
                    MessageBox.Show(lang.GetString("download/invalid_uri"));
                    textBoxLink.Clear();
                    return;
                }

                if (link.ToLower().Contains("playlist"))
                {
                    var playlist = await downloader.FetchPlaylist(textBoxLink.Text);

                    for (int i = 0; i < playlist.NumTracks(); i++)
                    {
                        listBoxTracks.Items.Add(new TrackItem(playlist.Track(i)));
                    }
                    textBoxLink.Clear();
                }
                else if (link.ToLower().Contains("track"))
                {
                    var track = await downloader.FetchTrack(textBoxLink.Text);

                    listBoxTracks.Items.Add(new TrackItem(track));
                    textBoxLink.Clear();
                }
                else if (link.ToLower().Contains("album"))
                {
                    var album = await downloader.FetchAlbum(textBoxLink.Text);

                    for (int i = 0; i < album.NumTracks(); i++)
                    {
                        listBoxTracks.Items.Add(new TrackItem(album.Track(i)));
                    }
                    textBoxLink.Clear();
                }
            }
            catch (NullReferenceException)
            {
            }
            finally
            {
                EnableControls(true);
            }
        }