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].Duration = m_trackDurations[i]; m_cdTrackDetail[i].EXTT = parseTrackExtension(i); m_cdTrackDetail[i].TrackNumber = i + 1; } return(new CDInfoDetail(m_discid, m_artist, m_title, m_genre, m_year, m_length, m_cdTrackDetail, m_extd, m_playorder)); }
public CDInfoDetail(string discID, string artist, string title, string genre, int year, int duration, CDTrackDetail[] tracks, string extd, int[] playorder) { m_discId = discID; m_artist = artist; m_title = title; m_genre = genre; m_year = year; m_duration = duration; m_tracks = tracks; m_extd = extd; m_playorder = playorder; }
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].Duration = m_trackDurations[i]; m_cdTrackDetail[i].EXTT = parseTrackExtension(i); m_cdTrackDetail[i].TrackNumber = 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 char[] { ' ' })[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].Duration = m_trackDurations[i]; m_cdTrackDetail[i].EXTT = extt; m_cdTrackDetail[i].TrackNumber = i + 1; } }
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 char[] { ' ' })[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].Duration = m_trackDurations[i]; m_cdTrackDetail[i].EXTT = extt; m_cdTrackDetail[i].TrackNumber = i + 1; } }