Example #1
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: ArCueDotNet <filename>");
                return;
            }
            string pathIn = args[0];
            if (!File.Exists(pathIn))
            {
                Console.WriteLine("Input CUE Sheet not found.");
                return;
            }
            CUEConfig config = new CUEConfig();
            config.writeArLogOnVerify = false;
            config.writeArTagsOnVerify = false;
            config.autoCorrectFilenames = true;
            config.extractAlbumArt = false;
            config.embedAlbumArt = false;

            string accurateRipLog;
            try
            {
                CUESheet cueSheet = new CUESheet(config);
                cueSheet.Action = CUEAction.Verify;
                //cueSheet.OutputStyle = CUEStyle.SingleFile;
                cueSheet.Open(pathIn);
                cueSheet.UseAccurateRip();
                cueSheet.GenerateFilenames(AudioEncoderType.NoAudio, "dummy", pathIn);
                cueSheet.Go();

                accurateRipLog = CUESheetLogWriter.GetAccurateRipLog(cueSheet);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                return;
            }

            Console.Write(accurateRipLog);
        }
        private void Lookup(object o)
        {
            ICDRipper audioSource = o as ICDRipper;
            int mbresults_count = 0; // have to cache results.Count, because it sometimes hangs in it, and we don't want UI thread to hang.
            string musicbrainzError = "";

            data.Releases.RaiseListChangedEvents = false;

            cueSheet = new CUESheet(_config);
            cueSheet.OpenCD(audioSource);
            cueSheet.Action = CUEAction.Encode;

            this.BeginInvoke((MethodInvoker)delegate() { toolStripStatusLabel1.Text = Properties.Resources.LookingUpVia + " CTDB..."; });
            cueSheet.UseCUEToolsDB("CUERipper " + CUESheet.CUEToolsVersion, selectedDriveInfo.drive.ARName, false, loadAllMetadata ? CTDBMetadataSearch.Extensive : _config.advanced.metadataSearch);
            cueSheet.CTDB.UploadHelper.onProgress += new EventHandler<Krystalware.UploadHelper.UploadProgressEventArgs>(UploadProgress);
            this.BeginInvoke((MethodInvoker)delegate() { toolStripStatusLabel1.Text = Properties.Resources.LookingUpVia + " AccurateRip..."; });
            cueSheet.UseAccurateRip();

            General.SetCUELine(cueSheet.Attributes, "REM", "DISCID", AccurateRipVerify.CalculateCDDBId(audioSource.TOC), false);

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

            foreach (var ctdbMeta in cueSheet.CTDB.Metadata)
            {
                data.Releases.Add(CreateCUESheet(audioSource, ctdbMeta));
            }

            if (data.Releases.Count == 0 || loadAllMetadata)
            {
                loadAllMetadata = false;

                //this.BeginInvoke((MethodInvoker)delegate() { toolStripStatusLabel1.Text = Properties.Resources.LookingUpVia + " MusicBrainz..."; });

                //ReleaseQueryParameters p = new ReleaseQueryParameters();
                //p.DiscId = audioSource.TOC.MusicBrainzId;
                //Query<Release> results = Release.Query(p);
                //MusicBrainzService.Proxy = _config.GetProxy();
                //MusicBrainzService.XmlRequest += new EventHandler<XmlRequestEventArgs>(MusicBrainz_LookupProgress);

                //try
                //{
                //    foreach (Release release in results)
                //    {
                //        release.GetEvents();
                //        release.GetTracks();
                //        data.Releases.Add(CreateCUESheet(audioSource, release));
                //    }
                //    mbresults_count = results.Count;
                //}
                //catch (Exception ex)
                //{
                //    System.Diagnostics.Trace.WriteLine(ex.Message);
                //    if (!(ex is MusicBrainzNotFoundException))
                //        musicbrainzError = ex.Message;
                //}
                //MusicBrainzService.Proxy = null;
                //MusicBrainzService.XmlRequest -= new EventHandler<XmlRequestEventArgs>(MusicBrainz_LookupProgress);

                this.BeginInvoke((MethodInvoker)delegate() { toolStripStatusLabel1.Text = Properties.Resources.LookingUpVia + " Freedb..."; });

                FreedbHelper m_freedb = new FreedbHelper();
                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;
                m_freedb.SetDefaultSiteAddress(Properties.Settings.Default.MAIN_FREEDB_SITEADDRESS);

                QueryResult queryResult;
                QueryResultCollection coll;
                string code = string.Empty;
                try
                {
                    FreeDB_LookupProgress(this);
                    code = m_freedb.Query(AccurateRipVerify.CalculateCDDBQuery(audioSource.TOC), out queryResult, out coll);
                    if (code == FreedbHelper.ResponseCodes.CODE_200)
                    {
                        bool duplicate = false;
                        foreach (var ctdbMeta in cueSheet.CTDB.Metadata)
                            if (ctdbMeta.source == "freedb" && ctdbMeta.id == queryResult.Category + "/" + queryResult.Discid)
                                duplicate = true;
                        if (!duplicate)
                        {
                            FreeDB_LookupProgress(queryResult.Category + "/" + queryResult.Discid);
                            CDEntry cdEntry;
                            code = m_freedb.Read(queryResult, out cdEntry);
                            if (code == FreedbHelper.ResponseCodes.CODE_210)
                            {
                                CUEMetadataEntry r = CreateCUESheet(audioSource, cdEntry);
                                data.Releases.Add(r);
                            }
                        }
                    }
                    else
                        if (code == FreedbHelper.ResponseCodes.CODE_210 ||
                            code == FreedbHelper.ResponseCodes.CODE_211)
                        {
                            foreach (QueryResult qr in coll)
                            {
                                bool duplicate = false;
                                foreach (var ctdbMeta in cueSheet.CTDB.Metadata)
                                    if (ctdbMeta.source == "freedb" && ctdbMeta.id == qr.Category + "/" + qr.Discid)
                                        duplicate = true;
                                if (!duplicate)
                                {
                                    CDEntry cdEntry;
                                    FreeDB_LookupProgress(qr.Category + "/" + qr.Discid);
                                    code = m_freedb.Read(qr, out cdEntry);
                                    if (code == FreedbHelper.ResponseCodes.CODE_210)
                                    {
                                        CUEMetadataEntry r = CreateCUESheet(audioSource, cdEntry);
                                        data.Releases.Add(r);
                                    }
                                }
                            }
                        }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex.Message);
                }
            }

            if (data.Releases.Count == 0)
            {
                data.Releases.Add(CreateCUESheet(audioSource));
            }
            _workThread = null;
            if (musicbrainzError != "")
                musicbrainzError = musicbrainzError + ": ";
            while (backgroundWorkerArtwork.IsBusy)
            {
                Thread.Sleep(100);
            }
            this.BeginInvoke((MethodInvoker)delegate()
            {
                SetupControls();
                data.Releases.RaiseListChangedEvents = true;
                data.Releases.ResetBindings();
                //bnComboBoxRelease.SelectedIndex = 0;
                toolStripStatusAr.Enabled = cueSheet.ArVerify.ARStatus == null;
                toolStripStatusAr.Text = cueSheet.ArVerify.ARStatus == null ? cueSheet.ArVerify.WorstTotal().ToString() : "";
                toolStripStatusAr.ToolTipText = "AccurateRip: " + (cueSheet.ArVerify.ARStatus ?? "found") + ".";
                toolStripStatusCTDB.Enabled = cueSheet.CTDB.DBStatus == null;
                toolStripStatusCTDB.Text = cueSheet.CTDB.DBStatus == null ? cueSheet.CTDB.Total.ToString() : "";
                toolStripStatusCTDB.ToolTipText = "CUETools DB: " + (cueSheet.CTDB.DBStatus ?? "found") + ".";
                toolStripStatusLabelMusicBrainz.Enabled = true;
                toolStripStatusLabelMusicBrainz.BorderStyle = mbresults_count > 0 ? Border3DStyle.SunkenInner : Border3DStyle.RaisedInner;
                toolStripStatusLabelMusicBrainz.Text = mbresults_count > 0 ? mbresults_count.ToString() : "";
                toolStripStatusLabelMusicBrainz.ToolTipText = "Musicbrainz: " + (mbresults_count > 0 ? mbresults_count.ToString() + " entries found." : (musicbrainzError + "click to submit."));
                if (_config.advanced.coversSearch != CUEConfigAdvanced.CTDBCoversSearch.None)
                    backgroundWorkerArtwork.RunWorkerAsync(new BackgroundWorkerArtworkArgs() { cueSheet = cueSheet, meta = data.selectedRelease });
            });
        }