internal void Merge(CDEntry slave) { if (slave != null) { Artist = StringUtils.TakeValid(Artist, slave.Artist); ExtendedData = StringUtils.TakeValid(ExtendedData, slave.ExtendedData); Genre = StringUtils.TakeValid(Genre, slave.Genre); PlayOrder = StringUtils.TakeValid(PlayOrder, slave.PlayOrder); Title = StringUtils.TakeValid(Title, slave.Title); Year = StringUtils.TakeValid(Year, slave.Year); Tracks = MergeTracks(Tracks, slave.Tracks); } }
/// <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) { StringBuilder builder = new StringBuilder(FreedbHelper.Commands.CMD_READ); builder.Append(" "); builder.Append(qr.Category); builder.Append(" "); builder.Append(qr.Discid); cdEntry = null; try { string request = builder.ToString(); List <string> reply = SendRequest(request); if (reply.Count <= 0) { string msg = "No results returned from cddb query."; Exception ex = new Exception(msg, null); throw ex; } string code = GetReplyCode(reply, request); switch (code) { case ResponseCodes.CODE_210: case ResponseCodes.CODE_211: { //remove first line, this one has code 210 or 211 reply.RemoveAt(0); cdEntry = new CDEntry(reply); } break; } return(code); } catch (Exception ex) { string msg = "Unable to perform cddb query."; Exception newex = new Exception(msg, ex); throw newex; } }
public void RefreshDisk() { string rootPath = System.IO.Path.GetPathRoot(this.Path); if (!string.IsNullOrEmpty(rootPath)) { char letter = rootPath.ToUpperInvariant()[0]; { using (CDDrive cd = new CDDrive()) { if (cd.Open(letter) && cd.Refresh()) { switch (ProTONEConfig.AudioCdInfoSource) { case CddaInfoSource.CdText: _cdEntry = BuildCdEntryByCdText(cd, _discId); break; case CddaInfoSource.Cddb: _cdEntry = BuildCdEntryByCddb(cd, _discId); break; case CddaInfoSource.CdText_Cddb: { _cdEntry = BuildCdEntryByCdText(cd, _discId); CDEntry cde = BuildCdEntryByCddb(cd, _discId); _cdEntry = Merge(_cdEntry, cde); } break; case CddaInfoSource.Cddb_CdText: { _cdEntry = BuildCdEntryByCddb(cd, _discId); CDEntry cde = BuildCdEntryByCdText(cd, _discId); _cdEntry = Merge(_cdEntry, cde); } break; default: break; } if (_cdEntry != null) { _cdEntry.PersistDisc(); } } } } } }
public static CDEntry Merge(CDEntry master, CDEntry slave) { if (master == null) return slave; master.Merge(slave); return master; }
public static CDEntry BuildCdEntryByCdText(CDDrive cd, string diskId) { List<Track> tracks = null; if (cd.ReadCDText(out tracks)) { CDEntry cdEntry = new CDEntry(diskId); cdEntry.Tracks.AddRange(tracks); return cdEntry; } return null; }
public CDAFileInfo(string path, bool deepLoad) : base(path, false) { try { string rootPath = System.IO.Path.GetPathRoot(path); if (!string.IsNullOrEmpty(rootPath)) { char letter = rootPath.ToUpperInvariant()[0]; using (CDDrive cd = new CDDrive()) { if (cd.Open(letter) && cd.Refresh()) { string trackStr = path.Replace(rootPath, "").ToLowerInvariant().Replace("track", "").Replace(".cda", ""); _track = -1; if (int.TryParse(trackStr, out _track) && _track > 0) { if (cd.IsAudioTrack(_track)) { _duration = cd.GetSeconds(_track); _discId = cd.GetCDDBDiskID(); // Check whether the disc is already added to our FreeDb lite database _cdEntry = CDEntry.LoadPersistentDisc(_discId); if (_cdEntry == null) { RefreshDisk(); } return; } } } } _cdEntry = null; } } catch(Exception ex) { Logger.LogException(ex); _cdEntry = null; } }
public override void Rebuild() { if (!string.IsNullOrEmpty(_discId)) { CDEntry cde = CDEntry.LoadPersistentDisc(_discId); if (cde != null) { _cdEntry = cde; return; } } RefreshDisk(); }
/// <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) { StringBuilder builder = new StringBuilder(FreedbHelper.Commands.CMD_READ); builder.Append(" "); builder.Append(qr.Category); builder.Append(" "); builder.Append(qr.Discid); cdEntry = null; try { string request = builder.ToString(); List<string> reply = SendRequest(request); if (reply.Count <= 0) { string msg = "No results returned from cddb query."; Exception ex = new Exception(msg, null); throw ex; } string code = GetReplyCode(reply, request); switch (code) { case ResponseCodes.CODE_210: case ResponseCodes.CODE_211: { //remove first line, this one has code 210 or 211 reply.RemoveAt(0); cdEntry = new CDEntry(reply); } break; } return code; } catch (Exception ex) { string msg = "Unable to perform cddb query."; Exception newex = new Exception(msg, ex); throw newex; } }