Dont throw EncodingFoundException unless asked to. Should remove the occassional...
[beagle.git] / Filters / FilterMusic.cs
blobe051a8e9ea83589d16b416e2dfc604ab1c153809
1 //
2 // FilterMusic.cs : This is our interface to entagged-sharp's AudioFileWrapper
3 // interface.
4 //
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a
8 // copy of this software and associated documentation files (the "Software"),
9 // to deal in the Software without restriction, including without limitation
10 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 // and/or sell copies of the Software, and to permit persons to whom the
12 // Software is furnished to do so, subject to the following conditions:
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 // DEALINGS IN THE SOFTWARE.
26 using System;
27 using System.IO;
28 using Beagle.Daemon;
29 using Beagle.Util;
30 using Entagged;
32 namespace Beagle.Filters {
34 [PropertyKeywordMapping (Keyword="album", PropertyName="fixme:album", IsKeyword=false)]
35 [PropertyKeywordMapping (Keyword="artist", PropertyName="fixme:artist", IsKeyword=false)]
36 public class FilterMusic : Beagle.Daemon.Filter {
38 public FilterMusic ()
40 // 1: Added duration and bitrate property
41 SetVersion (1);
43 // APE / Monkeys Audio
44 AddSupportedFlavor (FilterFlavor.NewFromExtension (".ape"));
46 // FLAC
47 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-flac"));
49 // MP3
50 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-mp3"));
51 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/mpeg"));
53 // MPC / Musepack / MPEG+
54 AddSupportedFlavor (FilterFlavor.NewFromExtension (".mpc"));
55 AddSupportedFlavor (FilterFlavor.NewFromExtension (".mp+"));
57 // M4A / Apple Audio Codec
58 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-m4a"));
59 AddSupportedFlavor (FilterFlavor.NewFromExtension (".m4p"));
61 // OGG Vorbis
62 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("application/ogg"));
63 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-vorbis+ogg"));
65 // Tracker / Amiga Audio
66 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-s3m"));
67 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-it"));
68 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-mod"));
69 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-xm"));
71 // ASF / WMA
72 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-ms-wma"));
75 private string GetEntaggedMimeType ()
77 if (Extension != null && Extension.Length > 0)
78 return "entagged/" + Extension.Substring (1);
79 else
80 return MimeType;
83 protected override void DoPullProperties ()
85 AudioFile tag;
87 try {
88 tag = new AudioFile (Stream, GetEntaggedMimeType ());
89 } catch (Exception e) {
90 Logger.Log.Warn (e, "Exception filtering music");
91 Finished();
92 return;
95 foreach (string artist in tag.Artists)
96 AddProperty (Beagle.Property.New ("fixme:artist", artist));
98 foreach (string album in tag.Albums)
99 AddProperty (Beagle.Property.New ("fixme:album", album));
101 foreach (string title in tag.Titles)
102 AddProperty (Beagle.Property.New ("fixme:title", title));
104 foreach (string comment in tag.Comments)
105 AddProperty (Beagle.Property.New ("fixme:comment", comment));
107 foreach (int track in tag.TrackNumbers)
108 AddProperty (Beagle.Property.NewUnsearched ("fixme:tracknumber", track));
110 foreach (int track in tag.TrackCounts)
111 AddProperty (Beagle.Property.NewUnsearched ("fixme:trackcount", track));
113 foreach (int year in tag.Years)
114 AddProperty (Beagle.Property.NewUnsearched ("fixme:year", year));
116 foreach (string genre in tag.Genres)
117 AddProperty (Beagle.Property.NewKeyword ("fixme:genre", genre));
119 AddProperty (Beagle.Property.NewUnsearched ("fixme:duration", tag.Duration));
120 AddProperty (Beagle.Property.NewUnsearched ("fixme:bitrate", tag.Bitrate));
122 Finished ();