File: Picture.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 (118 lines) | stat: -rw-r--r-- 5,021 bytes parent folder | download | duplicates (2)
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
/***************************************************************************
    copyright            : (C) 2005 Novell, Inc.
    email                : Aaron Bockover <abockover@novell.com>
 ***************************************************************************/

/***************************************************************************
 *   This library is free software; you can redistribute it and/or modify  *
 *   it  under the terms of the GNU Lesser General Public License version  *
 *   2.1 as published by the Free Software Foundation.                     *
 *                                                                         *
 *   This library is distributed in the hope that it will be useful, but   *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *   Lesser General Public License for more details.                       *
 *                                                                         *
 *   You should have received a copy of the GNU Lesser General Public      *
 *   License along with this library; if not, write to the Free Software   *
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
 *   USA                                                                   *
 ***************************************************************************/

using System;
 
namespace TagLib
{
    public enum PictureType
    {
        Other              = 0x00, // A type not enumerated below
        FileIcon           = 0x01, // 32x32 PNG image that should be used as the file icon
        OtherFileIcon      = 0x02, // File icon of a different size or format
        FrontCover         = 0x03, // Front cover image of the album
        BackCover          = 0x04, // Back cover image of the album
        LeafletPage        = 0x05, // Inside leaflet page of the album
        Media              = 0x06, // Image from the album itself
        LeadArtist         = 0x07, // Picture of the lead artist or soloist
        Artist             = 0x08, // Picture of the artist or performer
        Conductor          = 0x09, // Picture of the conductor
        Band               = 0x0A, // Picture of the band or orchestra
        Composer           = 0x0B, // Picture of the composer
        Lyricist           = 0x0C, // Picture of the lyricist or text writer
        RecordingLocation  = 0x0D, // Picture of the recording location or studio
        DuringRecording    = 0x0E, // Picture of the artists during recording
        DuringPerformance  = 0x0F, // Picture of the artists during performance
        MovieScreenCapture = 0x10, // Picture from a movie or video related to the track
        ColouredFish       = 0x11, // Picture of a large, coloured fish
        Illustration       = 0x12, // Illustration related to the track
        BandLogo           = 0x13, // Logo of the band or performer
        PublisherLogo      = 0x14  // Logo of the publisher (record company)
    }

    public interface IPicture
    {
        string MimeType { get; set; }
        PictureType Type { get; set; }
        string Description { get; set; }
        ByteVector Data { get; set; }
    }

    public class Picture : IPicture
    {
        private string      mime_type;
        private PictureType type;
        private string      description;
        private ByteVector  data;
       
        public static Picture CreateFromUri(string uri)
        {
            byte [] fc;
            string filename = null;
            string mimetype = "image/jpeg";
            string ext = "jpg";
            
            try {
                Uri uri_parse = new Uri(uri);
                string path = uri_parse.LocalPath;
                filename = System.IO.Path.GetFileName(path);
                if(filename == String.Empty) {
                    filename = null;
                }
            } catch {
            }
        
            Picture picture = new Picture();
            picture.Data = ByteVector.FromUri(uri, out fc, true);
            
            if(fc.Length >= 4 && (fc[1] == 'P' && fc[2] == 'N' && fc[3] == 'G')) {
                mimetype = "image/png";
                ext = "png";
            }
            
            picture.MimeType = mimetype;
            picture.Type = PictureType.FrontCover;
            picture.Description = filename == null ? ("cover." + ext) : mimetype; 
            
            return picture;
        }
       
        public string MimeType {
            get { return mime_type; }
            set { mime_type = value; }
        }
      
        public PictureType Type {
            get { return type; }
            set { type = value; }
        }
      
        public string Description {
            get { return description; }
            set { description = value; }
        }
      
        public ByteVector Data {
            get { return data; }
            set { data = value; }
        }
    }
}