Skip to content

Commit

Permalink
Fix CDDB lookup host, freedb.freedb.org has gone away.
Browse files Browse the repository at this point in the history
 Also allow multiple host to be configured.
  • Loading branch information
pudding committed Jan 28, 2024
1 parent 68268ec commit 9e71954
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 54 deletions.
4 changes: 2 additions & 2 deletions FoxTunes.Output.Bass.Cd/BassCdMetaDataSourceStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public BassCdMetaDataSourceStrategy(int drive)

public int Drive { get; private set; }

public virtual bool InitializeComponent()
public virtual bool Fetch()
{
return true;
return false;
}

public virtual IEnumerable<MetaDataItem> GetMetaDatas(int track)
Expand Down
38 changes: 27 additions & 11 deletions FoxTunes.Output.Bass.Cd/BassCdStreamProviderBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,24 @@ private set
}
}

private string _CdLookupHost { get; set; }
private IEnumerable<string> _CdLookupHosts { get; set; }

public string CdLookupHost
public IEnumerable<string> CdLookupHosts
{
get
{
return this._CdLookupHost;
return this._CdLookupHosts;
}
private set
{
this._CdLookupHost = value;
Logger.Write(this, LogLevel.Debug, "CD Lookup Host = {0}", this.CdLookupHost);
this._CdLookupHosts = value;
if (value != null)
{
foreach (var cdLookupHost in value)
{
Logger.Write(this, LogLevel.Debug, "CD Lookup Host = {0}", cdLookupHost);
}
}
}
}

Expand All @@ -114,7 +120,17 @@ public override void InitializeComponent(ICore core)
this.Configuration.GetElement<TextConfigurationElement>(
BassCdStreamProviderBehaviourConfiguration.SECTION,
BassCdStreamProviderBehaviourConfiguration.LOOKUP_HOST_ELEMENT
).ConnectValue(value => this.CdLookupHost = value);
).ConnectValue(value =>
{
if (!string.IsNullOrEmpty(value))
{
this.CdLookupHosts = value.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
}
else
{
this.CdLookupHosts = BassCdStreamProviderBehaviourConfiguration.GetLookupHosts();
}
});
this.BassStreamPipelineFactory = ComponentRegistry.Instance.GetComponent<IBassStreamPipelineFactory>();
this.BassStreamPipelineFactory.CreatingPipeline += this.OnCreatingPipeline;
base.InitializeComponent(core);
Expand Down Expand Up @@ -226,7 +242,7 @@ public Task OpenCd(int drive)

public async Task OpenCd(Playlist playlist, int drive)
{
using (var task = new AddCdToPlaylistTask(playlist, drive, this.CdLookup, this.CdLookupHost))
using (var task = new AddCdToPlaylistTask(playlist, drive, this.CdLookup, this.CdLookupHosts))
{
task.InitializeComponent(this.Core);
await this.BackgroundTaskEmitter.Send(task).ConfigureAwait(false);
Expand Down Expand Up @@ -279,11 +295,11 @@ protected virtual void OnDisposing()

private class AddCdToPlaylistTask : PlaylistTaskBase
{
public AddCdToPlaylistTask(Playlist playlist, int drive, bool cdLookup, string cdLookupHost) : base(playlist)
public AddCdToPlaylistTask(Playlist playlist, int drive, bool cdLookup, IEnumerable<string> cdLookupHosts) : base(playlist)
{
this.Drive = drive;
this.CdLookup = cdLookup;
this.CdLookupHost = cdLookupHost;
this.CdLookupHosts = cdLookupHosts;
}

public override bool Visible
Expand All @@ -298,7 +314,7 @@ public override bool Visible

public bool CdLookup { get; private set; }

public string CdLookupHost { get; private set; }
public IEnumerable<string> CdLookupHosts { get; private set; }

public IPlaylistManager PlaylistManager { get; private set; }

Expand All @@ -310,7 +326,7 @@ public override void InitializeComponent(ICore core)
{
this.PlaylistManager = core.Managers.Playlist;
this.PlaylistBrowser = core.Components.PlaylistBrowser;
this.Factory = new CdPlaylistItemFactory(this.Drive, this.CdLookup, this.CdLookupHost);
this.Factory = new CdPlaylistItemFactory(this.Drive, this.CdLookup, this.CdLookupHosts);
this.Factory.InitializeComponent(core);
base.InitializeComponent(core);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ManagedBass.Cd;
using System;
using System.Collections.Generic;

namespace FoxTunes
Expand All @@ -15,14 +15,24 @@ public static class BassCdStreamProviderBehaviourConfiguration

public static IEnumerable<ConfigurationSection> GetConfigurationSections()
{
yield return new ConfigurationSection(SECTION, "CD")
.WithElement(new BooleanConfigurationElement(ENABLED_ELEMENT, "Enabled").WithValue(false))
.WithElement(new BooleanConfigurationElement(LOOKUP_ELEMENT, "Lookup Tags")
yield return new ConfigurationSection(SECTION, Strings.BassCdStreamProviderBehaviourConfiguration_Section)
.WithElement(new BooleanConfigurationElement(ENABLED_ELEMENT, Strings.BassCdStreamProviderBehaviourConfiguration_Enabled).WithValue(false))
.WithElement(new BooleanConfigurationElement(LOOKUP_ELEMENT, Strings.BassCdStreamProviderBehaviourConfiguration_Lookup)
.WithValue(true)
.DependsOn(SECTION, ENABLED_ELEMENT))
.WithElement(new TextConfigurationElement(LOOKUP_HOST_ELEMENT, "Host")
.WithValue(BassCd.CDDBServer ?? "freedb.freedb.org")
.WithElement(new TextConfigurationElement(LOOKUP_HOST_ELEMENT, Strings.BassCdStreamProviderBehaviourConfiguration_Host)
.WithValue(string.Join(Environment.NewLine, GetLookupHosts()))
.WithFlags(ConfigurationElementFlags.MultiLine)
.DependsOn(SECTION, ENABLED_ELEMENT).DependsOn(SECTION, LOOKUP_ELEMENT));
}

public static IEnumerable<string> GetLookupHosts()
{
return new[]
{
Strings.BassCdStreamProviderBehaviourConfiguration_Host1,
Strings.BassCdStreamProviderBehaviourConfiguration_Host2
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace FoxTunes.Interfaces
{
public interface IBassCdMetaDataSourceStrategy
{
bool InitializeComponent();
bool Fetch();

IEnumerable<MetaDataItem> GetMetaDatas(int track);

Expand Down
54 changes: 54 additions & 0 deletions FoxTunes.Output.Bass.Cd/Properties/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions FoxTunes.Output.Bass.Cd/Properties/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,22 @@
<data name="BassCdStreamProviderBehaviour.Path" xml:space="preserve">
<value>Open CD</value>
</data>
<data name="BassCdStreamProviderBehaviourConfiguration.Enabled" xml:space="preserve">
<value>Enabled</value>
</data>
<data name="BassCdStreamProviderBehaviourConfiguration.Host" xml:space="preserve">
<value>Lookup Hosts</value>
</data>
<data name="BassCdStreamProviderBehaviourConfiguration.Host1" xml:space="preserve">
<value>gnudb.gnudb.org</value>
</data>
<data name="BassCdStreamProviderBehaviourConfiguration.Host2" xml:space="preserve">
<value>freedb.dbpoweramp.com</value>
</data>
<data name="BassCdStreamProviderBehaviourConfiguration.Lookup" xml:space="preserve">
<value>Lookup Tags</value>
</data>
<data name="BassCdStreamProviderBehaviourConfiguration.Section" xml:space="preserve">
<value>CD</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@ public BassCdMetaDataSourceCdTextStrategy(int drive)

public CdTextParser Parser { get; private set; }

public override bool InitializeComponent()
public override bool Fetch()
{
Logger.Write(this, LogLevel.Debug, "Querying CD-TEXT for drive: {0}", this.Drive);
Logger.Write(this, LogLevel.Debug, "Querying CD-TEXT for drive {0}...", this.Drive);
lock (SyncRoot)
{
this.Parser = new CdTextParser(BassCd.GetIDText(this.Drive));
}
if (this.Parser.Count == 0)
if (this.Parser.Count > 0)
{
Logger.Write(this, LogLevel.Debug, "CD-TEXT did not return any information for drive: {0}", this.Drive);
return false;
Logger.Write(this, LogLevel.Debug, "CD-TEXT contains {0} records for drive {1}.", this.Parser.Count, this.Drive);
return true;
}
return base.InitializeComponent();
Logger.Write(this, LogLevel.Debug, "CD-TEXT was empty for drive {0}.", this.Drive);
return base.Fetch();
}

public override IEnumerable<MetaDataItem> GetMetaDatas(int track)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,48 @@ public class BassCdMetaDataSourceCddaStrategy : BassCdMetaDataSourceStrategy
{ "DYEAR", CommonMetaData.Year }
};

public BassCdMetaDataSourceCddaStrategy(int drive, string host)
public BassCdMetaDataSourceCddaStrategy(int drive, IEnumerable<string> hosts)
: base(drive)
{
if (!string.Equals(BassCd.CDDBServer, host, StringComparison.OrdinalIgnoreCase))
{
BassCd.CDDBServer = host;
}
this.Hosts = hosts;
}

public IEnumerable<string> Hosts { get; private set; }

public CddbTextParser Parser { get; private set; }

public override bool InitializeComponent()
public override bool Fetch()
{
Logger.Write(this, LogLevel.Debug, "Querying CDDB for drive: {0}", this.Drive);
try
Logger.Write(this, LogLevel.Debug, "Querying CDDB for drive {0}...", this.Drive);
foreach (var host in this.Hosts)
{
//The CDDB and Read must be executed together so synchronize.
lock (SyncRoot)
try
{
var id = BassCd.GetID(this.Drive, CDID.CDDB);
var sequence = BassCd.GetID(this.Drive, CDID.Read);
this.Parser = new CddbTextParser(id, sequence);
lock (SyncRoot)
{
Logger.Write(this, LogLevel.Debug, "Using CDDB host: {0}", host);
if (!string.Equals(BassCd.CDDBServer, host, StringComparison.OrdinalIgnoreCase))
{
BassCd.CDDBServer = host;
}
var id = BassCd.GetID(this.Drive, CDID.CDDB);
Logger.Write(this, LogLevel.Debug, "CDDB identifier is \"{0}\" for drive {1}.", id, this.Drive);
var sequence = BassCd.GetID(this.Drive, CDID.Read);
this.Parser = new CddbTextParser(id, sequence);
if (this.Parser.Count > 0)
{
Logger.Write(this, LogLevel.Debug, "CDDB returned {0} records for drive {1}.", this.Parser.Count, this.Drive);
return true;
}
}
}
if (this.Parser.Count == 0)
catch (Exception e)
{
Logger.Write(this, LogLevel.Debug, "CDDB did not return any information for drive: {0}", this.Drive);
return false;
Logger.Write(this, LogLevel.Warn, "Failed to query CDDB for drive {0}: {1}", this.Drive, e.Message);
}
}
catch (Exception e)
{
Logger.Write(this, LogLevel.Warn, "Failed to query CDDB for drive {0}: {1}", this.Drive, e.Message);
return false;
}
return base.InitializeComponent();
Logger.Write(this, LogLevel.Debug, "CDDB was empty for drive {0}.", this.Drive);
return base.Fetch();
}

public override IEnumerable<MetaDataItem> GetMetaDatas(int track)
Expand Down
12 changes: 6 additions & 6 deletions FoxTunes.Output.Bass.Cd/Utilities/CdPlaylistItemFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ namespace FoxTunes
{
public class CdPlaylistItemFactory : BaseComponent
{
public CdPlaylistItemFactory(int drive, bool cdLookup, string cdLookupHost)
public CdPlaylistItemFactory(int drive, bool cdLookup, IEnumerable<string> cdLookupHosts)
{
this.Drive = drive;
this.CdLookup = cdLookup;
this.CdLookupHost = cdLookupHost;
this.CdLookupHosts = cdLookupHosts;
}

public int Drive { get; private set; }

public bool CdLookup { get; private set; }

public string CdLookupHost { get; private set; }
public IEnumerable<string> CdLookupHosts { get; private set; }

public ICore Core { get; private set; }

Expand Down Expand Up @@ -110,15 +110,15 @@ private IBassCdMetaDataSourceStrategy GetStrategy()
{
if (this.CdLookup)
{
var strategy = new BassCdMetaDataSourceCddaStrategy(this.Drive, this.CdLookupHost);
if (strategy.InitializeComponent())
var strategy = new BassCdMetaDataSourceCddaStrategy(this.Drive, this.CdLookupHosts);
if (strategy.Fetch())
{
return strategy;
}
}
{
var strategy = new BassCdMetaDataSourceCdTextStrategy(this.Drive);
if (strategy.InitializeComponent())
if (strategy.Fetch())
{
return strategy;
}
Expand Down

0 comments on commit 9e71954

Please sign in to comment.