-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmimetype.cpp
133 lines (120 loc) · 3.15 KB
/
mimetype.cpp
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
/*
mimetype.cpp - Maps file extensions to file mime types.
2020/12/09, Maya Posch
*/
#include "mimetype.h"
// Static initialisations.
std::map<std::string, std::string> MimeType::mimes {
{"*3gpp", "audio/3gpp"},
{"*jpm", "video/jpm"},
{"*mp3", "audio/mp3"},
{"*wav", "audio/wave"},
{"3g2", "video/3gpp2"},
{"3gp", "video/3gpp"},
{"aac", "audio/aac"},
{"avi", "video/x-msvideo"},
{"adp", "audio/adpcm"},
{"adp", "audio/adpcm"},
{"apng", "image/apng"},
{"au", "audio/basic"},
{"bmp", "image/bmp"},
{"cgm", "image/cgm"},
{"drle", "image/dicom-rle"},
{"emf", "image/emf"},
{"exr", "image/aces"},
{"fits", "image/fits"},
{"flac", "audio/flac"},
{"g3", "image/g3fax"},
{"gif", "image/gif"},
{"h261", "video/h261"},
{"h263", "video/h263"},
{"h264", "video/h264"},
{"heic", "image/heic"},
{"heics", "image/heic-sequence"},
{"heif", "image/heif"},
{"heifs", "image/heif-sequence"},
{"ief", "image/ief"},
{"jls", "image/jls"},
{"jp2", "image/jp2"},
{"jpe", "image/jpeg"},
{"jpeg", "image/jpeg"},
{"jpf", "image/jpx"},
{"jpg", "image/jpeg"},
{"jpg2", "image/jp2"},
{"jpgm", "video/jpm"},
{"jpgv", "video/jpeg"},
{"jpm", "image/jpm"},
{"jpx", "image/jpx"},
{"kar", "audio/midi"},
{"ktx", "image/ktx"},
{"mkv", "video/x-matroska"},
{"m1v", "video/mpeg"},
{"m2a", "audio/mpeg"},
{"m2v", "video/mpeg"},
{"m3a", "audio/mpeg"},
{"m4a", "audio/mp4"},
{"mid", "audio/midi"},
{"midi", "audio/midi"},
{"mj2", "video/mj2"},
{"mjp2", "video/mj2"},
{"mov", "video/quicktime"},
{"mp2", "audio/mpeg"},
{"mp2a", "audio/mpeg"},
{"mp3", "audio/mpeg"},
{"mp4", "video/mp4"},
{"mp4a", "audio/mp4"},
{"mp4v", "video/mp4"},
{"mpe", "video/mpeg"},
{"mpeg", "video/mpeg"},
{"mpg", "video/mpeg"},
{"mpg4", "video/mp4"},
{"mpga", "audio/mpeg"},
{"oga", "audio/ogg"},
{"ogg", "audio/ogg"},
{"ogv", "video/ogg"},
{"opus", "audio/opus"},
{"png", "image/png"},
{"qt", "video/quicktime"},
{"rmi", "audio/midi"},
{"s3m", "audio/s3m"},
{"sgi", "image/sgi"},
{"sil", "audio/silk"},
{"snd", "audio/basic"},
{"spx", "audio/ogg"},
{"svg", "image/svg+xml"},
{"svgz", "image/svg+xml"},
{"t38", "image/t38"},
{"tfx", "image/tiff-fx"},
{"tif", "image/tiff"},
{"tiff", "image/tiff"},
{"ts", "video/mp2t"},
{"wav", "audio/wav"},
{"weba", "audio/webm"},
{"webm", "video/webm"},
{"webp", "image/webp"},
{"wmf", "image/wmf"},
{"xm", "audio/xm"},
{"m3u", "application/mpegurl"},
{"m3u8", "application/mpegurl"},
};
// --- GET MIME TYPE ---
std::string MimeType::getMimeType(std::string extension) {
std::map<std::string, std::string>::const_iterator it;
it = mimes.find(extension);
if (it == mimes.end()) { return std::string(); }
return it->second;
}
// --- HAS EXTENSION ---
bool MimeType::hasExtension(std::string extension, uint8_t &type) {
std::map<std::string, std::string>::const_iterator it;
it = mimes.find(extension);
if (it == mimes.end()) { return false; }
//std::string ts = it->second.substr(0, it->second.find('/'));
std::string ts = it->second.substr(0, 5);
if (ts == "audio") { type = 0; }
else if (ts == "video") { type = 1; }
else if (ts == "image") { type = 2; }
else if (ts == "appli") { type = 3; }
else { return false; }
return true;
}