Example #1
0
        private void Btn_Add_Link_Click(object sender, RoutedEventArgs e)
        {
            musikerCurrent = (Musiker)LstVw_Künstler.SelectedItem;
            YoutubeLink youtubeLink = new YoutubeLink(TxtBx_LinkName.Text, TxtBx_Links.Text);

            musikerCurrent.ytLinks.Add(youtubeLink);
            // lst_media.Add(musikerCurrent);

            TxtBx_Links.Text    = "";
            TxtBx_LinkName.Text = "";
            LstVw_Links.Items.Refresh();
        }
        public ActionResult Create(FormCollection formCollection)
        {
            YoutubeLinksLayer layers = new YoutubeLinksLayer();
            YoutubeLink       ll     = new YoutubeLink();

            ll.Link  = formCollection["Link"];
            ll.Title = formCollection["Title"];

            bool v = layers.AddNewLink(ll);

            RedirectToAction("Index", );
            return(View());
        }
        private void loadThumbnails()
        {
            YoutubeLink linkClass1 = new YoutubeLink();

            addressConnection.ConnectionString = "Data Source = LYONSS2N1\\SQLEXPRESS; initial catalog = YoutubeLinksApp; Integrated Security = True;";
            addressConnection.Open();
            SqlCommand    sqlcommand1 = new SqlCommand("SELECT * FROM pagelink", addressConnection);
            List <string> results     = new List <string>();
            bool          loopBool    = false;

            //datareader takes each result from sqlcommand1 and puts it into a single list
            using (SqlDataReader reader = sqlcommand1.ExecuteReader())
            {
                while (reader.Read())
                {
                    string pageLink = (string)reader["pageLink"];
                    results.Add(pageLink);
                }
            }
            //list to put results of each getTopVideos method
            List <string>     videoIDs      = new List <string>();
            List <PictureBox> pictureBoxes  = new List <PictureBox>();
            List <Label>      channelLabels = new List <Label>();
            int y = 10;

            for (int i = 0; i < results.Count; i++)
            {
                String[] linkResults = linkClass1.getTopVideos(results[i]);
                int      x           = 6;


                SqlCommand labelCommand = new SqlCommand("SELECT channelName FROM pagelink WHERE pagelink = @pagelink", addressConnection);
                labelCommand.Parameters.AddWithValue("@pageLink", results[i]);
                string txtChannelLabel = (labelCommand.ExecuteScalar()).ToString();
                channelLabels.Add(
                    new Label()
                {
                    Name = "label" + i
                });
                channelLabels[i].Text     = txtChannelLabel;
                channelLabels[i].Location = new Point(x, y);
                channelLabels[i].Size     = new Size(90, 15);
                tabPage1.Controls.Add(channelLabels[i]);
                y = y + 80;

                SecondaryLoop(linkResults, videoIDs, pictureBoxes, loopBool);
                loopBool = true;
            }
            addressConnection.Close();
        }
Example #4
0
        public async Task <ActionResult <dynamic> > PostYoutubeSong(YoutubeLink youtubeLink)
        {
            var SongCount         = _context.TSongs.ToList <YoutubeSong>().Count;
            var PlaylistCount     = _playlistContext.TPlaylist.ToList <YoutubePlaylist>().Count;
            var SongPlaylistCount = _songPlaylistContext.TSongPlaylist.ToList <SongPlaylist>().Count;

            // This gets the YoutubeVideo object and downloads the mp3
            _youtube = new Youtube(youtubeLink.Url, @"C:\Users\nsedler\source\repos\WebApplication3\WebApplication3\Files\");
            Tuple <Video, Playlist> VideoPlaylist = await _youtube.GetYoutubeVideoAsync();

            await _youtube.DownloadYoutubeVideoAsync();

            //Sets the Songs fields
            YoutubeSong _song = new YoutubeSong();

            if (VideoPlaylist.Item1 != null)
            {
                _song = new YoutubeSong();
                var video = VideoPlaylist.Item1;
                _song.Title  = video.Title;
                _song.Length = video.Duration.Ticks;
                _song.Url    = $"https://localhost:44370/StaticSongs/{video.Title}.mp3";
                _song.Id     = SongCount + 1;

                _context.TSongs.Add(_song);
                await _context.SaveChangesAsync();
            }
            else
            {
                YoutubePlaylist YoutubePlaylist = new YoutubePlaylist();
                var             Playlist        = await _YoutubeClient.Playlists.GetAsync(VideoPlaylist.Item2.Id);

                YoutubePlaylist.Name = Playlist.Title;
                YoutubePlaylist.Id   = PlaylistCount + 1;

                _playlistContext.TPlaylist.Add(YoutubePlaylist);
                await _playlistContext.SaveChangesAsync();



                await foreach (var video in _YoutubeClient.Playlists.GetVideosAsync(VideoPlaylist.Item2.Id))
                {
                    _song        = new YoutubeSong();
                    _song.Title  = video.Title;
                    _song.Length = video.Duration.Ticks;
                    _song.Url    = $"https://localhost:44370/StaticSongs/{video.Title}.mp3";
                    _song.Id     = SongCount + 1;

                    _context.TSongs.Add(_song);
                    await _context.SaveChangesAsync();

                    SongPlaylist SongPlaylist = new SongPlaylist();
                    SongPlaylist.Id         = SongPlaylistCount + 1;
                    SongPlaylist.SongId     = _song.Id;
                    SongPlaylist.PlaylistId = YoutubePlaylist.Id;

                    _songPlaylistContext.TSongPlaylist.Add(SongPlaylist);
                    await _songPlaylistContext.SaveChangesAsync();

                    SongPlaylistCount++;
                    SongCount++;
                }

                return(CreatedAtAction("GetYoutubeSong", new { id = YoutubePlaylist.Id }, YoutubePlaylist));
            }

            return(CreatedAtAction("GetYoutubeSong", new { id = _song.Id }, _song));
        }