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); }
private void UKUpdate() { CheckToken(); int start = 0, end = 0; if (txtUKStart.Text == "") { start = 0; } else if (!int.TryParse(txtUKStart.Text, out start)) { MessageBox.Show("Start is a number only field"); return; } if (txtUKEnd.Text == "") { end = 0; } else if (!int.TryParse(txtUKEnd.Text, out end)) { MessageBox.Show("End is a number only field"); return; } if (start > 0 && end > 0) { //Clear existing list //Get playlist tracks var playlist = spotify.GetPlaylist(MYSPOTIFY_NAME, CHARTS_PLAYLIST); Paging <PlaylistTrack> deleteTracks = spotify.GetPlaylistTracks(MYSPOTIFY_NAME, CHARTS_PLAYLIST); List <DeleteTrackUri> deleteList = new List <DeleteTrackUri>(); foreach (PlaylistTrack t in deleteTracks.Items) { deleteList.Add(new DeleteTrackUri(t.Track.Uri)); } ErrorResponse doDelete = spotify.RemovePlaylistTracks(MYSPOTIFY_NAME, CHARTS_PLAYLIST, deleteList); //Add new tracks OfficialChartsEntities db = new OfficialChartsEntities(); var tracksToRecord = from t in db.Record_Spotify //where t.TrackTitle.Contains("have you ever been lonely") orderby t.ID select t; List <Record_Spotify> lTracks = tracksToRecord.ToList(); int perCycle = 100; int cycles = (end - start + 1) / perCycle; for (int cycle = 0; cycle < cycles; cycle++) { string uris = "{\"uris\":["; for (int t = 0; t < perCycle; t++) { int trackNo = start + cycle * perCycle; if (uris != "{\"uris\":[") { uris += ","; } string id = MySpotify.IdFromUrl(lTracks[t].SpotifyURL); uris += ("\"spotify:track:" + id + "\""); } uris += "]}"; string url = "https://api.spotify.com/v1/playlists/2ps7zHd9of81uPSCNZxWEv/tracks"; HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url); myReq.Headers["Authorization"] = "Bearer " + spotify.AccessToken; myReq.ContentType = "application/json"; myReq.Method = "POST"; using (var streamWriter = new StreamWriter(myReq.GetRequestStream())) { streamWriter.Write(uris); streamWriter.Flush(); streamWriter.Close(); } WebResponse wr = myReq.GetResponse(); wr.Dispose(); } //ErrorResponse addTracks = spotify.AddPlaylistTracks(mySpotifyName, "2ps7zHd9of81uPSCNZxWEv", tracksToAdd); //if (addTracks.HasError()) //{ // string debug = addTracks.Error.Message; //} GetPlayLists(); } }