cvsimport
[beagle.git] / Filters / FilterMusic.cs
blob0f8c028980881e513a0ba19fe81364592c2df269
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 [PropertyKeywordMapping (Keyword="genre", PropertyName="fixme:genre", IsKeyword=true)]
37 public class FilterMusic : Beagle.Daemon.Filter {
39 public FilterMusic ()
41 // 1: Added duration and bitrate property
42 SetVersion (1);
44 // APE / Monkeys Audio
45 AddSupportedFlavor (FilterFlavor.NewFromExtension (".ape"));
47 // FLAC
48 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-flac"));
50 // MP3
51 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-mp3"));
52 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/mpeg"));
54 // MPC / Musepack / MPEG+
55 AddSupportedFlavor (FilterFlavor.NewFromExtension (".mpc"));
56 AddSupportedFlavor (FilterFlavor.NewFromExtension (".mp+"));
58 // M4A / Apple Audio Codec
59 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-m4a"));
60 AddSupportedFlavor (FilterFlavor.NewFromExtension (".m4p"));
62 // OGG Vorbis
63 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("application/ogg"));
64 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-vorbis+ogg"));
66 // Tracker / Amiga Audio
67 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-s3m"));
68 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-it"));
69 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-mod"));
70 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-xm"));
72 // ASF / WMA
73 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("audio/x-ms-wma"));
76 private string GetEntaggedMimeType ()
78 if (Extension != null && Extension.Length > 0)
79 return "entagged/" + Extension.Substring (1);
80 else
81 return MimeType;
84 protected override void DoPullProperties ()
86 AudioFile tag;
88 try {
89 tag = new AudioFile (Stream, GetEntaggedMimeType ());
90 } catch (Exception e) {
91 Logger.Log.Warn (e, "Exception filtering music");
92 Finished();
93 return;
96 foreach (string artist in tag.Artists)
97 AddProperty (Beagle.Property.New ("fixme:artist", artist));
99 foreach (string album in tag.Albums)
100 AddProperty (Beagle.Property.New ("fixme:album", album));
102 foreach (string title in tag.Titles)
103 AddProperty (Beagle.Property.New ("fixme:title", title));
105 foreach (string comment in tag.Comments)
106 AddProperty (Beagle.Property.New ("fixme:comment", comment));
108 foreach (int track in tag.TrackNumbers)
109 AddProperty (Beagle.Property.NewUnsearched ("fixme:tracknumber", track));
111 foreach (int track in tag.TrackCounts)
112 AddProperty (Beagle.Property.NewUnsearched ("fixme:trackcount", track));
114 foreach (int year in tag.Years)
115 AddProperty (Beagle.Property.NewUnsearched ("fixme:year", year));
117 foreach (string genre in tag.Genres)
118 AddProperty (Beagle.Property.NewKeyword ("fixme:genre", genre));
120 AddProperty (Beagle.Property.NewUnsearched ("fixme:duration", tag.Duration));
121 AddProperty (Beagle.Property.NewUnsearched ("fixme:bitrate", tag.Bitrate));
123 Finished ();