protected override void LoadFromObject(VolumeDB.VolumeItem item) { if (!(item is AudioTrackVolumeItem)) { throw new ArgumentException(string.Format("must be of type {0}", typeof(AudioTrackVolumeItem)), "item"); } base.LoadFromObject(item); AudioTrackVolumeItem avi = (AudioTrackVolumeItem)item; UpdateLabel(lblDuration, avi.Duration.ToString()); UpdateLabel(lblMimeType, avi.MimeType); }
public static void GetAudioCdItemProperties(AudioTrackVolumeItem item, out ItemProperty[] properties, out Dictionary <string, string> nameProperty) { const int PCM_FACTOR = (44100 * 16 * 2) / 8; List <ItemProperty> tmp; GetCommonItemProperties(item, out tmp, out nameProperty); tmp.Add(new ItemProperty(S._("Duration"), FormatDuration(item.Duration), 202)); tmp.Add(new ItemProperty(S._("Size"), Util.GetSizeStr((long)(item.Duration.TotalSeconds * PCM_FACTOR)), 203)); tmp.Add(new ItemProperty(S._("Track No."), (item.ItemID - 1).ToString(), 204)); if (!string.IsNullOrEmpty(item.MimeType)) { tmp.Add(new ItemProperty(S._("Type"), item.MimeType, 205)); } tmp.Sort(); // sort by priority properties = tmp.ToArray(); }
internal override void ScanningThreadMain(PlatformIO.DriveInfo drive, AudioCdVolume volume, BufferedVolumeItemWriter writer) { if (Options.ComputeHashs) { SendScannerWarning(S._("Hashcode generation not implemented for audio cds yet.")); volume.IsHashed = false; } AudioCdRootVolumeItem root = GetNewVolumeItem <AudioCdRootVolumeItem>(VolumeDatabase.ID_NONE, "/", null, MetadataStore.Empty, VolumeItemType.AudioCdRootVolumeItem); LocalDisc localdisc = LocalDisc.GetFromDevice(drive.Device); if (localdisc == null) { throw new ApplicationException("Could not read contents of the audio cd"); } TimeSpan[] durations = localdisc.GetTrackDurations(); List <AudioTrackVolumeItem> items = new List <AudioTrackVolumeItem>(); for (int i = 0; i < durations.Length; i++) { AudioTrackVolumeItem item = GetNewVolumeItem <AudioTrackVolumeItem>(root.ItemID, "Track " + (i + 1), MIME_TYPE_AUDIO_TRACK, MetadataStore.Empty, VolumeItemType.AudioTrackVolumeItem); item.SetAudioTrackVolumeItemFields(durations[i]); items.Add(item); VolumeInfo.Tracks++; VolumeInfo.Duration = VolumeInfo.Duration.Add(durations[i]); } // retrieve musicbrainz metadata // (the metadata field of AudioTrackVolumeItems is set // depending on the EnableMusicBrainz flag) if (Options.EnableMusicBrainz) { try { // may throw MusicBrainzNotFoundException Release release = Release.Query(localdisc).PerfectMatch(); CheckForCancellationRequest(); if (release == null) { SendScannerWarning(S._("No MusicBrainz metadata available for this disc.")); } else { var tracks = release.GetTracks(); if (tracks.Count != items.Count) { SendScannerWarning(S._("The trackcount retrieved from MusicBrainz does not match the trackcount of the local disc. Skipped.")); } else { string albumTitle = release.GetTitle(); int releaseYear = GetReleaseYear(release); for (int i = 0; i < tracks.Count; i++) { items[i].Name = tracks[i].GetTitle(); items[i].MetaData = GetMetadata(tracks[i], albumTitle, releaseYear); } volume.Title = albumTitle; // preset category ReleaseType rtype = release.GetReleaseType(); if (rtype == ReleaseType.Album || rtype == ReleaseType.EP || rtype == ReleaseType.Compilation || rtype == ReleaseType.Remix) { volume.Category = PRESELECTED_CATEGORY; } } } } catch (MusicBrainzNotFoundException) { SendScannerWarning(S._("Error connecting to MusicBrainz server.")); } } volume.SetAudioCdVolumeFields(VolumeInfo.Tracks, VolumeInfo.Duration); // write items if (this.HasDB) { writer.Write(root); foreach (AudioTrackVolumeItem item in items) { writer.Write(item); } } }