From 5d63ab1d78dcbe2a4c668e683ccb473c539acc19 Mon Sep 17 00:00:00 2001 From: "craig.p.drummond" Date: Tue, 26 Nov 2013 19:59:15 +0000 Subject: [PATCH] Only use taglib in tags.cpp/filetyperesolver.cpp --- http/httpsocket.cpp | 87 ++++++++++++++------------------------- online/jamendoservice.cpp | 18 +------- tags/tags.cpp | 40 ++++++++++++++++++ tags/tags.h | 2 + 4 files changed, 75 insertions(+), 72 deletions(-) diff --git a/http/httpsocket.cpp b/http/httpsocket.cpp index 3bd388f05..5c4395b34 100644 --- a/http/httpsocket.cpp +++ b/http/httpsocket.cpp @@ -43,11 +43,8 @@ #include #endif #include -#ifdef TAGLIB_FOUND -#include -#include -#include -#include +#if defined TAGLIB_FOUND && !defined ENABLE_EXTERNAL_TAGS +#include "tags.h" #endif #include #define DBUG if (HttpServer::debugEnabled()) qWarning() << "HttpSocket" << __FUNCTION__ @@ -66,72 +63,50 @@ static QString detectMimeType(const QString &file) } #if defined TAGLIB_FOUND && !defined ENABLE_EXTERNAL_TAGS if (suffix == QLatin1String("ogg")) { - #ifdef Q_OS_WIN32 - const wchar_t *encodedName = reinterpret_cast< const wchar_t * >(file.utf16()); - #elif defined COMPLEX_TAGLIB_FILENAME - const wchar_t *encodedName = reinterpret_cast< const wchar_t * >(file.utf16()); - #else - QByteArray fileName = QFile::encodeName(file); - const char *encodedName = fileName.constData(); // valid as long as fileName exists - #endif - - QString mime; - TagLib::File *result = new TagLib::Ogg::Vorbis::File(encodedName, false, TagLib::AudioProperties::Fast); - if (result->isValid()) { - mime=QLatin1String("audio/x-vorbis+ogg"); - } - delete result; - if (mime.isEmpty()) { - result = new TagLib::Ogg::FLAC::File(encodedName, false, TagLib::AudioProperties::Fast); - if (result->isValid()) { - mime=QLatin1String("audio/x-flac+ogg"); - } - delete result; - } - if (mime.isEmpty()) { - result = new TagLib::TrueAudio::File(encodedName, false, TagLib::AudioProperties::Fast); - if (result->isValid()) { - mime=QLatin1String("audio/x-speex+ogg"); - } - delete result; - } - #ifdef TAGLIB_OPUS_FOUND - if (mime.isEmpty()) { - result = new TagLib::Ogg::Opus::File(encodedName, false, TagLib::AudioProperties::Fast); - if (result->isValid()) { - mime=QLatin1String("audio/x-opus+ogg"); - } - delete result; - } - #endif + return Tags::oggMimeType(file); + } + #else + if (suffix == QLatin1String("ogg")) { return QLatin1String("audio/ogg"); } #endif - else if (suffix == QLatin1String("flac")) { + if (suffix == QLatin1String("flac")) { return QLatin1String("audio/x-flac"); - } else if (suffix == QLatin1String("wma")) { + } + if (suffix == QLatin1String("wma")) { return QLatin1String("audio/x-ms-wma"); - } else if (suffix == QLatin1String("m4a") || suffix == QLatin1String("m4b") || suffix == QLatin1String("m4p") || suffix == QLatin1String("mp4")) { + } + if (suffix == QLatin1String("m4a") || suffix == QLatin1String("m4b") || suffix == QLatin1String("m4p") || suffix == QLatin1String("mp4")) { return QLatin1String("audio/mp4"); - } else if (suffix == QLatin1String("wav")) { + } + if (suffix == QLatin1String("wav")) { return QLatin1String("audio/x-wav"); - } else if (suffix == QLatin1String("wv") || suffix == QLatin1String("wvp")) { + } + if (suffix == QLatin1String("wv") || suffix == QLatin1String("wvp")) { return QLatin1String("audio/x-wavpack"); - } else if (suffix == QLatin1String("ape")) { + } + if (suffix == QLatin1String("ape")) { return QLatin1String("audio/x-monkeys-audio"); // "audio/x-ape"; - } else if (suffix == QLatin1String("spx")) { + } + if (suffix == QLatin1String("spx")) { return QLatin1String("audio/x-speex"); - } else if (suffix == QLatin1String("tta")) { + } + if (suffix == QLatin1String("tta")) { return QLatin1String("audio/x-tta"); - } else if (suffix == QLatin1String("aiff") || suffix == QLatin1String("aif") || suffix == QLatin1String("aifc")) { + } + if (suffix == QLatin1String("aiff") || suffix == QLatin1String("aif") || suffix == QLatin1String("aifc")) { return QLatin1String("audio/x-aiff"); - } else if (suffix == QLatin1String("mpc") || suffix == QLatin1String("mpp") || suffix == QLatin1String("mp+")) { + } + if (suffix == QLatin1String("mpc") || suffix == QLatin1String("mpp") || suffix == QLatin1String("mp+")) { return QLatin1String("audio/x-musepack"); - } else if (suffix == QLatin1String("dff")) { + } + if (suffix == QLatin1String("dff")) { return QLatin1String("application/x-dff"); - } else if (suffix == QLatin1String("dsf")) { + } + if (suffix == QLatin1String("dsf")) { return QLatin1String("application/x-dsf"); - } else if (suffix == QLatin1String("opus")) { + } + if (suffix == QLatin1String("opus")) { return QLatin1String("audio/opus"); } diff --git a/online/jamendoservice.cpp b/online/jamendoservice.cpp index b1399f147..fb9aa05a9 100644 --- a/online/jamendoservice.cpp +++ b/online/jamendoservice.cpp @@ -32,22 +32,8 @@ #include #ifdef TAGLIB_FOUND -#include -#include -#include - -static QString tString2QString(const TagLib::String &str) -{ - static QTextCodec *codec = QTextCodec::codecForName("UTF-8"); - return codec->toUnicode(str.toCString(true)).trimmed(); -} - -static QString id3Genre(int id) -{ - // Clementine: In theory, genre 0 is "blues"; in practice it's invalid. - return 0==id ? QString() : tString2QString(TagLib::ID3v1::genre(id)); -} - +#include "tags.h" +using namespace Tags; #else static QString id3Genre(int id) { diff --git a/tags/tags.cpp b/tags/tags.cpp index 37ec20db2..bc5be30f7 100644 --- a/tags/tags.cpp +++ b/tags/tags.cpp @@ -64,6 +64,7 @@ #include #include #include +#include #ifdef TAGLIB_MP4_FOUND #include #endif @@ -1121,4 +1122,43 @@ Update embedImage(const QString &fileName, const QByteArray &cover) return fileref.isNull() ? Update_Failed : update(fileref, Song(), Song(), RgTags(), cover); } +QString oggMimeType(const QString &fileName) +{ + LOCK_MUTEX + #ifdef Q_OS_WIN32 + const wchar_t*encodedName=reinterpret_cast(fileName.constData()); + #else + const char *encodedName=QFile::encodeName(fileName).constData(); + #endif + + TagLib::Ogg::Vorbis::File vorbis(encodedName, false, TagLib::AudioProperties::Fast); + if (vorbis.isValid()) { + return QLatin1String("audio/x-vorbis+ogg"); + } + + TagLib::Ogg::FLAC::File flac(encodedName, false, TagLib::AudioProperties::Fast); + if (flac.isValid()) { + return QLatin1String("audio/x-flac+ogg"); + } + + TagLib::Ogg::Speex::File speex(encodedName, false, TagLib::AudioProperties::Fast); + if (speex.isValid()) { + return QLatin1String("audio/x-speex+ogg"); + } + + #ifdef TAGLIB_OPUS_FOUND + TagLib::Ogg::Opus::File opus(encodedName, false, TagLib::AudioProperties::Fast); + if (opus.isValid()) { + return QLatin1String("audio/x-opus+ogg"); + } + #endif + return QLatin1String("audio/ogg"); +} + +QString id3Genre(int id) +{ + // Clementine: In theory, genre 0 is "blues"; in practice it's invalid. + return 0==id ? QString() : tString2QString(TagLib::ID3v1::genre(id)); +} + } diff --git a/tags/tags.h b/tags/tags.h index 0dce2b097..9375e3bdb 100644 --- a/tags/tags.h +++ b/tags/tags.h @@ -85,7 +85,9 @@ namespace Tags extern ReplayGain readReplaygain(const QString &fileName); extern Update updateReplaygain(const QString &fileName, const ReplayGain &rg); extern Update embedImage(const QString &fileName, const QByteArray &cover); + extern QString oggMimeType(const QString &fileName); #endif + extern QString id3Genre(int id); } #ifdef ENABLE_EXTERNAL_TAGS