Пример #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);
            }
        }
Пример #2
0
 public static void createPlaylistCollection()
 {
     string[] playlists = Directory.GetDirectories(musicFolderPath);
     foreach (string playlistPath in playlists)
     {
         string   playlistName   = new DirectoryInfo(playlistPath).Name;
         Playlist p              = new Playlist(playlistName);
         string   playlistFolder = Path.Combine(musicFolderPath, playlistPath);
         string[] songs          = Directory.GetFiles(playlistFolder);
         foreach (string songName in songs)
         {
             string songLocation = Path.Combine(playlistFolder, songName);
             p.addSong(new Song(songLocation));
         }
         PlaylistManager.Instance.addPlaylist(p);
     }
 }