| 104 | // |
| 105 | // Try to make an educated guess about the type of data present on the |
| 106 | // cd/dvd. |
| 107 | // |
| 108 | DetectMediaType(m_MountPath); |
| 109 | if (ExtensionMap.isEmpty ()) |
| 110 | { |
| 111 | VERBOSE(VB_GENERAL, |
| 112 | QString("No files with extension found in '%1'").arg (m_MountPath)); |
| 113 | } else { |
| 114 | struct { |
| 115 | int type; |
| 116 | char *extensions[16]; |
| 117 | } TypeMapping[] = { |
| 118 | { MEDIATYPE_MVIDEO, |
| 119 | { "wmv", "mpg", "avi", "vob", "mpeg", "nuv", NULL }}, |
| 120 | { MEDIATYPE_MMUSIC, |
| 121 | { "mp3", "ogg", "flac", NULL }}, |
| 122 | { MEDIATYPE_MGALLERY, |
| 123 | { "tif", "jpg", "png", NULL }}, |
| 124 | { 0 , {NULL} }}; |
| 125 | |
| 126 | int score = 0, highscore = 0, type = 0; |
| 127 | int i; char **p; |
| 128 | |
| 129 | for (i = 0, score = 0; TypeMapping[i].type != 0; i++) |
| 130 | { |
| 131 | for (p = TypeMapping[i].extensions; *p != NULL; p++) |
| 132 | { |
| 133 | if (ExtensionMap.contains(*p)) |
| 134 | score += ExtensionMap[*p]; |
| 135 | } |
| 136 | if (score > highscore) |
| 137 | type = TypeMapping[i].type; highscore = score; |
| 138 | } |
| 139 | // cerr << "Cdtype: " << type << "Score: " << highscore << endl; |
| 140 | } |
| 141 | ExtensionMap.clear(); |
| 142 | |
| 147 | |
| 148 | // |
| 149 | // Recursively scan directories and create an associative array with |
| 150 | // key: 'tolower(extension)' and value the number of times we've |
| 151 | // seen it. |
| 152 | // |
| 153 | void MythCDROM::DetectMediaType(const QString& directory) |
| 154 | { |
| 155 | QDir d(directory); |
| 156 | |
| 157 | d.setSorting(QDir::DirsFirst | QDir::Name | QDir::IgnoreCase); |
| 158 | if (!d.exists()) |
| 159 | return; |
| 160 | |
| 161 | const QFileInfoList *list = d.entryInfoList(); |
| 162 | if (!list) |
| 163 | return; |
| 164 | |
| 165 | QFileInfoListIterator it(*list); |
| 166 | QFileInfo *fi; |
| 167 | |
| 168 | while ((fi = it.current()) != 0) |
| 169 | { |
| 170 | ++it; |
| 171 | if (fi->fileName() == "." || fi->fileName() == ".." ) |
| 172 | continue; |
| 173 | if (!fi->isDir()) |
| 174 | { |
| 175 | QString extension = fi->extension(false); |
| 176 | if (!extension.isEmpty()) |
| 177 | { |
| 178 | extension = extension.lower(); |
| 179 | if (ExtensionMap.contains(extension)) |
| 180 | ExtensionMap[extension]++; |
| 181 | else |
| 182 | ExtensionMap[extension] = 1; |
| 183 | } |
| 184 | } |
| 185 | else DetectMediaType(fi->absFilePath()); |
| 186 | } |
| 187 | } |