public CDInfoDetail parse(string content) { m_content = (string)content.Clone(); if (m_content.IndexOf("# xmcd") != 0) { return(null); } m_offsets = parseOffsets(); m_length = parseLength(); m_trackDurations = calculateDurations(m_offsets, m_length); m_discid = parseDiscIDs()[0]; m_artist = parseArtist(); m_playorder = parsePlayOrder(); m_title = parseTitle(); m_year = parseYear(); m_genre = parseGenre(); m_extd = parseExtension(); m_cdTrackDetail = new CDTrackDetail[m_offsets.Length]; for (int i = 0; i < m_offsets.Length; i++) { m_cdTrackDetail[i] = new CDTrackDetail(); string trackArtist = parseTrackArtist(i); m_cdTrackDetail[i].Artist = trackArtist.Equals(m_artist) ? null : trackArtist; m_cdTrackDetail[i].Title = parseTrackTitle(i); m_cdTrackDetail[i].Offset = m_offsets[i]; m_cdTrackDetail[i].DurationInt = m_trackDurations[i]; m_cdTrackDetail[i].EXTT = parseTrackExtension(i); m_cdTrackDetail[i].Track = i + 1; } return(new CDInfoDetail(m_discid, m_artist, m_title, m_genre, m_year, m_length, m_cdTrackDetail, m_extd, m_playorder)); }
private void InitVariables(ArrayList offsets, Hashtable comments, Hashtable fields) { // all the song offsets m_offsets = (int[])offsets.ToArray(typeof (int)); m_cdTrackDetail = new CDTrackDetail[m_offsets.Length]; foreach (DictionaryEntry dict in comments) { string key = (string)dict.Key; string val = (string)dict.Value; switch (key) { case "Disc length": m_length = Convert.ToInt32(val.Split(new[] {' '})[0].Trim()); m_trackDurations = calculateDurations(m_offsets, m_length); break; case "Revision": break; case "Submitted via": break; case "Processed by": break; default: break; } } foreach (DictionaryEntry dict in fields) { string key = (string)dict.Key; string val = (string)dict.Value; if (key.StartsWith("TTITLE") || key.StartsWith("EXTT")) // a track { continue; } else { switch (key) { case "DISCID": m_discid = val; break; case "DTITLE": m_title = val; break; case "DYEAR": try { m_year = Convert.ToInt32(val); } catch { string year = val; int k = 0; int l = 0; char[] yearChar = year.ToCharArray(); for (l = 0; l < yearChar.Length; l++) { if (Char.IsDigit(yearChar[l])) break; } for (k = l; k < yearChar.Length; k++) { if (!Char.IsDigit(yearChar[k])) break; } if (l < k) { if (k == year.Length) m_year = Convert.ToInt32(year.Substring(l)); else m_year = Convert.ToInt32(year.Substring(l, k - l)); } } break; case "DGENRE": m_genre = val; break; case "EXTD": m_extd = val; break; case "PLAYORDER": { // restricting scope... int[] ai; char[] seps = {',', '\n', '\r', '\t'}; string[] tokens = val.Split(seps); if (tokens.Length == 1 && tokens[0].Trim().Length == 0) ai = new int[0]; else ai = new int[tokens.Length]; try { for (int i = 0; i < ai.Length; i++) ai[i] = Convert.ToInt32(tokens[i]); } catch {} m_playorder = ai; } break; default: break; } } } // find the artist from the title... int slash = m_title.IndexOf(" / "); //Some FreeDB annotators use a " - " instead of the conventional " / " //Try to find such a delimiter if the standard one is not found beforehand if (slash < 0) slash = m_title.IndexOf(" - "); if (slash < 0) m_artist = null; else { m_artist = m_title.Substring(0, slash); m_title = m_title.Substring(slash + 3); } /*Tracks from compilation-like albums have their own nomenclature in FreeDB (cf. http://www.freedb.org/modules.php?name=Sections&sop=viewarticle&artid=26#2-2), track tags have to be pre-processed The only difficulty here is whether or not some Artist or Title names may contain legitimate " / ", regarding FreeDB nomenclature it is illegal We split the string even if we're not sure this CD is a real compilation: it is usually no use to try to figure out if the CD is an actual compilation by looking at its Artist tag (album Artist tag = "((Various)|(Assorted))(Artists)?") because most annotators don't tag it that way Extended to the detection of " - " as well, a lot of FreeDB annotators do not follow the above rule and split the Artist from the Title name this way; this workaround is a hell more tricky, a few legitimate tags may be badly cut We only split the string if we're sure this CD is a real compilation */ //isALegitimateCompilation if the CD Artist is either not set or equals "Various", "Various Artists", etc... Regex artistTagIsSetToVarious = new Regex(@"^(([Vv]arious)|([Aa]ssorted))( [Aa]rtist[s]?)?$"); bool isALegitimateCompilation = (m_artist == string.Empty || artistTagIsSetToVarious.Match(m_artist).Success) ? true : false; for (int i = 0; i < offsets.Count; i++) { string title = (string)fields["TTITLE" + i]; string extt = (string)fields["EXTT" + i]; m_cdTrackDetail[i] = new CDTrackDetail(); string trackArtist = extendedParseTrackArtist(title, isALegitimateCompilation); string trackTitle = extendedParseTrackTitle(title, isALegitimateCompilation); m_cdTrackDetail[i].Artist = trackArtist.Equals(m_artist) ? null : trackArtist; m_cdTrackDetail[i].Title = trackTitle; m_cdTrackDetail[i].Offset = m_offsets[i]; m_cdTrackDetail[i].DurationInt = m_trackDurations[i]; m_cdTrackDetail[i].EXTT = extt; m_cdTrackDetail[i].Track = i + 1; } }
public CDInfoDetail parse(string content) { m_content = (string)content.Clone(); if (m_content.IndexOf("# xmcd") != 0) return null; m_offsets = parseOffsets(); m_length = parseLength(); m_trackDurations = calculateDurations(m_offsets, m_length); m_discid = parseDiscIDs()[0]; m_artist = parseArtist(); m_playorder = parsePlayOrder(); m_title = parseTitle(); m_year = parseYear(); m_genre = parseGenre(); m_extd = parseExtension(); m_cdTrackDetail = new CDTrackDetail[m_offsets.Length]; for (int i = 0; i < m_offsets.Length; i++) { m_cdTrackDetail[i] = new CDTrackDetail(); string trackArtist = parseTrackArtist(i); m_cdTrackDetail[i].Artist = trackArtist.Equals(m_artist) ? null : trackArtist; m_cdTrackDetail[i].Title = parseTrackTitle(i); m_cdTrackDetail[i].Offset = m_offsets[i]; m_cdTrackDetail[i].DurationInt = m_trackDurations[i]; m_cdTrackDetail[i].EXTT = parseTrackExtension(i); m_cdTrackDetail[i].Track = i + 1; } return new CDInfoDetail(m_discid, m_artist, m_title, m_genre, m_year, m_length, m_cdTrackDetail, m_extd, m_playorder); }
/// <summary> /// Queries FreeDB for the Audio CD inserted /// </summary> /// <param name = "drive"></param> private void QueryFreeDB(char drive) { log.Trace(">>>"); SetStatusLabel(localisation.ToString("Conversion", "FreeDBAccess")); string discId = string.Empty; CDInfoDetail MusicCD = new CDInfoDetail(); int driveID = Util.Drive2BassID(drive); if (driveID < 0) { SetStatusLabel(""); return; } log.Info("Starting FreeDB Lookup"); _main.Cursor = Cursors.WaitCursor; bindingList[driveID].Clear(); try { FreeDBQuery freedb = new FreeDBQuery(); freedb.Connect(); CDInfo[] cds = freedb.GetDiscInfo(drive); if (cds != null) { log.Debug("FreeDB: Found {0} matching discs.", cds.Length); if (cds.Length == 1) { MusicCD = freedb.GetDiscDetails(cds[0].Category, cds[0].DiscId); } else { FreeDBMultiCDSelect multiCDSelect = new FreeDBMultiCDSelect(); multiCDSelect.CDList.ValueMember = "DiscId"; multiCDSelect.CDList.DisplayMember = "Title"; multiCDSelect.CDList.DataSource = cds; if (multiCDSelect.ShowDialog() == DialogResult.OK) { MusicCD = freedb.GetDiscDetails(cds[0].Category, multiCDSelect.DiscID); } else { MusicCD = null; } } } else { log.Debug("FreeDB: Disc could not be located in FreeDB."); MusicCD = null; } freedb.Disconnect(); } catch (System.Net.WebException webEx) { if (webEx.Status == WebExceptionStatus.Timeout) { log.Info("FreeDB: Timeout querying FreeDB. No Data returned for CD"); MusicCD = null; } else { log.Error("FreeDB: Exception querying Disc. {0} {1}", webEx.Message, webEx.StackTrace); MusicCD = null; } } catch (Exception ex) { log.Error("FreeDB: Exception querying Disc. {0} {1}", ex.Message, ex.StackTrace); MusicCD = null; } log.Info("Finished FreeDB Lookup"); _main.Cursor = Cursors.Default; if (MusicCD != null) { tbAlbumArtist.Text = MusicCD.Artist; tbAlbum.Text = MusicCD.Title; tbGenre.Text = MusicCD.Genre; tbYear.Text = MusicCD.Year.ToString(); foreach (CDTrackDetail trackDetail in MusicCD.Tracks) { if (trackDetail.Artist == null) trackDetail.Artist = MusicCD.Artist; bindingList[driveID].Add(trackDetail); } } else { int numTracks = BassCd.BASS_CD_GetTracks(driveID); for (int i = 0; i < numTracks; i++) { CDTrackDetail trackDetail = new CDTrackDetail(); trackDetail.Track = i + 1; trackDetail.Title = string.Format("Track{0}", (i + 1).ToString().PadLeft(2, '0')); bindingList[driveID].Add(trackDetail); } } CheckRows(true); (dataGridViewRip.Columns[0].HeaderCell as DatagridViewCheckBoxHeaderCell).Checked = true; SetStatusLabel(""); log.Trace("<<<"); }
private void InitVariables(ArrayList offsets, Hashtable comments, Hashtable fields) { // all the song offsets m_offsets = (int[])offsets.ToArray(typeof(int)); m_cdTrackDetail = new CDTrackDetail[m_offsets.Length]; foreach (DictionaryEntry dict in comments) { string key = (string)dict.Key; string val = (string)dict.Value; switch (key) { case "Disc length": m_length = Convert.ToInt32(val.Split(new[] { ' ' })[0].Trim()); m_trackDurations = calculateDurations(m_offsets, m_length); break; case "Revision": break; case "Submitted via": break; case "Processed by": break; default: break; } } foreach (DictionaryEntry dict in fields) { string key = (string)dict.Key; string val = (string)dict.Value; if (key.StartsWith("TTITLE") || key.StartsWith("EXTT")) // a track { continue; } else { switch (key) { case "DISCID": m_discid = val; break; case "DTITLE": m_title = val; break; case "DYEAR": try { m_year = Convert.ToInt32(val); } catch { string year = val; int k = 0; int l = 0; char[] yearChar = year.ToCharArray(); for (l = 0; l < yearChar.Length; l++) { if (Char.IsDigit(yearChar[l])) { break; } } for (k = l; k < yearChar.Length; k++) { if (!Char.IsDigit(yearChar[k])) { break; } } if (l < k) { if (k == year.Length) { m_year = Convert.ToInt32(year.Substring(l)); } else { m_year = Convert.ToInt32(year.Substring(l, k - l)); } } } break; case "DGENRE": m_genre = val; break; case "EXTD": m_extd = val; break; case "PLAYORDER": { // restricting scope... int[] ai; char[] seps = { ',', '\n', '\r', '\t' }; string[] tokens = val.Split(seps); if (tokens.Length == 1 && tokens[0].Trim().Length == 0) { ai = new int[0]; } else { ai = new int[tokens.Length]; } try { for (int i = 0; i < ai.Length; i++) { ai[i] = Convert.ToInt32(tokens[i]); } } catch {} m_playorder = ai; } break; default: break; } } } // find the artist from the title... int slash = m_title.IndexOf(" / "); //Some FreeDB annotators use a " - " instead of the conventional " / " //Try to find such a delimiter if the standard one is not found beforehand if (slash < 0) { slash = m_title.IndexOf(" - "); } if (slash < 0) { m_artist = null; } else { m_artist = m_title.Substring(0, slash); m_title = m_title.Substring(slash + 3); } /*Tracks from compilation-like albums have their own nomenclature in FreeDB (cf. http://www.freedb.org/modules.php?name=Sections&sop=viewarticle&artid=26#2-2), track tags have to be pre-processed * * The only difficulty here is whether or not some Artist or Title names may contain legitimate " / ", regarding FreeDB nomenclature it is illegal * We split the string even if we're not sure this CD is a real compilation: it is usually no use to try to figure out if the CD is an actual compilation by looking at its Artist tag (album Artist tag = "((Various)|(Assorted))(Artists)?") because most annotators don't tag it that way * * Extended to the detection of " - " as well, a lot of FreeDB annotators do not follow the above rule and split the Artist from the Title name this way; this workaround is a hell more tricky, a few legitimate tags may be badly cut * We only split the string if we're sure this CD is a real compilation * */ //isALegitimateCompilation if the CD Artist is either not set or equals "Various", "Various Artists", etc... Regex artistTagIsSetToVarious = new Regex(@"^(([Vv]arious)|([Aa]ssorted))( [Aa]rtist[s]?)?$"); bool isALegitimateCompilation = (m_artist == string.Empty || artistTagIsSetToVarious.Match(m_artist).Success) ? true : false; for (int i = 0; i < offsets.Count; i++) { string title = (string)fields["TTITLE" + i]; string extt = (string)fields["EXTT" + i]; m_cdTrackDetail[i] = new CDTrackDetail(); string trackArtist = extendedParseTrackArtist(title, isALegitimateCompilation); string trackTitle = extendedParseTrackTitle(title, isALegitimateCompilation); m_cdTrackDetail[i].Artist = trackArtist.Equals(m_artist) ? null : trackArtist; m_cdTrackDetail[i].Title = trackTitle; m_cdTrackDetail[i].Offset = m_offsets[i]; m_cdTrackDetail[i].DurationInt = m_trackDurations[i]; m_cdTrackDetail[i].EXTT = extt; m_cdTrackDetail[i].Track = i + 1; } }