Esempio n. 1
0
        private static void WaveToMP3(string waveFileName, string mp3FileName, ExtTrack extTrack, int bitRate = 320)
        {
            //get genres

            genres = new List <string>();
            DiscogCall(extTrack);
            string directory   = savePathMP3 + "\\" + CleanString(extTrack.TagArtists[0]) + "\\" + CleanString(extTrack.Album.Name);
            string fullPathMP3 = directory + "\\" + CleanString(extTrack.Filename) + ".mp3";

            Directory.CreateDirectory(directory);

            // LASTFM - genres dodgy?
            // extTrack.Year = LastFMCall(extTrack.OCName, extTrack.OCArtist);

            extTrack.TagGenres = genres.ToArray();

            // temporary workaround for problems with genres
            extTrack.TagGenres = new string[] { string.Join(",", extTrack.TagGenres) };

            //Stopwatch timer = new Stopwatch();
            //timer.Start();
            using (var reader = new AudioFileReader(waveFileName))
                using (var writer = new LameMP3FileWriter(fullPathMP3, reader.WaveFormat, bitRate))
                    reader.CopyTo(writer);
            //timer.Stop();
            //long elapsedSecs = timer.ElapsedMilliseconds / 1000;


            //tag wav file
            TagLib.File wav = TagLib.File.Create(waveFileName);
            wav.Tag.Title        = extTrack.Filename;
            wav.Tag.Performers   = extTrack.TagArtists;
            wav.Tag.Album        = extTrack.Album.Name;
            wav.Tag.AlbumArtists = extTrack.TagArtists;
            wav.Tag.Genres       = extTrack.TagGenres;
            //wav.Tag.Comment = "my comments, maybe some info about track";
            if (extTrack.Year != null)
            {
                wav.Tag.Year = (uint)extTrack.Year;
            }

            wav.Save();
            wav.Dispose();

            //tag mp3 file
            TagLib.File mp3 = TagLib.File.Create(fullPathMP3);
            mp3.Tag.Title        = extTrack.Filename;
            mp3.Tag.Performers   = extTrack.TagArtists;
            mp3.Tag.Album        = extTrack.Album.Name;
            mp3.Tag.AlbumArtists = extTrack.TagArtists;
            mp3.Tag.Genres       = extTrack.TagGenres;
            //mp3.Tag.Comment = "my comments, maybe some info about track";
            if (extTrack.Year != null)
            {
                mp3.Tag.Year = (uint)extTrack.Year;
            }

            mp3.Save();
            mp3.Dispose();

            // update table with filepath of mp3.
            OfficialChartsEntities db2 = new OfficialChartsEntities();
            var record = db2.Tracks.SingleOrDefault(b => b.TrackID == extTrack.OCID);

            if (record != null)
            {
                record.PathOnDisc = fullPathMP3;
                db2.SaveChanges();
            }
            // CheckFileTags(extTrack.Filename);
        }