Beispiel #1
0
 private void EditBut_Click(object sender, RoutedEventArgs e)
 {
     UserGetSet.input();
     if (EditBut.Content.ToString() == "Edit Key")
     {
         ApiKeyTextBox.IsReadOnly = false;
         EditBut.Content          = "Save";
     }
     else if (EditBut.Content.ToString() == "Save")
     {
         try
         {
             if (UserGetSet.ApiKey == ApiKeyTextBox.Text)
             {
                 MessageBox.Show("Api keys are the same");
                 return;
             }
             string    url      = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=PLYQ21GguN2ssJfHlwxZxzepHaiu3t798Y&key=" + ApiKeyTextBox.Text;
             WebClient wc       = new WebClient();
             string    urlData  = wc.DownloadString(url);
             Database  database = new Database();
             database.UpdateApiKey(ApiKeyTextBox.Text);
             EditBut.Content          = "Edit Key";
             ApiKeyTextBox.IsReadOnly = true;
             MessageBox.Show("Api key has been changed");
         }
         catch
         {
             MessageBox.Show("Api key is invalid");
         }
     }
 }
Beispiel #2
0
        public List <string> getData(string pageToken, List <string> videoId, string urll)
        {
            string[] playlistId = urll.Split('=');
            UserGetSet.input();
            string    url = "https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults=50&pageToken=" + pageToken + "&playlistId=" + playlistId[1] + "&key=" + UserGetSet.apiKey + "";
            WebClient wc  = new WebClient();
            //Calls google ur to get JSON file with an address
            string urlData = wc.DownloadString(url);

            string[] data = urlData.Split('"');
            for (int i = 0; i < data.Length; i++)
            {
                if (data[i].Contains("videoId"))
                {
                    videoId.Add(data[i + 2]);
                }
            }
            for (int i = 0; i < data.Length; i++)
            {
                if (data[i].Contains("nextPageToken"))
                {
                    string   nextPage      = data[i + 2];
                    string[] dataArray     = nextPage.Split('"');
                    string   nextPageToken = dataArray[0];
                    videoId = getData(nextPageToken, videoId, urll);
                }
            }
            return(videoId);
        }
Beispiel #3
0
        private void AddSong_Click(object sender, EventArgs e)
        {
            string playlistName = Microsoft.VisualBasic.Interaction.InputBox("Please type in your new song link", "Add song", "");

            string[] array = playlistName.Split('?');
            if (playlistName == "")
            {
            }
            else if (array[0] != "https://www.youtube.com/watch" && array[0] != "https://www.youtube.com/playlist")
            {
                MessageBox.Show("We only support Youtube.com links");
            }
            else if (array[0] == "https://www.youtube.com/watch")
            {
                //fix adding
                AddInfo addInfo = new AddInfo();
                addInfo.addSong(playlistName);
                MessageBox.Show("Your song has been added");
                updateList();
            }
            else if (array[0] == "https://www.youtube.com/playlist")
            {
                DialogResult dr = MessageBox.Show("This is a song play list do you want to add it ?", "Add song", MessageBoxButtons.YesNo);
                if (dr == DialogResult.Yes)
                {
                    AddInfo addInfo = new AddInfo();
                    UserGetSet.input();
                    addInfo.addSongs(UserGetSet.selectedPlaylis, playlistName, "No");
                    MessageBox.Show("Your songs have been added");
                    updateList();
                }
            }
        }
Beispiel #4
0
        public void DeleteSong(string songName)
        {
            sqlite_conn.Open();
            SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();

            UserGetSet.input();
            sqlite_cmd.CommandText = "DELETE FROM Titles WHERE VideoTitle = '" + songName + "' AND PlaylistID = '" + UserGetSet.selectedPlaylis + "'";
            sqlite_cmd.ExecuteNonQuery();
            sqlite_conn.Close();
        }
Beispiel #5
0
 public PlaylistDetaislWindow()
 {
     InitializeComponent();
     songDownloads = new SongDownloads(SongProgressBar);
     _database     = new Database();
     UserGetSet.input();
     PlaylistNameLabel.Text = $"Playlist {UserGetSet.SelectedPlaylistName} ";
     UpdateInterface();
     SongGrid.ItemsSource = Item;
 }
Beispiel #6
0
        public void updateOneStatus(string songName)
        {
            sqlite_conn.Open();
            SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();

            UserGetSet.input();
            sqlite_cmd.CommandText = "Update Titles Set DownloadedVideo = 'Yes' Where VideoTitle = '" + songName + "' AND PlaylistID = '" + UserGetSet.selectedPlaylis + "'; ";
            sqlite_cmd.ExecuteNonQuery();
            sqlite_conn.Close();
        }
Beispiel #7
0
        public void videoTitlesFromYoutubeDataApi_goodData()
        {
            GetTitles getTitles = new GetTitles();

            UserGetSet.input();
            UserGetSet.apiKey = "AIzaSyCBYx5nDeHanit6rpvzhZLSDy52diu7ecI";

            List <string> list = getTitles.getTitles("https://www.youtube.com/playlist?list=PLYQ21GguN2ssJfHlwxZxzepHaiu3t798Y");

            CollectionAssert.AreEqual(list, getTitles.getTitles("https://www.youtube.com/playlist?list=PLYQ21GguN2ssJfHlwxZxzepHaiu3t798Y"));
        }
        public void getAllVideoId_goodData()
        {
            LinksFromPlaylist linksFromPlaylist = new LinksFromPlaylist();

            UserGetSet.input();
            UserGetSet.apiKey = "AIzaSyCBYx5nDeHanit6rpvzhZLSDy52diu7ecI";

            List <string> list = linksFromPlaylist.getLinks("https://www.youtube.com/playlist?list=PLYQ21GguN2ssJfHlwxZxzepHaiu3t798Y");

            CollectionAssert.AreEqual(list, linksFromPlaylist.getLinks("https://www.youtube.com/playlist?list=PLYQ21GguN2ssJfHlwxZxzepHaiu3t798Y"));
        }
Beispiel #9
0
        public void RenamePlaylist(string newPlaylistName)
        {
            sqlite_conn.Open();
            UserGetSet.input();
            SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();

            sqlite_cmd.CommandText = "UPDATE Playlist Set PlaylistName = ? Where Id = ?";
            sqlite_cmd.Parameters.AddWithValue("PlaylistName", newPlaylistName);
            sqlite_cmd.Parameters.AddWithValue("Id", UserGetSet.SelectedPlaylistId);
            sqlite_cmd.ExecuteNonQuery();
            sqlite_conn.Close();
        }
Beispiel #10
0
 public void UpdateDownloadStatus(List <JsonList> songList)
 {
     sqlite_conn.Open();
     UserGetSet.input();
     foreach (var song in songList)
     {
         SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();
         sqlite_cmd.CommandText = $"UPDATE Songs Set Downloaded = 'Yes'  Where PlaylistId = '{UserGetSet.SelectedPlaylistId}' AND SongId = '{song.VideoId}'";
         sqlite_cmd.ExecuteNonQuery();
     }
     sqlite_conn.Close();
 }
Beispiel #11
0
        public void addNewPlaylist(string playlistName, string url, string yesNo)
        {
            AddInfo addInfo = new AddInfo();

            addInfo.addSongs(playlistName, url, yesNo);
            sqlite_conn.Open();
            SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();

            UserGetSet.input();
            sqlite_cmd.CommandText = "INSERT INTO Playlist (UserId, Name, PlaylistUrl) VALUES('" + UserGetSet.username + "' ,'" + playlistName + "' ,'" + url + "'); ";
            sqlite_cmd.ExecuteNonQuery();
            sqlite_conn.Close();
        }
        private void listView_Click(object sender, RoutedEventArgs e)
        {
            var item          = (sender as ListView).SelectedItem;
            var selectedIndex = PlaylistListView.SelectedIndex;

            UserGetSet.input();
            UserGetSet.SelectedPlaylistName = item.ToString();
            UserGetSet.SelectedPlaylistId   = playlistLists[selectedIndex].Id;
            this.Hide();
            PlaylistDetaislWindow playlist = new PlaylistDetaislWindow();

            playlist.Show();
        }
Beispiel #13
0
 public void DeleteSongs(List <JsonList> deleteSongs)
 {
     sqlite_conn.Open();
     UserGetSet.input();
     foreach (var item in deleteSongs)
     {
         SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();
         sqlite_cmd.CommandText = "DELETE FROM Songs WHERE SongId = ? AND PlaylistId = ?";
         sqlite_cmd.Parameters.AddWithValue("SongId", item.VideoId);
         sqlite_cmd.Parameters.AddWithValue("PlaylistId", UserGetSet.SelectedPlaylistId);
         sqlite_cmd.ExecuteNonQuery();
     }
     sqlite_conn.Close();
 }
Beispiel #14
0
        public async void addSong(string url)
        {
            var youtube = new YoutubeClient();
            var vid     = await youtube.Videos.GetAsync(url);

            string[] videoId = vid.Url.Split('=');
            sqlite_conn.Open();
            SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();

            UserGetSet.input();
            sqlite_cmd.CommandText = "INSERT INTO Titles (PlaylistID, VideoTitle, VideoId, DownloadedVideo) VALUES('" + UserGetSet.selectedPlaylis + "' ,'" + vid.Title.Replace("\"", "").Replace("'", "") + "' ,'" + videoId[1] + "', 'No'); ";
            sqlite_cmd.ExecuteNonQuery();
            sqlite_conn.Close();
        }
Beispiel #15
0
        public void AddSong(string songId, string songName)
        {
            sqlite_conn.Open();
            SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();

            UserGetSet.input();
            sqlite_cmd.CommandText = $"INSERT INTO Songs (SongId, SongName, Downloaded, PlaylistId) Values (?,?,?,?)";
            sqlite_cmd.Parameters.AddWithValue("SongId", songId);
            sqlite_cmd.Parameters.AddWithValue("SongName", songName);
            sqlite_cmd.Parameters.AddWithValue("Downloaded", "No");
            sqlite_cmd.Parameters.AddWithValue("PlaylistId", UserGetSet.SelectedPlaylistId);
            sqlite_cmd.ExecuteNonQuery();
            sqlite_conn.Close();
        }
Beispiel #16
0
        public void GetApiKey()
        {
            sqlite_conn.Open();
            SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();

            sqlite_cmd.CommandText = "SELECT ApiKey FROM Details";
            SQLiteDataReader sqlite_datareader = sqlite_cmd.ExecuteReader();

            UserGetSet.input();
            while (sqlite_datareader.Read())
            {
                UserGetSet.ApiKey = sqlite_datareader.GetString(0);
            }
            sqlite_conn.Close();
        }
Beispiel #17
0
        public YourTube()
        {
            InitializeComponent();
            songPlaylistDownload = new SongPlaylistDownload(ProgressBar);
            songDownload = new SongDownload(ProgressBar);
            oneSongDownload = new OneSongDownload(ProgressBar);
            videoDownload = new VideoDownload(ProgressBarVideo);
            videoPlaylistDownload = new VideoPlaylistDownload(ProgressBarVideo);
            updateList();
            UserGetSet.input();
            labelUsername.Text = UserGetSet.username;
            labelApiKey.Text = UserGetSet.apiKey;
            labelTotalPlaylist.Text = UserGetSet.playlistCount;
            GetInfo getInfo = new GetInfo();

        }
Beispiel #18
0
        public async void addUpdatedSongs(List <string> videoId, string rrr)
        {
            sqlite_conn.Open();
            foreach (string id in videoId)
            {
                var    youtube = new YoutubeClient();
                string url     = "https://www.youtube.com/watch?v=" + id;
                var    vid     = await youtube.Videos.GetAsync(url);

                SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();
                UserGetSet.input();
                sqlite_cmd.CommandText = "INSERT INTO Titles (PlaylistID, VideoTitle, VideoId, DownloadedVideo, VideoUrl) VALUES('" + UserGetSet.selectedPlaylis + "' ,'" + vid.Title.Replace("\"", "").Replace("'", "") + "' ,'" + id + "', 'No', '" + rrr + "'); ";
                sqlite_cmd.ExecuteNonQuery();
            }
            sqlite_conn.Close();
        }
Beispiel #19
0
        public string oneVideoId(string videoName)
        {
            sqlite_conn.Open();
            SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();

            UserGetSet.input();
            sqlite_cmd.CommandText = "Select VideoId from Titles Where VideoTitle = '" + videoName + "' AND PlaylistID = '" + UserGetSet.selectedPlaylis + "'";
            SQLiteDataReader sqlite_datareader = sqlite_cmd.ExecuteReader();
            string           myreader          = null;

            while (sqlite_datareader.Read())
            {
                myreader = sqlite_datareader.GetString(0);
            }
            sqlite_conn.Close();
            return(myreader);
        }
Beispiel #20
0
        private void InspectPlaylistBu_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select a playlist");
            }
            else
            {
                string selectedPlaylistName = listView1.Items[listView1.SelectedIndices[0]].Text;
                UserGetSet.input();
                UserGetSet.selectedPlaylis = selectedPlaylistName;
                this.Hide();
                InspectPlaylist inspectPlaylist = new InspectPlaylist();
                inspectPlaylist.Show();
            }

        }
Beispiel #21
0
 public void updateList()
 {
     listView1.Items.Clear();
     GetInfo getInfo = new GetInfo();
     List<string> playlistData = getInfo.getPlaylists();
     List<string> count = new List<string>();
     UserGetSet.input();
     UserGetSet.playlistCount = playlistData.Count.ToString();
     foreach (string playlistName in playlistData)
     {
         count.Add(getInfo.getSongCount(playlistName));
     }
     for (int i = 0; i < playlistData.Count; i++)
     {
         listView1.Items.Add(playlistData[i]);
         listView1.Items[i].SubItems.Add(count[i]);
     }
 }
Beispiel #22
0
        public string getSongCount(string playlistName)
        {
            sqlite_conn.Open();
            SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();

            UserGetSet.input();
            sqlite_cmd.CommandText = "Select PlaylistID from Titles Where PlaylistID='" + playlistName + "'";
            SQLiteDataReader sqlite_datareader = sqlite_cmd.ExecuteReader();
            List <string>    count             = new List <string>();

            while (sqlite_datareader.Read())
            {
                string myreader = sqlite_datareader.GetString(0);
                count.Add(myreader);
            }
            sqlite_conn.Close();
            return(count.Count.ToString());
        }
Beispiel #23
0
        public List <string> GetPlaylistId()
        {
            sqlite_conn.Open();
            SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();

            sqlite_cmd.CommandText = "SELECT PlaylistCode FROM PlaylistDetails WHERE PlaylistId = ?";
            UserGetSet.input();
            sqlite_cmd.Parameters.AddWithValue("PlaylistId", UserGetSet.SelectedPlaylistId);
            SQLiteDataReader sqlite_datareader = sqlite_cmd.ExecuteReader();
            List <string>    list = new List <string>();

            while (sqlite_datareader.Read())
            {
                list.Add(sqlite_datareader.GetString(0));
            }
            sqlite_conn.Close();
            return(list);
        }
Beispiel #24
0
        public List <string> playlistUrls()
        {
            sqlite_conn.Open();
            SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();

            UserGetSet.input();
            sqlite_cmd.CommandText = "Select PlaylistID from PlaylistInfo Where PlaylistName = '" + UserGetSet.selectedPlaylis + "'";
            SQLiteDataReader sqlite_datareader = sqlite_cmd.ExecuteReader();
            List <string>    playlistUrls      = new List <string>();

            while (sqlite_datareader.Read())
            {
                string myreader = sqlite_datareader.GetString(0);
                playlistUrls.Add(myreader);
            }
            sqlite_conn.Close();
            return(playlistUrls);
        }
Beispiel #25
0
        public List <string> getVideoIdUpdate(string url)
        {
            sqlite_conn.Open();
            SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();

            UserGetSet.input();
            sqlite_cmd.CommandText = "Select VideoId from Titles Where VideoUrl='" + url + "' And PlaylistID = '" + UserGetSet.selectedPlaylis + "'";
            SQLiteDataReader sqlite_datareader = sqlite_cmd.ExecuteReader();
            List <string>    videoId           = new List <string>();

            while (sqlite_datareader.Read())
            {
                string myreader = sqlite_datareader.GetString(0);
                videoId.Add(myreader);
            }
            sqlite_conn.Close();
            return(videoId);
        }
Beispiel #26
0
        public List <string> getPlaylists()
        {
            sqlite_conn.Open();
            SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();

            UserGetSet.input();
            sqlite_cmd.CommandText = "Select Name from Playlist WHERE UserId = '" + UserGetSet.username + "'";
            SQLiteDataReader sqlite_datareader = sqlite_cmd.ExecuteReader();
            List <string>    playlistData      = new List <string>();

            while (sqlite_datareader.Read())
            {
                string name = sqlite_datareader.GetString(0);
                playlistData.Add(name);
            }
            sqlite_conn.Close();
            return(playlistData);
        }
Beispiel #27
0
        private void DownloadNew_Click(object sender, EventArgs e)
        {
            GetInfo       getInfo         = new GetInfo();
            List <string> downloadedYesNo = getInfo.getData();
            bool          noNew           = false;

            for (int i = 0; i < downloadedYesNo.Count; i++)
            {
                string word = downloadedYesNo[i];
                if (word == "No")
                {
                    noNew = true;
                    break;
                }
            }
            if (noNew == true)
            {
                string directory = Microsoft.VisualBasic.Interaction.InputBox("Please type in where you want to save the playlist", "Save", "");
                if (directory == "")
                {
                }
                else if (Directory.Exists(directory))
                {
                    List <string>   newVideoId   = getInfo.getNewSongVideoId();
                    OneSongDownload songDownload = new OneSongDownload(ProgressBar);
                    toLab.Text           = newVideoId.Count.ToString();
                    progressBar1.Maximum = newVideoId.Count;
                    songDownload.DownloadSong(newVideoId, directory);
                    UpdateInfo updateInfo = new UpdateInfo();
                    UserGetSet.input();
                    updateInfo.updateStatus(UserGetSet.selectedPlaylis);
                }
                else
                {
                    MessageBox.Show("Save location is invalid");
                }
            }
            else
            {
                MessageBox.Show("There are no new songs in playlist, try updating it");
            }
        }
Beispiel #28
0
        public List <string> getData()
        {
            sqlite_conn.Open();
            SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();

            UserGetSet.input();
            sqlite_cmd.CommandText = "Select VideoTitle, DownloadedVideo from Titles WHERE PlaylistID = '" + UserGetSet.selectedPlaylis + "'";
            SQLiteDataReader sqlite_datareader = sqlite_cmd.ExecuteReader();
            List <string>    playlistData      = new List <string>();

            while (sqlite_datareader.Read())
            {
                string title      = sqlite_datareader.GetString(0);
                string downloaded = sqlite_datareader.GetString(1);
                playlistData.Add(title);
                playlistData.Add(downloaded);
            }
            sqlite_conn.Close();
            return(playlistData);
        }
        public int checkUserCredentials(string username, string password)
        {
            SQLiteConnection sqlite_conn = new SQLiteConnection("Data Source=YourTubeDB.db; Version = 3; New = True; Compress = True; ");

            sqlite_conn.Open();
            SQLiteCommand sqlite_cmd = sqlite_conn.CreateCommand();

            sqlite_cmd.CommandText = "Select Username, Password, ApiKey from User where Username ='******'";
            SQLiteDataReader sqlite_datareader = sqlite_cmd.ExecuteReader();
            string           myreader          = null;
            string           myreaderr         = null;
            string           myreaderrr        = null;

            while (sqlite_datareader.Read())
            {
                myreader   = sqlite_datareader.GetString(0);
                myreaderr  = sqlite_datareader.GetString(1);
                myreaderrr = sqlite_datareader.GetString(2);
            }
            if (myreader == username)
            {
                if (myreaderr == password)
                {
                    sqlite_conn.Close();
                    UserGetSet.input();
                    UserGetSet.username = myreader;
                    UserGetSet.password = myreaderr;
                    UserGetSet.apiKey   = myreaderrr;
                    return(1);
                }
            }
            else
            {
                sqlite_conn.Close();
                return(0);
            }
            sqlite_conn.Close();
            return(6969);
        }
Beispiel #30
0
 public List <string> getLinks(string uri)
 {
     try
     {
         string[] playlistId = uri.Split('=');
         UserGetSet.input();
         string    url = "https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults=50&playlistId=" + playlistId[1] + "&key=" + UserGetSet.apiKey + "";
         WebClient wc  = new WebClient();
         //Calls google ur to get JSON file with an address
         string        urlData     = wc.DownloadString(url);
         List <string> videoIdList = new List <string>();
         string[]      data        = urlData.Split('"');
         for (int i = 0; i < data.Length; i++)
         {
             if (data[i].Contains("videoId"))
             {
                 videoIdList.Add(data[i + 2]);
             }
         }
         for (int i = 0; i < data.Length; i++)
         {
             if (data[i].Contains("nextPageToken"))
             {
                 string           nextPage         = data[i + 2];
                 string[]         dataArray        = nextPage.Split('"');
                 string           nextPageToken    = dataArray[0];
                 DataFromNextPage dataFromNextPage = new DataFromNextPage();
                 videoIdList = dataFromNextPage.getData(nextPageToken, videoIdList, uri);
             }
         }
         return(videoIdList);
     }
     catch (Exception e)
     {
         List <string> error = new List <string>();
         error.Add("error");
         return(error);
     }
 }