File: ReadFromUri.cs

package info (click to toggle)
taglib-sharp 2.1.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 3,880 kB
  • sloc: cs: 29,524; sh: 594; makefile: 229
file content (171 lines) | stat: -rw-r--r-- 6,796 bytes parent folder | download | duplicates (4)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using System;
using TagLib;
using Gnome.Vfs;

public class ReadFromUri
{
    public static void Write (string name, object value)
    {
        Console.WriteLine ("{0,20}: {1}",
            name, value == null ? "" : value
        );
    }

    public static void Write (string name, string [] values)
    {
        Console.WriteLine ("{0,20}: {1}",
            name, 
            values == null ? "" : String.Join ("\n            ", values)
        );
    }

    public static void Main(string [] args)
    {
        if(args.Length == 0) {
            Console.Error.WriteLine("USAGE: mono ReadFromUri.exe PATH [...]");
            return;
        }
        
        Gnome.Vfs.Vfs.Initialize();
        
        DateTime start = DateTime.Now;
        int songs_read = 0;
        try {
            foreach (string path in args)
            {
                string uri = path;
                Console.WriteLine (uri);
                TagLib.File file = null;
                
                try {
                    System.IO.FileInfo file_info = new System.IO.FileInfo(uri);
                    uri = Gnome.Vfs.Uri.GetUriFromLocalPath (file_info.FullName);
                } catch {
                }
                
                try
                {
                    file = TagLib.File.Create(new VfsFileAbstraction (uri));
                }
                catch (TagLib.UnsupportedFormatException)
                {
                    Console.WriteLine ("UNSUPPORTED FILE: " + uri);
                    Console.WriteLine (String.Empty);
                    Console.WriteLine ("---------------------------------------");
                    Console.WriteLine (String.Empty);
                    continue;
                }
                
                Console.WriteLine("Tags on disk:   " +  file.TagTypesOnDisk);
                Console.WriteLine("Tags in object: " +  file.TagTypes);
                Console.WriteLine (String.Empty);
               
                Write ("Grouping",              file.Tag.Grouping);
                Write ("Title",                 file.Tag.Title);
                Write ("TitleSort",             file.Tag.TitleSort);
                Write ("Album Artists",         file.Tag.AlbumArtists);
                Write ("Album Artists Sort",    file.Tag.AlbumArtistsSort);
                Write ("Performers",            file.Tag.Performers);
                Write ("Performers Sort",       file.Tag.PerformersSort);
                Write ("Composers",             file.Tag.Composers);
                Write ("Composers Sort",        file.Tag.ComposersSort);
                Write ("Conductor",             file.Tag.Conductor);
                Write ("Album",                 file.Tag.Album);
                Write ("Album Sort",            file.Tag.AlbumSort);
                Write ("Comment",               file.Tag.Comment);
                Write ("Copyright",             file.Tag.Copyright);
                Write ("Genres",                file.Tag.Genres);
                Write ("BPM",                   file.Tag.BeatsPerMinute);
                Write ("Year",                  file.Tag.Year);
                Write ("Track",                 file.Tag.Track);
                Write ("TrackCount",            file.Tag.TrackCount);
                Write ("Disc",                  file.Tag.Disc);
                Write ("DiscCount",             file.Tag.DiscCount);

                Console.WriteLine("Lyrics:\n"    +  file.Tag.Lyrics + "\n");
                
                Console.WriteLine("Media Types:     " + file.Properties.MediaTypes + "\n");
                
                foreach (TagLib.ICodec codec in file.Properties.Codecs)
                {
                    TagLib.IAudioCodec acodec = codec as TagLib.IAudioCodec;
                    TagLib.IVideoCodec vcodec = codec as TagLib.IVideoCodec;
                
                    if (acodec != null && (acodec.MediaTypes & TagLib.MediaTypes.Audio) != TagLib.MediaTypes.None)
                    {
                        Console.WriteLine("Audio Properties : " + acodec.Description);
                        Console.WriteLine("Bitrate:    " + acodec.AudioBitrate);
                        Console.WriteLine("SampleRate: " + acodec.AudioSampleRate);
                        Console.WriteLine("Channels:   " + acodec.AudioChannels + "\n");
                    }
                
                    if (vcodec != null && (vcodec.MediaTypes & TagLib.MediaTypes.Video) != TagLib.MediaTypes.None)
                    {
                        Console.WriteLine("Video Properties : " + vcodec.Description);
                        Console.WriteLine("Width:      " + vcodec.VideoWidth);
                        Console.WriteLine("Height:     " + vcodec.VideoHeight + "\n");
                    }
                }
                
                if (file.Properties.MediaTypes != TagLib.MediaTypes.None)
                    Console.WriteLine("Length:     " + file.Properties.Duration + "\n");
                
                IPicture [] pictures = file.Tag.Pictures;
                
                Console.WriteLine("Embedded Pictures: " + pictures.Length);
                
                foreach(IPicture picture in pictures) {
                    Console.WriteLine(picture.Description);
                    Console.WriteLine("   MimeType: " + picture.MimeType);
                    Console.WriteLine("   Size:     " + picture.Data.Count);
                    Console.WriteLine("   Type:     " + picture.Type);
                }
                
                Console.WriteLine (String.Empty);
                Console.WriteLine ("---------------------------------------");
                Console.WriteLine (String.Empty);
                
                songs_read ++;
            }
        } finally {
           Gnome.Vfs.Vfs.Shutdown();
        }
        
        DateTime end = DateTime.Now;
        
        Console.WriteLine ("Total running time:    " + (end - start));
        Console.WriteLine ("Total files read:      " + songs_read);

        if (songs_read > 0)
        {
            Console.WriteLine ("Average time per file: " + new TimeSpan ((end - start).Ticks / songs_read));
        }
    }
}

public class VfsFileAbstraction : TagLib.File.IFileAbstraction
{
    private string name;

    public VfsFileAbstraction(string file)
    {
        name = file;
    }

    public string Name {
        get { return name; }
    }

    public System.IO.Stream ReadStream {
        get { return new VfsStream(Name, System.IO.FileMode.Open); }
    }

    public System.IO.Stream WriteStream {
        get { return new VfsStream(Name, System.IO.FileMode.Open); }
    }
    
    public void CloseStream (System.IO.Stream stream)
    {
       stream.Close ();
    }
}