File: File.cs

package info (click to toggle)
banshee 0.11.2%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 11,976 kB
  • ctags: 9,958
  • sloc: cs: 54,529; xml: 21,240; sh: 8,835; ansic: 2,040; makefile: 1,248
file content (139 lines) | stat: -rw-r--r-- 5,138 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
namespace TagLib.Mpeg4
{
   [SupportedMimeType("taglib/m4a", "m4a")]
   [SupportedMimeType("taglib/m4p", "m4p")]
   [SupportedMimeType("taglib/mp4", "mp4")]
   [SupportedMimeType("audio/mp4")]
   [SupportedMimeType("audio/x-m4a")]
   public class File : TagLib.File
   {
      //////////////////////////////////////////////////////////////////////////
      // private properties
      //////////////////////////////////////////////////////////////////////////
      private AppleTag   tag;
      private Properties properties;
      
      
      //////////////////////////////////////////////////////////////////////////
      // public methods
      //////////////////////////////////////////////////////////////////////////
      public File (string file, AudioProperties.ReadStyle properties_style) : base (file)
      {
         // Nullify for safety.
         tag = null;
         properties = null;
         
         // Try to open read support.
         try {Mode = AccessMode.Read;}
         catch {return;}
         
         // Read
         Read (properties_style);
         
         // Be nice and close.
         Mode = AccessMode.Closed;
      }
      
      // Assume average speed.
      public File (string file) : this (file, AudioProperties.ReadStyle.Average)
      {
      }
      
      // Read the tag. If it doesn't exist, create.
      public override TagLib.Tag Tag {get {return GetTag (TagTypes.Apple, true);}}
      
      // Read the properties.
      public override TagLib.AudioProperties AudioProperties {get {return properties;}}
      
      // Save. This work is done in the AppleTag.
      public override void Save () 
      {
        tag.Save();
      }
      
      // Get the Apple Tag.
      public override TagLib.Tag GetTag (TagTypes type, bool create)
      {
         if (type == TagTypes.Apple)
         {
            if (tag == null && create)
               tag = new AppleTag (this);
            
            return tag;
         }
         
         return null;
      }
      
      // Read the file.
      private void Read (AudioProperties.ReadStyle properties_style)
      {
         // Create a dummie outer box, as perscribed by the specs.
         FileBox file_box = new FileBox (this);
         
         // Find the movie box and item list. If the movie box doen't exist, an
         // exception will be thrown on the next call, but if there is no movie 
         // box, the file can't possibly be valid.
         IsoMovieBox moov_box = (IsoMovieBox) file_box.FindChildDeep ("moov");
         AppleItemListBox ilst_box = (AppleItemListBox) moov_box.FindChildDeep ("ilst");
         
         // If we have a ItemListBox, deparent it.
         if (ilst_box != null)
            ilst_box.RemoveFromParent ();
         
         // Create the tag.
         tag = new AppleTag (ilst_box, this);
         
         // If we're not reading properties, we're done.
         if(properties_style == Properties.ReadStyle.None)
            return;
         
         // Get the movie header box.
         IsoMovieHeaderBox   mvhd_box = (IsoMovieHeaderBox) moov_box.FindChildDeep ("mvhd");
         IsoAudioSampleEntry sample_entry = null;
         
         // Find a TrackBox with a sound Handler.
         foreach (Box box in moov_box.Children)
            if (box.BoxType == "trak")
            {
               // If the handler isn't sound, it could be metadata or video or
               // any number of other things.
               IsoHandlerBox hdlr_box = (IsoHandlerBox) box.FindChildDeep ("hdlr");
               if (hdlr_box == null || hdlr_box.HandlerType != "soun")
                  continue;
               
               // This track SHOULD contain at least one sample entry.
               sample_entry = (IsoAudioSampleEntry) box.FindChildDeep (typeof (IsoAudioSampleEntry));
               break;
            }
         
         // If we have a MovieHeaderBox, deparent it.
         if (mvhd_box != null)
            mvhd_box.RemoveFromParent ();
         
         // If we have a SampleEntry, deparent it.
         if (sample_entry != null)
            sample_entry.RemoveFromParent ();
         
         // Read the properties.
         properties = new Properties (mvhd_box, sample_entry, properties_style);
      }
      
      /*
      private void ShowAllTags (Box box, string spa)
      {
         if (box.GetType () == typeof (AppleDataBox))
            System.Console.WriteLine (spa + box.BoxType.Mid (box.BoxType [0] == 0xa9 ? 1 : 0).ToString () + " - " + box.ToString () + " - " + ((AppleDataBox)box).Text);
         else if (box.GetType () == typeof (AppleAdditionalInfoBox))
            System.Console.WriteLine (spa + box.BoxType.Mid (box.BoxType [0] == 0xa9 ? 1 : 0).ToString () + " - " + box.ToString () + " - " + ((AppleAdditionalInfoBox)box).Text);
         else
            System.Console.WriteLine (spa + box.BoxType.Mid (box.BoxType [0] == 0xa9 ? 1 : 0).ToString () + " - " + box.ToString ());
         
         foreach (Box child in box.Children)
         {
            ShowAllTags (child, spa + " ");
         }
      }
      */
   }
}