Esempio n. 1
0
 public void CopyMetadata(CUEMetadata metadata)
 {
     // if (metadata.Tracks.Count != Tracks.Count) throw;
     // Tracks.Count = metadata.Tracks.Count;
     TotalDiscs  = metadata.TotalDiscs;
     DiscNumber  = metadata.DiscNumber;
     DiscName    = metadata.DiscName;
     Comment     = metadata.Comment;
     Year        = metadata.Year;
     Genre       = metadata.Genre;
     Artist      = metadata.Artist;
     Title       = metadata.Title;
     Barcode     = metadata.Barcode;
     ReleaseDate = metadata.ReleaseDate;
     Country     = metadata.Country;
     Label       = metadata.Label;
     LabelNo     = metadata.LabelNo;
     AlbumArt    = metadata.AlbumArt;
     for (int i = 0; i < Tracks.Count; i++)
     {
         Tracks[i].Title   = metadata.Tracks[i].Title;
         Tracks[i].Artist  = metadata.Tracks[i].Artist;
         Tracks[i].Comment = metadata.Tracks[i].Comment;
         Tracks[i].ISRC    = metadata.Tracks[i].ISRC;
     }
 }
Esempio n. 2
0
        public bool Contains(CUEMetadata metadata)
        {
            CUEMetadata sum = new CUEMetadata(metadata);

            sum.Merge(this, false);
            return(sum.Equals(this));
        }
Esempio n. 3
0
		private void AddItem(object i)
		{
			if (i is CUEToolsSourceFile)
			{
				CUEToolsSourceFile sf = i as CUEToolsSourceFile;
				ListViewItem item = new ListViewItem(sf.path, 0);
				item.Tag = sf;
				listChoices.Items.Add(item);
			}
			else if (i is TagLib.IPicture)
			{
				TagLib.IPicture pic = i as TagLib.IPicture;
				ListViewItem item = new ListViewItem(pic.Description, -1);
				item.Tag = pic;
				listChoices.Items.Add(item);
			}
			else if (i is CUEMetadataEntry)
			{
				CUEMetadataEntry entry = i as CUEMetadataEntry;
				ListViewItem item = new ListViewItem(entry.ToString(), entry.ImageKey);
				item.Tag = entry;
				listChoices.Items.Add(item);

				if (entry.ImageKey == "freedb")
				{
					// check if the entry contains non-iso characters,
					// and add a second one if it does
					CUEMetadata copy = new CUEMetadata(entry.metadata);
					if (copy.FreedbToEncoding())
					{
						entry = new CUEMetadataEntry(copy, entry.TOC, entry.ImageKey);
						item = new ListViewItem(entry.ToString(), entry.ImageKey);
						item.Tag = entry;
						listChoices.Items.Add(item);
					}
				}
			}
			else
			{
				ListViewItem item = new ListViewItem(i.ToString(), -1);
				item.Tag = i;
				listChoices.Items.Add(item);
			}
		}
Esempio n. 4
0
        public override bool Equals(object obj)
        {
            CUEMetadata metadata = obj as CUEMetadata;

            if (metadata == null)
            {
                return(false);
            }
            if (TotalDiscs != metadata.TotalDiscs ||
                DiscNumber != metadata.DiscNumber ||
                DiscName != metadata.DiscName ||
                Comment != metadata.Comment ||
                Year != metadata.Year ||
                Genre != metadata.Genre ||
                Artist != metadata.Artist ||
                Title != metadata.Title ||
                Barcode != metadata.Barcode ||
                ReleaseDate != metadata.ReleaseDate ||
                Label != metadata.Label ||
                LabelNo != metadata.LabelNo ||
                Country != metadata.Country ||
                Tracks.Count != metadata.Tracks.Count
                )
            {
                return(false);
            }
            for (int i = 0; i < Tracks.Count; i++)
            {
                if (Tracks[i].Title != metadata.Tracks[i].Title ||
                    Tracks[i].Artist != metadata.Tracks[i].Artist ||
                    Tracks[i].Comment != metadata.Tracks[i].Comment ||
                    Tracks[i].ISRC != metadata.Tracks[i].ISRC)
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 5
0
        public List<object> LookupAlbumInfo(bool useCache, bool useCUE, bool useCTDB, CTDBMetadataSearch metadataSearch)
        {
            List<object> Releases = new List<object>();

            CUEMetadata dbmeta = null;

            if (useCache && _localDB != null)
            {
                List<string> fullAudioPaths = this.SourcePaths.ConvertAll(p => CUEToolsLocalDBEntry.NormalizePath(p));
                var myEntry = _localDB.Find(e => e.Equals(this.TOC, fullAudioPaths));
                if (myEntry != null)
                    dbmeta = myEntry.Metadata;
            }

            if (dbmeta != null)
                Releases.Add(new CUEMetadataEntry(dbmeta, TOC, "local"));

            //if (useCache)
            //{
            //    try
            //    {
            //        CUEMetadata cache = CUEMetadata.Load(TOC.TOCID);
            //        if (cache != null)
            //            Releases.Add(new CUEMetadataEntry(cache, TOC, "local"));
            //    }
            //    catch (Exception ex)
            //    {
            //        System.Diagnostics.Trace.WriteLine(ex.Message);
            //    }
            //}

            if (useCUE)
            {
                if (dbmeta == null || !dbmeta.Contains(cueMetadata))
                {
                    if (cueMetadata.Contains(taglibMetadata) || !taglibMetadata.Contains(cueMetadata))
                        Releases.Add(new CUEMetadataEntry(new CUEMetadata(cueMetadata), TOC, "cue"));
                }
                if (dbmeta == null || !dbmeta.Contains(taglibMetadata))
                {
                    if (!cueMetadata.Contains(taglibMetadata))
                        Releases.Add(new CUEMetadataEntry(new CUEMetadata(taglibMetadata), TOC, "tags"));
                }
            }

            if (useCache && _localDB != null)
            {
                foreach (var entry in _localDB)
                    if (entry.DiscID == TOC.TOCID && entry.Metadata != null && (dbmeta == null || !dbmeta.Contains(entry.Metadata)))
                        Releases.Add(new CUEMetadataEntry(entry.Metadata, TOC, "local"));
            }

            bool ctdbFound = false;
            if (useCTDB)
            {
                ShowProgress("Looking up album via CTDB...", 0.0, null, null);
                var ctdb = new CUEToolsDB(TOC, proxy);
                ctdb.ContactDB(_config.advanced.CTDBServer, "CUETools " + CUEToolsVersion, null, false, false, metadataSearch);
                foreach (var meta in ctdb.Metadata)
                {
                    CUEMetadata metadata = new CUEMetadata(TOC.TOCID, (int)TOC.AudioTracks);
                    metadata.FillFromCtdb(meta, TOC.FirstAudio - 1);
                    CDImageLayout toc = TOC; //  TocFromCDEntry(meta);
                    Releases.Add(new CUEMetadataEntry(metadata, toc, meta.source));
                    ctdbFound = true;
                }
            }

            if (!ctdbFound && metadataSearch == CTDBMetadataSearch.Extensive)
            {
                ShowProgress("Looking up album via Freedb...", 0.0, null, null);

                FreedbHelper m_freedb = new FreedbHelper();
                m_freedb.Proxy = proxy;
                m_freedb.UserName = _config.advanced.FreedbUser;
                m_freedb.Hostname = _config.advanced.FreedbDomain;
                m_freedb.ClientName = "CUETools";
                m_freedb.Version = CUEToolsVersion;
                m_freedb.SetDefaultSiteAddress("freedb.org");

                QueryResult queryResult;
                QueryResultCollection coll;
                string code = string.Empty;
                try
                {
                    CDEntry cdEntry = null;
                    code = m_freedb.Query(AccurateRipVerify.CalculateCDDBQuery(_toc), out queryResult, out coll);
                    if (code == FreedbHelper.ResponseCodes.CODE_200)
                    {
                        ShowProgress("Looking up album via Freedb... " + queryResult.Discid, 0.5, null, null);
                        code = m_freedb.Read(queryResult, out cdEntry);
                        if (code == FreedbHelper.ResponseCodes.CODE_210)
                        {
                            CUEMetadata metadata = new CUEMetadata(TOC.TOCID, (int)TOC.AudioTracks);
                            metadata.FillFromFreedb(cdEntry, TOC.FirstAudio - 1);
                            CDImageLayout toc = TocFromCDEntry(cdEntry);
                            Releases.Add(new CUEMetadataEntry(metadata, toc, "freedb"));
                        }
                    }
                    else
                        if (code == FreedbHelper.ResponseCodes.CODE_210 ||
                            code == FreedbHelper.ResponseCodes.CODE_211)
                        {
                            int i = 0;
                            foreach (QueryResult qr in coll)
                            {
                                ShowProgress("Looking up album via freedb... " + qr.Discid, (++i + 0.0) / coll.Count, null, null);
                                CheckStop();
                                code = m_freedb.Read(qr, out cdEntry);
                                if (code == FreedbHelper.ResponseCodes.CODE_210)
                                {
                                    CUEMetadata metadata = new CUEMetadata(TOC.TOCID, (int)TOC.AudioTracks);
                                    metadata.FillFromFreedb(cdEntry, TOC.FirstAudio - 1);
                                    CDImageLayout toc = TocFromCDEntry(cdEntry);
                                    Releases.Add(new CUEMetadataEntry(metadata, toc, "freedb"));
                                }
                            }
                        }
                }
                catch (Exception ex)
                {
                    if (ex is StopException)
                        throw ex;
                }
            }

            ShowProgress("", 0, null, null);
            return Releases;
        }
Esempio n. 6
0
 public void CopyMetadata(CUEMetadata metadata)
 {
     if (this.cueMetadata == null)
         this.cueMetadata = new CUEMetadata(TOC.TOCID, (int)TOC.AudioTracks);
     this.cueMetadata.CopyMetadata(metadata);
 }
Esempio n. 7
0
 public void OpenCD(ICDRipper ripper)
 {
     _ripper = ripper;
     _toc = (CDImageLayout)_ripper.TOC.Clone();
     for (int iTrack = 0; iTrack < _toc.AudioTracks; iTrack++)
     {
         _trackFilenames.Add(string.Format("{0:00}.wav", iTrack + 1));
         _tracks.Add(new TrackInfo());
     }
     cueMetadata = new CUEMetadata(TOC.TOCID, (int)TOC.AudioTracks);
     _arVerify = new AccurateRipVerify(_toc, proxy);
     _isCD = true;
     SourceInfo cdInfo;
     cdInfo.Path = _ripper.ARName;
     cdInfo.Offset = 0;
     cdInfo.Length = _toc.AudioLength * 588;
     _sources.Add(cdInfo);
     // Causes memory leak, so had to disable!
     //_ripper.ReadProgress += new EventHandler<ReadProgressArgs>(CDReadProgress);
     _padding += TrackCount * 200;
     _padding += _config.embedLog ? 500 + TrackCount * 200 : 0;
 }
Esempio n. 8
0
        public void OpenCUE(TextReader sr)
        {
            string pathAudio = null;
            string lineStr, command, fileType;
            bool fileIsBinary = false;
            int timeRelativeToFileStart, absoluteFileStartTime = 0;
            int fileTimeLengthSamples = 0, fileTimeLengthFrames = 0, i;
            TagLib.File _trackFileInfo = null;
            bool seenFirstFileIndex = false;
            bool isAudioTrack = true;
            List<IndexInfo> indexes = new List<IndexInfo>();
            IndexInfo indexInfo;
            SourceInfo sourceInfo;
            TrackInfo trackInfo = null;
            int trackNumber = 0;

            using (sr)
            {
                while ((lineStr = sr.ReadLine()) != null)
                {
                    CUELine line = new CUELine(lineStr);
                    if (line.Params.Count > 0)
                    {
                        command = line.Params[0].ToUpper();

                        if (command == "FILE")
                        {
                            fileType = line.Params[2].ToUpper();
                            fileIsBinary = (fileType == "BINARY") || (fileType == "MOTOROLA");
                            if (fileIsBinary)
                            {
                                if (!_hasEmbeddedCUESheet && _sourcePaths.Count == 0)
                                {
                                    try
                                    {
                                        if (_isArchive)
                                            pathAudio = FileLocator.LocateFile(_archiveCUEpath, line.Params[1], _archiveContents);
                                        else
                                            pathAudio = FileLocator.LocateFile(_inputDir, line.Params[1], null);
                                        fileIsBinary = (pathAudio == null);
                                    }
                                    catch { }
                                }
                            }
                            if (!fileIsBinary)
                            {
                                if (_sourcePaths.Count != 0 && !seenFirstFileIndex)
                                    throw new Exception("Double FILE in CUE sheet: \"" + line.Params[1] + "\".");
                                if (!_hasEmbeddedCUESheet)
                                {
                                    if (_isArchive)
                                        pathAudio = FileLocator.LocateFile(_archiveCUEpath, line.Params[1], _archiveContents);
                                    else
                                        pathAudio = FileLocator.LocateFile(_inputDir, line.Params[1], null);
                                }
                                else
                                {
                                    pathAudio = _inputPath;
                                    if (_sourcePaths.Count > 0)
                                        throw new Exception("Extra file in embedded CUE sheet: \"" + line.Params[1] + "\".");
                                }

                                if (pathAudio == null)
                                {
                                    throw new Exception("Unable to locate file \"" + line.Params[1] + "\".");
                                    //fileTimeLengthFrames = 75 * 60 * 70;;
                                    //fileTimeLengthSamples = fileTimeLengthFrames * 588;
                                    //if (_hasEmbeddedCUESheet)
                                    //    _fileInfo = null;
                                    //else
                                    //    _trackFileInfo = null;
                                }
                                else
                                {
                                    // Wierd case: audio file after data track with only index 00 specified.
                                    if (!isAudioTrack && _sourcePaths.Count == 0 && indexes.Count > 0 && indexes[indexes.Count - 1].Index == 0)
                                    {
                                        indexInfo.Track = indexes[indexes.Count - 1].Track;
                                        indexInfo.Index = 1;
                                        indexInfo.Time = indexes[indexes.Count - 1].Time + 150;
                                        indexes.Add(indexInfo);
                                        absoluteFileStartTime += 150;
                                    }

                                    TagLib.File fileInfo;
                                    _sourcePaths.Add(pathAudio);
                                    absoluteFileStartTime += fileTimeLengthFrames;
                                    fileTimeLengthSamples = GetSampleLength(pathAudio, out fileInfo);
                                    if ((fileTimeLengthSamples % 588) == 492 && _config.truncate4608ExtraSamples)
                                    {
                                        _truncated4608 = true;
                                        fileTimeLengthSamples -= 4608;
                                    }
                                    fileTimeLengthFrames = (int)((fileTimeLengthSamples + 587) / 588);
                                    if (_hasEmbeddedCUESheet)
                                        _fileInfo = fileInfo;
                                    else
                                        _trackFileInfo = fileInfo;
                                }
                                seenFirstFileIndex = false;
                            }
                        }
                        else if (command == "TRACK")
                        {
                            isAudioTrack = line.Params[2].ToUpper() == "AUDIO";
                            trackNumber = int.Parse(line.Params[1]);
                            if (trackNumber != _toc.TrackCount + 1)
                                throw new Exception("Invalid track number");
                            // Disabled this check: fails on Headcandy test image
                            //if (isAudioTrack && _sourcePaths.Count == 0)
                            //    throw new Exception("No FILE seen before TRACK");
                            _toc.AddTrack(new CDTrack((uint)trackNumber, 0, 0, isAudioTrack, false));
                            if (isAudioTrack)
                            {
                                trackInfo = new TrackInfo();
                                _tracks.Add(trackInfo);
                            }
                        }
                        else if (command == "INDEX")
                        {
                            timeRelativeToFileStart = CDImageLayout.TimeFromString(line.Params[2]);
                            if (!seenFirstFileIndex)
                            {
                                if (timeRelativeToFileStart != 0)
                                    throw new Exception("First index must start at file beginning.");
                                seenFirstFileIndex = true;
                                if (isAudioTrack)
                                {
                                    if (_tracks.Count > 0 && _trackFileInfo != null)
                                        _tracks[_tracks.Count - 1]._fileInfo = _trackFileInfo;
                                    _trackFileInfo = null;
                                    sourceInfo.Path = pathAudio;
                                    sourceInfo.Offset = 0;
                                    sourceInfo.Length = (uint)fileTimeLengthSamples;
                                    _sources.Add(sourceInfo);
                                    if ((fileTimeLengthSamples % 588) != 0)
                                    {
                                        sourceInfo.Path = null;
                                        sourceInfo.Offset = 0;
                                        sourceInfo.Length = (uint)((fileTimeLengthFrames * 588) - fileTimeLengthSamples);
                                        _sources.Add(sourceInfo);
                                        _paddedToFrame = true;
                                    }
                                }
                            }
                            else
                            {
                                if (fileIsBinary)
                                {
                                    fileTimeLengthFrames = timeRelativeToFileStart + 150;
                                    sourceInfo.Path = null;
                                    sourceInfo.Offset = 0;
                                    sourceInfo.Length = 150 * 588;
                                    _sources.Add(sourceInfo);
                                    //throw new Exception("unexpected BINARY directive");
                                }
                                else
                                {
                                    if (timeRelativeToFileStart > fileTimeLengthFrames)
                                        throw new Exception(string.Format("TRACK {0} INDEX {1} is at {2}, which is past {3} - the end of source file {4}", trackNumber, line.Params[1], CDImageLayout.TimeToString((uint)timeRelativeToFileStart), CDImageLayout.TimeToString((uint)fileTimeLengthFrames), pathAudio));
                                }
                            }
                            indexInfo.Track = trackNumber;
                            indexInfo.Index = Int32.Parse(line.Params[1]);
                            indexInfo.Time = absoluteFileStartTime + timeRelativeToFileStart;
                            indexes.Add(indexInfo);
                        }
                        else if (!isAudioTrack)
                        {
                            // Ignore lines belonging to data tracks
                        }
                        else if (command == "PREGAP")
                        {
                            if (seenFirstFileIndex)
                                throw new Exception("Pregap must occur at the beginning of a file.");
                            int pregapLength = CDImageLayout.TimeFromString(line.Params[1]);
                            indexInfo.Track = trackNumber;
                            indexInfo.Index = 0;
                            indexInfo.Time = absoluteFileStartTime;
                            indexes.Add(indexInfo);
                            sourceInfo.Path = null;
                            sourceInfo.Offset = 0;
                            sourceInfo.Length = (uint)pregapLength * 588;
                            _sources.Add(sourceInfo);
                            absoluteFileStartTime += pregapLength;
                        }
                        else if (command == "POSTGAP")
                        {
                            throw new Exception("POSTGAP command isn't supported.");
                        }
                        //else if ((command == "REM") &&
                        //    (line.Params.Count >= 3) &&
                        //    (line.Params[1].Length >= 10) &&
                        //    (line.Params[1].Substring(0, 10).ToUpper() == "REPLAYGAIN"))
                        //{
                        //    // Remove ReplayGain lines
                        //}
                        else if ((command == "REM") &&
                           (line.Params.Count == 3) &&
                           (line.Params[1].ToUpper() == "ACCURATERIPID"))
                        {
                            _accurateRipId = line.Params[2];
                        }
                        //else if ((command == "REM") &&
                        //   (line.Params.Count == 3) &&
                        //   (line.Params[1].ToUpper() == "SHORTEN"))
                        //{
                        //    fileTimeLengthFrames -= General.TimeFromString(line.Params[2]);
                        //}							
                        //else if ((command == "REM") &&
                        //   (line.Params.Count == 3) &&
                        //   (line.Params[1].ToUpper() == "LENGTHEN"))
                        //{
                        //    fileTimeLengthFrames += General.TimeFromString(line.Params[2]);
                        //}							
                        else
                        {
                            if (trackInfo != null)
                            {
                                trackInfo.Attributes.Add(line);
                            }
                            else
                            {
                                if (line.Params.Count > 2 && !line.IsQuoted[1] &&
                                    (line.Params[0].ToUpper() == "TITLE" || line.Params[0].ToUpper() == "ARTIST" ||
                                    (line.Params[0].ToUpper() == "REM" && (line.Params[1].ToUpper() == "GENRE" || line.Params[1].ToUpper() == "COMMENT") && line.Params.Count > 3 && !line.IsQuoted[2])))
                                {
                                    CUELine modline = new CUELine();
                                    int nParams = line.Params[0].ToUpper() == "REM" ? 2 : 1;
                                    for (int iParam = 0; iParam < nParams; iParam++)
                                    {
                                        modline.Params.Add(line.Params[iParam]);
                                        modline.IsQuoted.Add(false);
                                    }
                                    string s = line.Params[nParams];
                                    for (int iParam = nParams + 1; iParam < line.Params.Count; iParam++)
                                        s += " " + line.Params[iParam];
                                    modline.Params.Add(s);
                                    modline.IsQuoted.Add(true);
                                    line = modline;
                                }
                                _attributes.Add(line);
                            }
                        }
                    }
                }
                sr.Close();
            }

            if (_tracks.Count == 0)
                throw new Exception("File must contain at least one audio track.");

            // Add dummy index 01 for data track
            if (!_toc[_toc.TrackCount].IsAudio && indexes[indexes.Count - 1].Index == 0)
            {
                fileTimeLengthFrames += 152 * 75;
                indexInfo.Track = trackNumber;
                indexInfo.Index = 1;
                indexInfo.Time = absoluteFileStartTime + fileTimeLengthFrames;
                indexes.Add(indexInfo);
            }

            // Add dummy track for calculation purposes
            indexInfo.Track = trackNumber + 1;
            indexInfo.Index = 1;
            indexInfo.Time = absoluteFileStartTime + fileTimeLengthFrames;
            indexes.Add(indexInfo);

            // Calculate the length of each index
            for (i = 0; i < indexes.Count - 1; i++)
            {
                if (indexes[i + 1].Time - indexes[i].Time < 0)
                    throw new Exception("Indexes must be in chronological order.");
                if ((indexes[i + 1].Track != indexes[i].Track || indexes[i + 1].Index != indexes[i].Index + 1) &&
                    (indexes[i + 1].Track != indexes[i].Track + 1 || indexes[i].Index < 1 || indexes[i + 1].Index > 1))
                    throw new Exception("Indexes must be in chronological order.");
                if (indexes[i].Index == 1 && (i == 0 || indexes[i - 1].Index != 0))
                    _toc[indexes[i].Track].AddIndex(new CDTrackIndex(0U, (uint)indexes[i].Time));
                _toc[indexes[i].Track].AddIndex(new CDTrackIndex((uint)indexes[i].Index, (uint)indexes[i].Time));
            }

            // Calculate the length of each track
            for (int iTrack = 1; iTrack <= _toc.TrackCount; iTrack++)
            {
                _toc[iTrack].Start = _toc[iTrack][1].Start;
                _toc[iTrack].Length = iTrack == _toc.TrackCount
                    ? (uint)indexes[indexes.Count - 1].Time - _toc[iTrack].Start
                    : _toc[iTrack + 1].IsAudio
                        ? _toc[iTrack + 1][1].Start - _toc[iTrack].Start
                        : _toc[iTrack + 1][0].Start - _toc[iTrack].Start;

            }

            // Store the audio filenames, generating generic names if necessary
            _hasSingleFilename = _sourcePaths.Count == 1;
            _singleFilename = _hasSingleFilename ? Path.GetFileName(_sourcePaths[0]) :
                "Range.wav";

            _hasHTOAFilename = (_sourcePaths.Count == (TrackCount + 1));
            _htoaFilename = _hasHTOAFilename ? Path.GetFileName(_sourcePaths[0]) : "00.wav";

            _hasTrackFilenames = !_hasEmbeddedCUESheet && !_hasSingleFilename && (_sourcePaths.Count == TrackCount || _hasHTOAFilename);
            for (i = 0; i < TrackCount; i++)
            {
                _trackFilenames.Add(_hasTrackFilenames ? Path.GetFileName(
                    _sourcePaths[i + (_hasHTOAFilename ? 1 : 0)]) : String.Format("{0:00}.wav", i + 1));
            }
            if (!_hasEmbeddedCUESheet && _hasSingleFilename)
            {
                _fileInfo = _tracks[0]._fileInfo;
                _tracks[0]._fileInfo = null;
            }
            taglibMetadata = new CUEMetadata(TOC.TOCID, (int)TOC.AudioTracks);
            taglibMetadata.Artist = GetCommonTag(file => file.Tag.JoinedAlbumArtists) ?? GetCommonTag(file => file.Tag.JoinedPerformers) ?? "";
            taglibMetadata.Title = GetCommonTag(file => file.Tag.Album) ?? "";
            taglibMetadata.Year = GetCommonTag(file => file.Tag.Year != 0 ? file.Tag.Year.ToString() : null) ?? "";
            taglibMetadata.Genre = GetCommonTag(file => file.Tag.JoinedGenres) ?? "";
            taglibMetadata.Comment = GetCommonTag(file => file.Tag.Comment) ?? "";
            taglibMetadata.TotalDiscs = GetCommonTag(file => file.Tag.DiscCount != 0 ? file.Tag.DiscCount.ToString() : null) ?? "";
            taglibMetadata.DiscNumber = GetCommonTag(file => file.Tag.Disc != 0 ? file.Tag.Disc.ToString() : null) ?? "";
			taglibMetadata.ReleaseDate = GetCommonTag(file => file.Tag.ReleaseDate) ?? "";
			taglibMetadata.Country = GetCommonTag(file => file.Tag.MusicBrainzReleaseCountry) ?? "";
			taglibMetadata.Label = GetCommonTag(file => file.Tag.Publisher) ?? "";
			taglibMetadata.LabelNo = GetCommonTag(file => file.Tag.CatalogNo) ?? "";
			taglibMetadata.DiscName = GetCommonTag(file => file.Tag.DiscSubtitle) ?? "";
            for (i = 0; i < TrackCount; i++)
            {
                TrackInfo track = _tracks[i];
                taglibMetadata.Tracks[i].Artist = (_hasTrackFilenames && track._fileInfo != null ? track._fileInfo.Tag.JoinedPerformers :
                    _hasEmbeddedCUESheet && _fileInfo != null ? Tagging.TagListToSingleValue(Tagging.GetMiscTag(_fileInfo, String.Format("cue_track{0:00}_ARTIST", i + 1))) :
                    null) ?? "";
                taglibMetadata.Tracks[i].Title = (_hasTrackFilenames && track._fileInfo != null ? track._fileInfo.Tag.Title :
                    _hasEmbeddedCUESheet && _fileInfo != null ? Tagging.TagListToSingleValue(Tagging.GetMiscTag(_fileInfo, String.Format("cue_track{0:00}_TITLE", i + 1))) :
                    null) ?? "";
				taglibMetadata.Tracks[i].Comment = (_hasTrackFilenames && track._fileInfo != null ? track._fileInfo.Tag.Title :
					_hasEmbeddedCUESheet && _fileInfo != null ? Tagging.TagListToSingleValue(Tagging.GetMiscTag(_fileInfo, String.Format("cue_track{0:00}_COMMENT", i + 1))) :
					null) ?? "";
			}

            cueMetadata = new CUEMetadata(TOC.TOCID, (int)TOC.AudioTracks);
            cueMetadata.Artist = General.GetCUELine(_attributes, "PERFORMER");
            cueMetadata.Title = General.GetCUELine(_attributes, "TITLE");
            cueMetadata.Barcode = General.GetCUELine(_attributes, "CATALOG");
            cueMetadata.Year = General.GetCUELine(_attributes, "REM", "DATE");
            cueMetadata.DiscNumber = General.GetCUELine(_attributes, "REM", "DISCNUMBER");
            cueMetadata.TotalDiscs = General.GetCUELine(_attributes, "REM", "TOTALDISCS");
            cueMetadata.Genre = General.GetCUELine(_attributes, "REM", "GENRE");
            cueMetadata.Comment = General.GetCUELine(_attributes, "REM", "COMMENT");
			cueMetadata.ReleaseDate = General.GetCUELine(_attributes, "REM", "RELEASEDATE");
			cueMetadata.Country = General.GetCUELine(_attributes, "REM", "COUNTRY");
			cueMetadata.Label = General.GetCUELine(_attributes, "REM", "LABEL");
			cueMetadata.LabelNo = General.GetCUELine(_attributes, "REM", "CATALOGNUMBER");
			cueMetadata.DiscName = General.GetCUELine(_attributes, "REM", "DISCSUBTITLE");
            for (i = 0; i < Tracks.Count; i++)
            {
                cueMetadata.Tracks[i].Artist = General.GetCUELine(Tracks[i].Attributes, "PERFORMER");
                cueMetadata.Tracks[i].Title = General.GetCUELine(Tracks[i].Attributes, "TITLE");
                cueMetadata.Tracks[i].ISRC = General.GetCUELine(Tracks[i].Attributes, "ISRC");
            }
            // Now, TOC.TOCID might change!!!

            if (_config.fillUpCUE)
            {
                cueMetadata.Merge(taglibMetadata, _config.overwriteCUEData);
                for (i = 0; i < TrackCount; i++)
                {
                    if (cueMetadata.Tracks[i].Title == "" && _hasTrackFilenames)
                        cueMetadata.Tracks[i].Title = Path.GetFileNameWithoutExtension(_trackFilenames[i]).TrimStart(" .-_0123456789".ToCharArray());
                }
            }

            CUELine cddbDiscIdLine = General.FindCUELine(_attributes, "REM", "DISCID");
            _cddbDiscIdTag = cddbDiscIdLine != null && cddbDiscIdLine.Params.Count == 3 ? cddbDiscIdLine.Params[2] : null;
            if (_cddbDiscIdTag == null)
                _cddbDiscIdTag = GetCommonMiscTag("DISCID");

            if (_accurateRipId == null)
                _accurateRipId = GetCommonMiscTag("ACCURATERIPID");

            if (_eacLog == null && _logFiles != null && _logFiles.Count > 0)
            {
                foreach (CUEToolsSourceFile sf in _logFiles)
                {
                    CDImageLayout tocFromLog1 = LogToTocParser.LogToToc(this._toc, sf.contents);
                    if (tocFromLog1 != null && tocFromLog1.TOCID == _toc.TOCID)
                    {
                        if (_eacLog == null)
                            _eacLog = sf.contents;
                        else
                        {
                            _eacLog = null;
                            break;
                        }
                    }
                }
            }

            if (_eacLog == null && _logFiles != null && _logFiles.Count > 0)
            {
                CUEToolsSourceFile selectedLogFile = ChooseFile(_logFiles, _defaultLog, false);
                _eacLog = selectedLogFile != null ? selectedLogFile.contents : null;
            }

            CDImageLayout tocFromLog = _eacLog == null ? null : LogToTocParser.LogToToc(this._toc, _eacLog);

            if (tocFromLog == null)
            {
                string tocPath = Path.ChangeExtension(InputPath, ".toc");
                if (File.Exists(tocPath))
                {
                    tocFromLog = LogToTocParser.LogToToc(this._toc, new StreamReader(tocPath, CUESheet.Encoding).ReadToEnd());
                }
            }

            // use pregaps from log
            if (tocFromLog != null)
            {
                //int srcNo = (int) _toc[_toc.FirstAudio].LastIndex - (PreGapLength == 0 ? 1 : 0);
                if (PreGapLength < tocFromLog.Pregap)
                {
                    PreGapLength = tocFromLog.Pregap;
                    //srcNo ++;
                }
                int trNo;
                for (trNo = 1; trNo < tocFromLog.AudioTracks && trNo < _toc.AudioTracks; trNo++)
                {
                    if (_toc[_toc.FirstAudio + trNo].Pregap < tocFromLog[tocFromLog.FirstAudio + trNo].Pregap)
                        _toc[_toc.FirstAudio + trNo].Pregap = tocFromLog[tocFromLog.FirstAudio + trNo].Pregap;
                }
                //if (_toc[_toc.FirstAudio].Length > tocFromLog[tocFromLog.FirstAudio].Length)
                //{
                //    uint offs = _toc[_toc.FirstAudio].Length - tocFromLog[tocFromLog.FirstAudio].Length;
                //    _toc[_toc.FirstAudio].Length -= offs;

                //    sourceInfo = _sources[srcNo];
                //    sourceInfo.Length -= offs * 588;
                //    _sources[srcNo] = sourceInfo;
                //    for (i = _toc.FirstAudio + 1; i <= _toc.TrackCount; i++)
                //    {
                //        _toc[i].Start -= offs;
                //        for (int j = 0; j <= _toc[i].LastIndex; j++)
                //            if (i != _toc.FirstAudio + 1 || j != 0 || _toc[i][0].Start == _toc[i][1].Start)
                //                _toc[i][j].Start -= offs;
                //    }
                //}
                //for (trNo = 1; trNo < tocFromLog.AudioTracks && trNo < _toc.AudioTracks; trNo++)
                //{
                //    srcNo ++;
                //    if (_toc[_toc.FirstAudio + trNo].Length > tocFromLog[tocFromLog.FirstAudio + trNo].Length)
                //    {
                //        uint offs = _toc[_toc.FirstAudio + trNo].Length - tocFromLog[tocFromLog.FirstAudio + trNo].Length;
                //        _toc[_toc.FirstAudio + trNo].Length -= offs;
                //        sourceInfo = _sources[srcNo];
                //        sourceInfo.Length -= offs * 588;
                //        _sources[srcNo] = sourceInfo;
                //        for (i = _toc.FirstAudio + trNo + 1; i <= _toc.TrackCount; i++)
                //        {
                //            _toc[i].Start -= offs;
                //            for (int j = 0; j <= _toc[i].LastIndex; j++)
                //                if (i != _toc.FirstAudio + trNo + 1 || j != 0 || _toc[i][0].Start == _toc[i][1].Start)
                //                    _toc[i][j].Start -= offs;
                //        }
                //    }
                //}
            }

            // use data track length from log
            if (tocFromLog != null)
            {
                if (tocFromLog.AudioTracks == _toc.AudioTracks
                    && tocFromLog.TrackCount == tocFromLog.AudioTracks + 1
                    && !tocFromLog[tocFromLog.TrackCount].IsAudio)
                {
                    DataTrackLength = tocFromLog[tocFromLog.TrackCount].Length;
                    _toc[_toc.TrackCount].Start = tocFromLog[_toc.TrackCount].Start;
                    _toc[_toc.TrackCount][0].Start = tocFromLog[_toc.TrackCount].Start;
                    _toc[_toc.TrackCount][1].Start = tocFromLog[_toc.TrackCount].Start;
                }
                if (_toc.TrackCount == _toc.AudioTracks
                    && tocFromLog.TrackCount == tocFromLog.AudioTracks
                    && tocFromLog.TrackCount > _toc.TrackCount)
                {
                    int dtracks = tocFromLog.TrackCount - _toc.TrackCount;
                    bool matches = true;
                    for (int iTrack = 1; iTrack <= _toc.TrackCount; iTrack++)
                        if (tocFromLog[iTrack + dtracks].Length != _toc[iTrack].Length)
                            matches = false;
                    if (matches)
                    {
                        for (int iTrack = 1; iTrack <= dtracks; iTrack++)
                        {
                            _toc.InsertTrack(new CDTrack((uint)iTrack, 0, 0, false, false));
                            tocFromLog[iTrack].IsAudio = false;
                        }
                        tocFromLog.FirstAudio += dtracks;
                        tocFromLog.AudioTracks -= (uint)dtracks;
                    }
                }
                if (tocFromLog.AudioTracks == _toc.AudioTracks
                    && tocFromLog.TrackCount == _toc.TrackCount
                    && tocFromLog.FirstAudio == _toc.FirstAudio
                    && tocFromLog.TrackCount == tocFromLog.FirstAudio + tocFromLog.AudioTracks - 1)
                {
                    //DataTrackLength = tocFromLog[1].Length;
                    uint delta = tocFromLog[_toc.FirstAudio].Start - _toc[_toc.FirstAudio].Start;
                    for (int itr = 1; itr < _toc.FirstAudio; itr++)
                    {
                        _toc[itr].Start = tocFromLog[itr].Start;
                        _toc[itr].Length = tocFromLog[itr].Length;
                    }
                    for (int itr = _toc.FirstAudio; itr <= _toc.TrackCount; itr++)
                    {
                        _toc[itr].Start += delta;
                        for (int j = 0; j <= _toc[itr].LastIndex; j++)
                            _toc[itr][j].Start += delta;
                    }
                }
            }

            // use data track length range from cddbId
            if (DataTrackLength == 0 && _cddbDiscIdTag != null)
            {
                uint cddbDiscIdNum;
                if (uint.TryParse(_cddbDiscIdTag, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out cddbDiscIdNum) && (cddbDiscIdNum & 0xff) == _toc.AudioTracks + 1)
                {
                    if (_toc.TrackCount == _toc.AudioTracks)
                        _toc.AddTrack(new CDTrack((uint)_toc.TrackCount + 1, _toc.Length + 152 * 75, 0, false, false));
                    uint lengthFromTag = ((cddbDiscIdNum >> 8) & 0xffff);
                    _minDataTrackLength = (lengthFromTag + _toc[1].Start / 75) * 75 - _toc.Length;
                }
            }

            _arVerify = new AccurateRipVerify(_toc, proxy);

            if (_eacLog != null)
            {
                sr = new StringReader(_eacLog);
                bool isEACLog = false;
                int trNo = 1;
                while ((lineStr = sr.ReadLine()) != null)
                {
                    if (isEACLog && trNo <= TrackCount)
                    {
                        string[] s = { "Copy CRC ", "CRC копии" };
                        string[] s1 = { "CRC" };
                        string[] n = lineStr.Split(s, StringSplitOptions.None);
                        uint crc;
                        if (n.Length == 2 && uint.TryParse(n[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out crc))
                            _arVerify.CRCLOG(trNo++, crc);
                        else if (n.Length == 1)
                        {
                            n = lineStr.Split(s1, StringSplitOptions.None);
                            if (n.Length == 2 && n[0].Trim() == "" && uint.TryParse(n[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out crc))
                                _arVerify.CRCLOG(trNo++, crc);
                        }
                    }
                    else
                        if (lineStr.StartsWith("Exact Audio Copy")
                            || lineStr.StartsWith("EAC extraction logfile"))
                            isEACLog = true;
                }
                if (trNo == 2)
                {
                    _arVerify.CRCLOG(0, _arVerify.CRCLOG(1));
                    if (TrackCount > 1)
                        _arVerify.CRCLOG(1, 0);
                }
            }

            LoadAlbumArt(_tracks[0]._fileInfo ?? _fileInfo);
            ResizeAlbumArt();
            if (_config.embedAlbumArt || _config.CopyAlbumArt)
                _albumArt.ForEach(t => _padding += _albumArt[0].Data.Count);
            if (_config.embedLog && _eacLog != null)
                _padding += _eacLog.Length;

            cueMetadata.Id = TOC.TOCID;
            taglibMetadata.Id = TOC.TOCID;
            // TODO: It should also be set when assigning a DataTrack!!!
        }
Esempio n. 9
0
 public CUEMetadata(CUEMetadata src)
     : this(src.Id, src.Tracks.Count)
 {
     CopyMetadata(src);
 }
Esempio n. 10
0
 public void Merge(CUEMetadata metadata, bool overwrite)
 {
     if ((overwrite || TotalDiscs == "") && metadata.TotalDiscs != "")
     {
         TotalDiscs = metadata.TotalDiscs;
     }
     if ((overwrite || DiscNumber == "") && metadata.DiscNumber != "")
     {
         DiscNumber = metadata.DiscNumber;
     }
     if ((overwrite || DiscName == "") && metadata.DiscName != "")
     {
         DiscName = metadata.DiscName;
     }
     if ((overwrite || Comment == "") && metadata.Comment != "")
     {
         Comment = metadata.Comment;
     }
     if ((overwrite || Year == "") && metadata.Year != "")
     {
         Year = metadata.Year;
     }
     if ((overwrite || Genre == "") && metadata.Genre != "")
     {
         Genre = metadata.Genre;
     }
     if ((overwrite || Artist == "") && metadata.Artist != "")
     {
         Artist = metadata.Artist;
     }
     if ((overwrite || Title == "") && metadata.Title != "")
     {
         Title = metadata.Title;
     }
     if ((overwrite || Barcode == "") && metadata.Barcode != "")
     {
         Barcode = metadata.Barcode;
     }
     if ((overwrite || ReleaseDate == "") && metadata.ReleaseDate != "")
     {
         ReleaseDate = metadata.ReleaseDate;
     }
     if ((overwrite || Label == "") && metadata.Label != "")
     {
         Label = metadata.Label;
     }
     if ((overwrite || LabelNo == "") && metadata.LabelNo != "")
     {
         LabelNo = metadata.LabelNo;
     }
     if ((overwrite || Country == "") && metadata.Country != "")
     {
         Country = metadata.Country;
     }
     if ((overwrite || AlbumArt.Count == 0) && metadata.AlbumArt.Count != 0)
     {
         AlbumArt = metadata.AlbumArt;
     }
     for (int i = 0; i < Tracks.Count; i++)
     {
         if ((overwrite || Tracks[i].Title == "") && metadata.Tracks[i].Title != "")
         {
             Tracks[i].Title = metadata.Tracks[i].Title;
         }
         if ((overwrite || Tracks[i].Artist == "") && metadata.Tracks[i].Artist != "")
         {
             Tracks[i].Artist = metadata.Tracks[i].Artist;
         }
         if ((overwrite || Tracks[i].Comment == "") && metadata.Tracks[i].Artist != "")
         {
             Tracks[i].Comment = metadata.Tracks[i].Comment;
         }
         if ((overwrite || Tracks[i].ISRC == "") && metadata.Tracks[i].ISRC != "")
         {
             Tracks[i].ISRC = metadata.Tracks[i].ISRC;
         }
     }
 }
Esempio n. 11
0
 public CUEMetadataEntry(CUEMetadata metadata, CDImageLayout TOC, string key)
 {
     this.metadata = new CUEMetadata(metadata);
     this.TOC      = TOC;
     this.ImageKey = key;
 }
Esempio n. 12
0
		public CUEMetadata(CUEMetadata src)
			: this(src.Id, src.Tracks.Count)
		{
			CopyMetadata(src);
		}
Esempio n. 13
0
		public void CopyMetadata(CUEMetadata metadata)
		{
			// if (metadata.Tracks.Count != Tracks.Count) throw;
			// Tracks.Count = metadata.Tracks.Count;
			TotalDiscs = metadata.TotalDiscs;
			DiscNumber = metadata.DiscNumber;
			DiscName = metadata.DiscName;
            Comment = metadata.Comment;
			Year = metadata.Year;
			Genre = metadata.Genre;
			Artist = metadata.Artist;
			Title = metadata.Title;
			Barcode = metadata.Barcode;
			ReleaseDate = metadata.ReleaseDate;
			Country = metadata.Country;
			Label = metadata.Label;
            LabelNo = metadata.LabelNo;
            AlbumArt = metadata.AlbumArt;
			for (int i = 0; i < Tracks.Count; i++)
			{
				Tracks[i].Title = metadata.Tracks[i].Title;
				Tracks[i].Artist = metadata.Tracks[i].Artist;
				Tracks[i].Comment = metadata.Tracks[i].Comment;
				Tracks[i].ISRC = metadata.Tracks[i].ISRC;
			}
		}
Esempio n. 14
0
		public bool Contains(CUEMetadata metadata)
		{
			CUEMetadata sum = new CUEMetadata(metadata);
			sum.Merge(this, false);
			return sum.Equals(this);
		}
Esempio n. 15
0
		public void Merge(CUEMetadata metadata, bool overwrite)
		{
			if ((overwrite || TotalDiscs == "") && metadata.TotalDiscs != "") TotalDiscs = metadata.TotalDiscs;
			if ((overwrite || DiscNumber == "") && metadata.DiscNumber != "") DiscNumber = metadata.DiscNumber;
			if ((overwrite || DiscName == "") && metadata.DiscName != "") DiscName = metadata.DiscName;
            if ((overwrite || Comment == "") && metadata.Comment != "") Comment = metadata.Comment;
            if ((overwrite || Year == "") && metadata.Year != "") Year = metadata.Year;
			if ((overwrite || Genre == "") && metadata.Genre != "") Genre = metadata.Genre;
			if ((overwrite || Artist == "") && metadata.Artist != "") Artist = metadata.Artist;
			if ((overwrite || Title == "") && metadata.Title != "") Title = metadata.Title;
			if ((overwrite || Barcode == "") && metadata.Barcode != "") Barcode = metadata.Barcode;
			if ((overwrite || ReleaseDate == "") && metadata.ReleaseDate != "") ReleaseDate = metadata.ReleaseDate;
			if ((overwrite || Label == "") && metadata.Label != "") Label = metadata.Label;
            if ((overwrite || LabelNo == "") && metadata.LabelNo != "") LabelNo = metadata.LabelNo;
			if ((overwrite || Country == "") && metadata.Country != "") Country = metadata.Country;
            if ((overwrite || AlbumArt.Count == 0) && metadata.AlbumArt.Count != 0) AlbumArt = metadata.AlbumArt;
			for (int i = 0; i < Tracks.Count; i++)
			{
				if ((overwrite || Tracks[i].Title == "") && metadata.Tracks[i].Title != "") Tracks[i].Title = metadata.Tracks[i].Title;
				if ((overwrite || Tracks[i].Artist == "") && metadata.Tracks[i].Artist != "") Tracks[i].Artist = metadata.Tracks[i].Artist;
				if ((overwrite || Tracks[i].Comment == "") && metadata.Tracks[i].Artist != "") Tracks[i].Comment = metadata.Tracks[i].Comment;
				if ((overwrite || Tracks[i].ISRC == "") && metadata.Tracks[i].ISRC != "") Tracks[i].ISRC = metadata.Tracks[i].ISRC;
			}
		}
 public CUEMetadataEntry(CUEMetadata metadata, CDImageLayout TOC, string key)
 {
     this.metadata = new CUEMetadata(metadata);
     this.TOC = TOC;
     this.ImageKey = key;
 }