Beispiel #1
0
 protected virtual Discogs.TrackDetails GetTrackDetails(IFileData fileData, int track, string title, Discogs.ReleaseDetails releaseDetails)
 {
     //If no track number was provided but the release contains only one track then return it.
     if (track == default(int))
     {
         if (releaseDetails.Tracks.Length == 1)
         {
             return(releaseDetails.Tracks.First());
         }
     }
     foreach (var trackDetails in releaseDetails.Tracks)
     {
         //If no track numer was provided then attempt a title match.
         if (track == default(int))
         {
             if (!string.IsNullOrEmpty(title) && Discogs.Sanitize(title).Similarity(Discogs.Sanitize(trackDetails.Title), true) >= this.MinConfidence.Value)
             {
                 return(trackDetails);
             }
         }
         //Otherwise attept a position match.
         else
         {
             var position = default(int);
             if (int.TryParse(trackDetails.Position, out position))
             {
                 if (position == track)
                 {
                     return(trackDetails);
                 }
             }
             else
             {
                 //TODO: Position is not always numeric.
             }
         }
     }
     Logger.Write(this, LogLevel.Warn, "No track details found: {0}", fileData.FileName);
     return(default(Discogs.TrackDetails));
 }
Beispiel #2
0
        public override void InitializeComponent(ICore core)
        {
            var configuration = core.Components.Configuration;
            var baseUrl       = configuration.GetElement <TextConfigurationElement>(
                DiscogsBehaviourConfiguration.SECTION,
                DiscogsBehaviourConfiguration.BASE_URL
                );
            var key = configuration.GetElement <TextConfigurationElement>(
                DiscogsBehaviourConfiguration.SECTION,
                DiscogsBehaviourConfiguration.CONSUMER_KEY
                );
            var secret = configuration.GetElement <TextConfigurationElement>(
                DiscogsBehaviourConfiguration.SECTION,
                DiscogsBehaviourConfiguration.CONSUMER_SECRET
                );
            var maxRequests = configuration.GetElement <IntegerConfigurationElement>(
                DiscogsBehaviourConfiguration.SECTION,
                DiscogsBehaviourConfiguration.MAX_REQUESTS
                );

            this.Discogs = new Discogs(baseUrl.Value, key.Value, secret.Value, maxRequests.Value);
            base.InitializeComponent(core);
        }