public CDEntry(CDEntry src) { m_Discid = src.m_Discid; m_Artist = src.m_Artist; m_Title = src.m_Title; m_Year = src.m_Year; m_Genre = src.m_Genre; m_ExtendedData = src.m_ExtendedData; m_PlayOrder = src.m_PlayOrder; m_Tracks = new TrackCollection(); foreach (Track tr in src.m_Tracks) { m_Tracks.Add(new Track(tr)); } }
public string Submit(CDEntry entry, int length, string discid, string category, bool test) { StreamReader reader = null; HttpWebResponse response = null; string url = "http://" + MAIN_FREEDB_ADDRESS + SUBMIT_ADDITIONAL_URL_INFO; string command = ""; string result = ""; if ((entry.Artist ?? "") == "") { throw new Exception("Artist not set"); } if ((entry.Title ?? "") == "") { throw new Exception("Title not set"); } if (!ValidCategories.Contains(category)) { throw new Exception("Category not valid"); } foreach (Track t in entry.Tracks) { if ((t.Title ?? "") == "") { throw new Exception("Track titles not set"); } } foreach (Track t in entry.Tracks) { if (t.FrameOffset < 150) { throw new Exception("Track frame offsets not set"); } } command += "# xmcd CD database file\n"; command += "#\n"; command += "# Track frame offsets:\n"; foreach (Track t in entry.Tracks) { command += "# " + t.FrameOffset + "\n"; } command += "#\n"; command += "# Disc length: " + length.ToString() + " seconds\n"; command += "#\n"; command += "# Revision: 0\n"; command += "# Submitted via: " + ClientName + " " + Version + "\n"; command += "#\n"; command += "DISCID=" + discid.ToLower() + "\n"; command += "DTITLE=" + entry.Artist.Replace(" / ", "/") + " / " + entry.Title.Replace(" / ", "/") + "\n"; command += "DYEAR=" + entry.Year + "\n"; // DYEAR=#{@year.to_i == 0 ? "" : "%04d" % @year} command += "DGENRE=" + entry.Genre + "\n"; // DGENRE=#{(@genre || "").split(" ").collect do |w| w.capitalize end.join(" ")} int i = 0; foreach (Track t in entry.Tracks) { command += "TTITLE" + (i++).ToString() + "=" + t.Title + "\n"; // escape } i = 0; command += "EXTD=" + entry.ExtendedData + "\n"; foreach (Track t in entry.Tracks) { command += "EXTT" + (i++).ToString() + "=" + t.ExtendedData + "\n"; // escape } command += "PLAYORDER=\n"; try { //create our HttpWebRequest which we use to call the freedb server HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Proxy = Proxy; req.ContentType = "text/plain"; req.Method = "POST"; req.Headers.Add("Category", category); req.Headers.Add("Discid", discid.ToLower()); req.Headers.Add("User-Email", UserName + '@' + Hostname); req.Headers.Add("Submit-Mode", test ? "test" : "submit"); req.Headers.Add("X-Cddbd-Note", "Sent by " + ClientName + " " + Version); req.Headers.Add("Charset", "utf-8"); //using Unicode byte[] byteArray = Encoding.UTF8.GetBytes(command); //get our request stream Stream newStream = req.GetRequestStream(); //write our command data to it newStream.Write(byteArray, 0, byteArray.Length); newStream.Close(); //Make the call. Note this is a synchronous call response = (HttpWebResponse)req.GetResponse(); //put the results into a StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8); result = reader.ReadToEnd(); } catch (Exception ex) { throw ex; } finally { if (response != null) { response.Close(); } if (reader != null) { reader.Close(); } } return(result); }
/// <summary> /// Read Entry from the database. /// </summary> /// <param name="qr">A QueryResult object that is created by performing a query</param> /// <param name="cdEntry">out parameter - CDEntry object</param> /// <returns></returns> public string Read(QueryResult qr, out CDEntry cdEntry) { Debug.Assert(qr != null); cdEntry = null; StringCollection coll = null; StringBuilder builder = new StringBuilder(FreedbHelper.Commands.CMD_READ); builder.Append("+"); builder.Append(qr.Category); builder.Append("+"); builder.Append(qr.Discid); //make call try { coll = Call(builder.ToString()); } catch (Exception ex) { string msg = "Error performing cddb read."; Exception newex = new Exception(msg, ex); throw newex; } // check if results came back if (coll.Count < 0) { string msg = "No results returned from cddb read."; Exception ex = new Exception(msg, null); throw ex; } string code = GetCode(coll[0]); if (code == ResponseCodes.CODE_INVALID) { string msg = "Unable to process results for cddb read. Returned Data: " + coll[0]; Exception ex = new Exception(msg, null); throw ex; } switch (code) { case ResponseCodes.CODE_500: return(ResponseCodes.CODE_500); case ResponseCodes.CODE_401: // entry not found case ResponseCodes.CODE_402: // server error case ResponseCodes.CODE_403: // Database entry is corrupt case ResponseCodes.CODE_409: // No handshake return(code); case ResponseCodes.CODE_210: // good { coll.RemoveAt(0); // remove the 210 cdEntry = new CDEntry(coll); return(ResponseCodes.CODE_210); } default: return(ResponseCodes.CODE_500); } }
/// <summary> /// Read Entry from the database. /// </summary> /// <param name="qr">A QueryResult object that is created by performing a query</param> /// <param name="cdEntry">out parameter - CDEntry object</param> /// <returns></returns> public string Read(QueryResult qr, out CDEntry cdEntry) { Debug.Assert(qr != null); cdEntry = null; StringCollection coll = null; StringBuilder builder = new StringBuilder(FreedbHelper.Commands.CMD_READ); builder.Append("+"); builder.Append(qr.Genre); builder.Append("+"); builder.Append(qr.Discid); //make call try { coll = Call(builder.ToString()); } catch (Exception ex) { string msg = "Error performing cddb read."; Exception newex = new Exception(msg,ex); throw newex ; } // check if results came back if (coll.Count < 0) { string msg = "No results returned from cddb read."; Exception ex = new Exception(msg,null); throw ex; } string code = GetCode(coll[0]); if (code == ResponseCodes.CODE_INVALID) { string msg = "Unable to process results for cddb read. Returned Data: " + coll[0]; Exception ex = new Exception(msg,null); throw ex; } switch (code) { case ResponseCodes.CODE_500: return ResponseCodes.CODE_500; case ResponseCodes.CODE_401: // entry not found case ResponseCodes.CODE_402: // server error case ResponseCodes.CODE_403: // Database entry is corrupt case ResponseCodes.CODE_409: // No handshake return code; case ResponseCodes.CODE_210: // good { coll.RemoveAt(0); // remove the 210 cdEntry = new CDEntry(coll); return ResponseCodes.CODE_210; } default: return ResponseCodes.CODE_500; } }
public CDImageLayout TocFromCDEntry(CDEntry cdEntry) { CDImageLayout tocFromCDEntry = new CDImageLayout(); for (int i = 0; i < cdEntry.Tracks.Count; i++) { if (i >= _toc.TrackCount) break; tocFromCDEntry.AddTrack(new CDTrack((uint)i + 1, (uint)cdEntry.Tracks[i].FrameOffset - 150, (i + 1 < cdEntry.Tracks.Count) ? (uint)(cdEntry.Tracks[i + 1].FrameOffset - cdEntry.Tracks[i].FrameOffset) : _toc[i + 1].Length, _toc[i + 1].IsAudio, false/*preEmphasis*/)); } if (tocFromCDEntry.TrackCount > 0 && tocFromCDEntry[1].IsAudio) tocFromCDEntry[1][0].Start = 0; return tocFromCDEntry; }
public CDEntry(CDEntry src) { m_Discid = src.m_Discid; m_Artist = src.m_Artist; m_Title = src.m_Title; m_Year = src.m_Year; m_Genre = src.m_Genre; m_ExtendedData = src.m_ExtendedData; m_PlayOrder = src.m_PlayOrder; m_Tracks = new TrackCollection(); foreach (Track tr in src.m_Tracks) m_Tracks.Add(new Track(tr)); }
//private CUEMetadataEntry CreateCUESheet(ICDRipper audioSource, Release release) //{ // CUEMetadataEntry entry = new CUEMetadataEntry(audioSource.TOC, "musicbrainz"); // entry.metadata.FillFromMusicBrainz(release, entry.TOC.FirstAudio - 1); // return entry; //} private CUEMetadataEntry CreateCUESheet(ICDRipper audioSource, CDEntry cdEntry) { CUEMetadataEntry entry = new CUEMetadataEntry(audioSource.TOC, "freedb"); entry.metadata.FillFromFreedb(cdEntry, entry.TOC.FirstAudio - 1); return entry; }
private void FreedbSubmit(object o) { StringCollection tmp = new StringCollection(); tmp.Add("DTITLE="); CDEntry entry = new CDEntry(tmp); entry.Artist = data.selectedRelease.metadata.Artist; entry.Title = data.selectedRelease.metadata.Title; entry.Year = data.selectedRelease.metadata.Year; entry.Genre = data.selectedRelease.metadata.Genre; int i = 1; for (i = 1; i <= selectedDriveInfo.drive.TOC.TrackCount; i++) { Freedb.Track tt = new Freedb.Track(); if (i >= selectedDriveInfo.drive.TOC.FirstAudio && i < selectedDriveInfo.drive.TOC.FirstAudio + selectedDriveInfo.drive.TOC.AudioTracks) { CUETrackMetadata t = data.selectedRelease.metadata.Tracks[i - selectedDriveInfo.drive.TOC.FirstAudio]; if (t.Artist != "" && t.Artist != entry.Artist) tt.Title = t.Artist + " / " + t.Title; else tt.Title = t.Title; } else tt.Title = "Data track"; tt.FrameOffset = 150 + (int)selectedDriveInfo.drive.TOC[i].Start; entry.Tracks.Add(tt); } /* foreach (CUETrackMetadata t in data.selectedRelease.metadata.Tracks) { Freedb.Track tt = new Freedb.Track(); if (t.Artist != "" && t.Artist != entry.Artist) tt.Title = t.Artist + " / " + t.Title; else tt.Title = t.Title; tt.FrameOffset = 150 + (int)selectedDriveInfo.drive.TOC[i++].Start; entry.Tracks.Add(tt); }*/ FreedbHelper m_freedb = new FreedbHelper(); frmFreedbSubmit frm = new frmFreedbSubmit(); foreach (string c in m_freedb.ValidCategories) frm.Data.Categories.Add(c); frm.Data.User = _config.advanced.FreedbUser; frm.Data.Domain = _config.advanced.FreedbDomain; frm.Data.Category = "misc"; DialogResult dlgRes = DialogResult.Cancel; this.Invoke((MethodInvoker)delegate() { dlgRes = frm.ShowDialog(); }); if (dlgRes == DialogResult.Cancel) { _workThread = null; this.BeginInvoke((MethodInvoker)delegate() { SetupControls(); }); return; } data.selectedRelease.metadata.Save(); _config.advanced.FreedbUser = frm.Data.User; _config.advanced.FreedbDomain = frm.Data.Domain; m_freedb.Proxy = _config.GetProxy(); m_freedb.UserName = _config.advanced.FreedbUser; m_freedb.Hostname = _config.advanced.FreedbDomain; m_freedb.ClientName = "CUERipper"; m_freedb.Version = CUESheet.CUEToolsVersion; //try //{ // string code = m_freedb.GetCategories(out tmp); // if (code == FreedbHelper.ResponseCodes.CODE_210) // m_freedb.ValidCategories = tmp; //} //catch //{ //} uint length = selectedDriveInfo.drive.TOC.Length / 75 + 2; try { string res = m_freedb.Submit(entry, (int)length, AccurateRipVerify.CalculateCDDBId(selectedDriveInfo.drive.TOC), frm.Data.Category, false); this.BeginInvoke((MethodInvoker)delegate() { dlgRes = MessageBox.Show(this, res, "Submit result", MessageBoxButtons.OK, MessageBoxIcon.Information); }); } catch (Exception ex) { this.BeginInvoke((MethodInvoker)delegate() { dlgRes = MessageBox.Show(this, ex.Message, "Submit result", MessageBoxButtons.OK, MessageBoxIcon.Error); }); } _workThread = null; this.BeginInvoke((MethodInvoker)delegate() { SetupControls(); }); }
public string Submit(CDEntry entry, int length, string discid, string category, bool test) { StreamReader reader = null; HttpWebResponse response = null; string url = "http://" + MAIN_FREEDB_ADDRESS + SUBMIT_ADDITIONAL_URL_INFO; string command = ""; string result = ""; if ((entry.Artist ?? "") == "") throw new Exception("Artist not set"); if ((entry.Title ?? "") == "") throw new Exception("Title not set"); if (!ValidCategories.Contains(category)) throw new Exception("Category not valid"); foreach (Track t in entry.Tracks) if ((t.Title ?? "") == "") throw new Exception("Track titles not set"); foreach (Track t in entry.Tracks) if (t.FrameOffset < 150) throw new Exception("Track frame offsets not set"); command += "# xmcd CD database file\n"; command += "#\n"; command += "# Track frame offsets:\n"; foreach(Track t in entry.Tracks) command += "# " + t.FrameOffset + "\n"; command += "#\n"; command += "# Disc length: " + length.ToString() + " seconds\n"; command += "#\n"; command += "# Revision: 0\n"; command += "# Submitted via: " + ClientName + " " + Version + "\n"; command += "#\n"; command += "DISCID=" + discid.ToLower() + "\n"; command += "DTITLE=" + entry.Artist.Replace(" / ", "/") + " / " + entry.Title.Replace(" / ", "/") + "\n"; command += "DYEAR=" + entry.Year + "\n"; // DYEAR=#{@year.to_i == 0 ? "" : "%04d" % @year} command += "DGENRE=" + entry.Genre + "\n"; // DGENRE=#{(@genre || "").split(" ").collect do |w| w.capitalize end.join(" ")} int i = 0; foreach (Track t in entry.Tracks) command += "TTITLE" + (i++).ToString() + "=" + t.Title + "\n"; // escape i = 0; command += "EXTD=" + entry.ExtendedData + "\n"; foreach (Track t in entry.Tracks) command += "EXTT" + (i++).ToString() + "=" + t.ExtendedData + "\n"; // escape command += "PLAYORDER=\n"; try { //create our HttpWebRequest which we use to call the freedb server HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Proxy = Proxy; req.ContentType = "text/plain"; req.Method = "POST"; req.Headers.Add("Category", category); req.Headers.Add("Discid", discid.ToLower()); req.Headers.Add("User-Email", UserName + '@' + Hostname); req.Headers.Add("Submit-Mode", test ? "test" : "submit"); req.Headers.Add("X-Cddbd-Note", "Sent by " + ClientName + " " + Version); req.Headers.Add("Charset", "utf-8"); //using Unicode byte[] byteArray = Encoding.UTF8.GetBytes(command); //get our request stream Stream newStream = req.GetRequestStream(); //write our command data to it newStream.Write(byteArray, 0, byteArray.Length); newStream.Close(); //Make the call. Note this is a synchronous call response = (HttpWebResponse)req.GetResponse(); //put the results into a StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8); result = reader.ReadToEnd(); } catch (Exception ex) { throw ex; } finally { if (response != null) response.Close(); if (reader != null) reader.Close(); } return result; }