Beispiel #1
0
        public async Task SaveAudioToDiskAsync(string link, Playlist playList)
        {
            string source = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, @"music\");

            playList.PlaylistName += @"\"; //playlistname is the foldername
            YoutubeClient youtube = new YoutubeClient();
            Video         video   = await youtube.Videos.GetAsync(link);

            string         legalTitle     = string.Join("", video.Title.Split(Path.GetInvalidFileNameChars())); // Removes all possible illegal filename characetrs from the title
            StreamManifest streamManifest = await youtube.Videos.Streams.GetManifestAsync(link);

            IStreamInfo streamInfo = streamManifest.GetAudioOnly().WithHighestBitrate();

            if (streamInfo != null)
            {
                // Download the stream to file
                string fileName = $"{source + playList.PlaylistName + legalTitle}";

                await youtube.Videos.Streams.DownloadAsync(streamInfo, fileName + ".mp4"); //downloaden van mp4

                FFMpegConverter ffMpeg = new FFMpegConverter();
                ffMpeg.ConvertMedia(fileName + ".mp4", fileName + ".mp3", "mp3"); //converteren van mp4 naar mp3
                File.Delete(fileName + ".mp4");

                Song newSong = new Song(fileName + ".mp3"); //aanmaken van songobject
                newSong.ArtistName    = video.Author;       //zetten van de filetags
                newSong.SongTitle     = video.Title;
                newSong.AlbumTitle    = null;
                newSong.AlbumTrack    = 0;
                newSong.MaxAlbumTrack = 0;
                newSong.Year          = 0;
                newSong.BPM           = 0;
                /* downloaden van thumbnail*/
                using (WebClient client = new WebClient())
                {
                    client.DownloadFile(video.Thumbnails.HighResUrl, fileName + ".jpg");
                }

                newSong.setAlbumArt(fileName + ".jpg"); //zetten van albumart metadata

                File.Delete(fileName + ".jpg");         //deleten van thumbnail image file

                newSong.saveFileTag();                  //opslaan van filetags

                playList.addSong(newSong);

                //toevoegen aan database
                DbManager db = new DbManager();
                db.addSongToDatabase(newSong);
            }
        }
Beispiel #2
0
        private void songImport(Window window)
        {
            if (FileLocation == null)
            {
                System.Windows.MessageBox.Show("Kies een nummer om te importeren");
                return;
            }
            if (SelectedPlaylistInImportWindow == null)
            {
                System.Windows.MessageBox.Show("Kies een playlist");
                return;
            }
            if (ArtistName == null)
            {
                System.Windows.MessageBox.Show("Vul de artiest van het nummer in");
                return;
            }
            if (SongTitle == null)
            {
                System.Windows.MessageBox.Show("Vul de titel van het nummer in");
                return;
            }
            string songFilePath = FileLocation;
            string destPath     = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, @"music\" + SelectedPlaylistInImportWindow.PlaylistName + @"\" + ArtistName + " - " + SongTitle + ".mp3");

            File.Copy(songFilePath, destPath);
            Song newSong = new Song(destPath);

            newSong.ArtistName = ArtistName;
            newSong.SongTitle  = SongTitle;
            newSong.saveFileTag();
            SelectedPlaylistInImportWindow.addSong(newSong);
            DbManager db = new DbManager();

            db.addSongToDatabase(newSong);
            System.Windows.MessageBox.Show("Import succesvol");
            CloseWindow(window);
        }