CTDB metadata support

This commit is contained in:
chudov
2011-05-15 17:41:14 +00:00
parent a6941bc51b
commit d5fdd19735
20 changed files with 1246 additions and 572 deletions

View File

@@ -45,6 +45,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="FormMetadata.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FormMetadata.Designer.cs">
<DependentUpon>FormMetadata.cs</DependentUpon>
</Compile>
<Compile Include="Metadata.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Options.cs">
<SubType>Form</SubType>
@@ -55,6 +62,9 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="FormMetadata.resx">
<DependentUpon>FormMetadata.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Options.resx">
<DependentUpon>Options.cs</DependentUpon>
</EmbeddedResource>

View File

@@ -0,0 +1,110 @@
namespace CUETools.CTDB.EACPlugin
{
partial class FormMetadata
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// progressBar1
//
this.progressBar1.Dock = System.Windows.Forms.DockStyle.Top;
this.progressBar1.Location = new System.Drawing.Point(10, 198);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(587, 23);
this.progressBar1.Style = System.Windows.Forms.ProgressBarStyle.Marquee;
this.progressBar1.TabIndex = 0;
//
// backgroundWorker1
//
this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted);
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1});
this.listView1.Dock = System.Windows.Forms.DockStyle.Top;
this.listView1.FullRowSelect = true;
this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
this.listView1.HideSelection = false;
this.listView1.Location = new System.Drawing.Point(10, 10);
this.listView1.MultiSelect = false;
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(587, 188);
this.listView1.TabIndex = 1;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseDoubleClick);
//
// columnHeader1
//
this.columnHeader1.Text = "Album";
//
// button1
//
this.button1.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button1.Location = new System.Drawing.Point(519, 204);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 2;
this.button1.Text = "Cancel";
this.button1.UseVisualStyleBackColor = true;
this.button1.Visible = false;
//
// FormMetadata
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.button1;
this.ClientSize = new System.Drawing.Size(607, 233);
this.Controls.Add(this.button1);
this.Controls.Add(this.progressBar1);
this.Controls.Add(this.listView1);
this.Name = "FormMetadata";
this.Padding = new System.Windows.Forms.Padding(10);
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "CTDB Metadata Lookup";
this.Load += new System.EventHandler(this.FormMetadata_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ProgressBar progressBar1;
private System.ComponentModel.BackgroundWorker backgroundWorker1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.Button button1;
}
}

View File

@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CUETools.CTDB.EACPlugin
{
public partial class FormMetadata : Form
{
private CUEToolsDB ctdb;
private CTDBResponseMeta meta;
private string agent;
public FormMetadata(CUEToolsDB ctdb, string agent)
{
this.ctdb = ctdb;
this.agent = agent;
this.InitializeComponent();
}
public CTDBResponseMeta Meta
{
get
{
return this.meta;
}
}
private void FormMetadata_Load(object sender, EventArgs e)
{
this.backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
this.ctdb.ContactDB(this.agent, null, true, false);
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.progressBar1.Visible = false;
this.button1.Visible = true;
CTDBResponseMeta bestMeta = null;
foreach (var metadata in ctdb.Metadata)
{
bestMeta = metadata;
uint td = 0, dn = 0;
var disccount = metadata.disccount ?? "1";
var discnumber = metadata.discnumber ?? "1";
var discnumber01 = (uint.TryParse(disccount, out td) && uint.TryParse(discnumber, out dn) && td > 9 && dn > 0) ?
string.Format("{0:00}", dn) : discnumber;
var discnumberandtotal = disccount != "1" ? discnumber01 + "/" + disccount : (discnumber != "1" ? discnumber01 : "");
var label = metadata.country ?? "";
if (metadata.label != null)
foreach (var l in metadata.label)
label = (label == "" ? "" : label + ": ") + (l.name ?? "") + (l.name != null && l.catno != null ? " " : "") + (l.catno ?? "");
var text = string.Format("{0}{1} - {2}{3}{4}", metadata.year != null ? metadata.year + ": " : "",
metadata.artist == null ? "Unknown Artist" : metadata.artist,
metadata.album == "" ? "Unknown Title" : metadata.album,
discnumberandtotal != "" ? " (disc " + discnumberandtotal + (metadata.discname != null ? ": " + metadata.discname : "") + ")" : "",
label == "" ? "" : " (" + label + ")");
listView1.Items.Add(new ListViewItem(text) { Tag = metadata });
}
this.listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
this.meta = bestMeta;
if (listView1.Items.Count < 2)
this.Close();
}
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
var ht = listView1.HitTest(e.Location);
if (ht.Item != null)
{
meta = ht.Item.Tag as CTDBResponseMeta;
this.Close();
}
}
}
}

View File

@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@@ -0,0 +1,123 @@
using System;
using System.Collections.Generic;
using System.Text;
using HelperFunctionsLib;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Net;
using System.IO;
using CUETools.CDImage;
using CUETools.AccurateRip;
using CUETools.Codecs;
using CUETools.CTDB;
namespace MetadataPlugIn
{
[Guid("8271734A-126F-44e9-AC9C-836449B39E51"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(IMetadataRetriever)),
]
public class MetadataRetriever : IMetadataRetriever
{
public bool GetCDInformation(CCDMetadata data, bool cdinfo, bool cover, bool lyrics)
{
if (!cdinfo)
return false;
var TOC = new CDImageLayout();
for (int i = 0; i < data.NumberOfTracks; i++)
{
uint start = data.GetTrackStartPosition(i);
uint next = data.GetTrackEndPosition(i);
TOC.AddTrack(new CDTrack(
(uint)i + 1,
start,
next - start,
!data.GetTrackDataTrack(i),
data.GetTrackPreemphasis(i)));
}
TOC[1][0].Start = 0U;
var ctdb = new CUEToolsDB(TOC, null);
var form = new CUETools.CTDB.EACPlugin.FormMetadata(ctdb, "EAC" + data.HostVersion + " CTDB 2.1.1");
form.ShowDialog();
var meta = form.Meta;
if (meta == null)
return false;
int year, disccount, discnumber;
if (meta.year != null && int.TryParse(meta.year, out year))
data.Year = year;
if (meta.disccount != null && int.TryParse(meta.disccount, out disccount))
data.TotalNumberOfCDs = disccount;
if (meta.discnumber != null && int.TryParse(meta.discnumber, out discnumber))
data.CDNumber = discnumber;
if (meta.album != null)
data.AlbumTitle = meta.album;
if (meta.artist != null)
data.AlbumArtist = meta.artist;
if (meta.track != null)
for (int track = 0; track < data.NumberOfTracks; track++)
{
if (track < meta.track.Length)
{
if (meta.track[track].name != null)
data.SetTrackTitle(track, meta.track[track].name);
var trackartist = meta.track[track].artist ?? meta.artist;
if (trackartist != null)
data.SetTrackArtist(track, trackartist);
}
else if (meta.artist != null)
data.SetTrackArtist(track, meta.artist);
}
return true;
}
public string GetPluginGuid()
{
return ((GuidAttribute)Attribute.GetCustomAttribute(GetType(), typeof(GuidAttribute))).Value;
}
public Array GetPluginLogo()
{
return null; // File.ReadAllBytes(@"C:\Work\cuetoolsnet\CUETools\Resources\accuraterip.bmp");
}
public string GetPluginName()
{
return "CUETools DB Metadata Plugin V2.1.1";
}
public void ShowOptions()
{
AudioDataPlugIn.Options opt = new AudioDataPlugIn.Options();
opt.ShowDialog();
}
public bool SubmitCDInformation(IMetadataLookup data)
{
throw new NotSupportedException();
}
public bool SupportsCoverRetrieval()
{
return false;
}
public bool SupportsLyricsRetrieval()
{
return false;
}
public bool SupportsMetadataRetrieval()
{
return true;
}
public bool SupportsMetadataSubmission()
{
return false;
}
}
}

View File

@@ -42,62 +42,26 @@ namespace AudioDataPlugIn
// This functions just returns an unique identifier.
// For that, the string representation of the unique
// guid is used
public string GetAudioTransferPluginGuid()
{
// Determine the guid attribute of the given class
Attribute attrib = Attribute.GetCustomAttribute(typeof(AudioDataTransfer), typeof(GuidAttribute));
// Is the returned attribute a GuidAttribute as
// we asked for?
if (attrib is GuidAttribute)
{
// Yes, so return the guid of this class
return ((GuidAttribute)attrib).Value;
}
else
{
// No, something went wrong. Just return
// the name of the plugin and hope that it
// is unique
return GetAudioTransferPluginName();
}
return ((GuidAttribute)Attribute.GetCustomAttribute(GetType(), typeof(GuidAttribute))).Value;
}
// Each plugin has also an (unique) display name
// which will be used for selecting/deselecting
// the plugin and for display in the log file
public string GetAudioTransferPluginName()
{
// Return the name which should be
// displayed in EAC and in the log file
// including a version number
return "CUETools DB Plugin V2.1.1";
}
// Each plugin should have its own options page.
// Even though if there are no options, a help or
// information dialog should be displayed
public void ShowOptions()
{
// Create a new option dialog object
Options opt = new Options();
// And show that dialog (return when
// the dialog is closed)
opt.ShowDialog();
}
@@ -155,7 +119,7 @@ namespace AudioDataPlugIn
#if USEAR
ar.ContactAccurateRip(ArId);
#endif
ctdb.ContactDB("EAC" + m_data.HostVersion + " CTDB 2.1.1", m_drivename);
ctdb.ContactDB("EAC" + m_data.HostVersion + " CTDB 2.1.1", m_drivename, false, false);
ctdb.Init(true, ar);
this.sequence_ok = true;
this.m_start_pos = 0;