diff options
Diffstat (limited to 'tdefile-plugins/mp3')
-rw-r--r-- | tdefile-plugins/mp3/Makefile.am | 22 | ||||
-rw-r--r-- | tdefile-plugins/mp3/configure.in.in | 1 | ||||
-rw-r--r-- | tdefile-plugins/mp3/tdefile_mp3.cpp | 307 | ||||
-rw-r--r-- | tdefile-plugins/mp3/tdefile_mp3.desktop | 70 | ||||
-rw-r--r-- | tdefile-plugins/mp3/tdefile_mp3.h | 42 |
5 files changed, 442 insertions, 0 deletions
diff --git a/tdefile-plugins/mp3/Makefile.am b/tdefile-plugins/mp3/Makefile.am new file mode 100644 index 00000000..97fbe73d --- /dev/null +++ b/tdefile-plugins/mp3/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for mp3 file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) $(taglib_includes) + +# these are the headers for your project +noinst_HEADERS = tdefile_mp3.h + +kde_module_LTLIBRARIES = tdefile_mp3.la + +tdefile_mp3_la_SOURCES = tdefile_mp3.cpp +tdefile_mp3_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_KIO) -ltdetexteditor $(taglib_libs) -module $(KDE_PLUGIN) +tdefile_mp3_la_LIBADD = $(LIB_KIO) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) tdefile_mp3.cpp -o $(podir)/tdefile_mp3.pot + +services_DATA = tdefile_mp3.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/mp3/configure.in.in b/tdefile-plugins/mp3/configure.in.in new file mode 100644 index 00000000..d04bc223 --- /dev/null +++ b/tdefile-plugins/mp3/configure.in.in @@ -0,0 +1 @@ +AM_CONDITIONAL(include_mp3_SUBDIR, test "x$have_taglib" = xyes) diff --git a/tdefile-plugins/mp3/tdefile_mp3.cpp b/tdefile-plugins/mp3/tdefile_mp3.cpp new file mode 100644 index 00000000..ccabd079 --- /dev/null +++ b/tdefile-plugins/mp3/tdefile_mp3.cpp @@ -0,0 +1,307 @@ +/* This file is part of the KDE project + * Copyright (C) 2001, 2002 Rolf Magnus <ramagnus@kde.org> + * Copyright (C) 2002 Ryan Cumming <bodnar42@phalynx.dhs.org> + * Copyright (C) 2003 Scott Wheeler <wheeler@kde.org> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation version 2. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#include "tdefile_mp3.h" + +#include <kprocess.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kstringvalidator.h> +#include <kdebug.h> + +#include <tqdict.h> +#include <tqvalidator.h> +#include <tqcstring.h> +#include <tqfile.h> +#include <tqdatetime.h> + +#include <tstring.h> +#include <tag.h> +#include <mpegfile.h> +#include <id3v1genres.h> +#include <id3v2framefactory.h> + +typedef KGenericFactory<KMp3Plugin> Mp3Factory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_mp3, Mp3Factory( "tdefile_mp3" )) + +KMp3Plugin::KMp3Plugin(TQObject *parent, const char *name, const TQStringList &args) + : KFilePlugin(parent, name, args) +{ + kdDebug(7034) << "mp3 plugin\n"; + + KFileMimeTypeInfo *info = addMimeTypeInfo("audio/x-mp3"); + + // id3 group + + KFileMimeTypeInfo::GroupInfo *group = addGroupInfo(info, "id3", i18n("ID3 Tag")); + + setAttributes(group, KFileMimeTypeInfo::Addable | + KFileMimeTypeInfo::Removable); + + KFileMimeTypeInfo::ItemInfo *item; + + item = addItemInfo(group, "Title", i18n("Title"), TQVariant::String); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + setHint(item, KFileMimeTypeInfo::Name); + + item = addItemInfo(group, "Artist", i18n("Artist"), TQVariant::String); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + setHint(item, KFileMimeTypeInfo::Author); + + item = addItemInfo(group, "Album", i18n("Album"), TQVariant::String); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + + item = addItemInfo(group, "Date", i18n("Year"), TQVariant::String); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + + item = addItemInfo(group, "Comment", i18n("Comment"), TQVariant::String); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + setHint(item, KFileMimeTypeInfo::Description); + + item = addItemInfo(group, "Tracknumber", i18n("Track"), TQVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + + item = addItemInfo(group, "Genre", i18n("Genre"), TQVariant::String); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + + // technical group + + group = addGroupInfo(info, "Technical", i18n("Technical Details")); + + item = addItemInfo(group, "Version", i18n("Version"), TQVariant::Int); + setPrefix(item, i18n("MPEG ")); + + item = addItemInfo(group, "Layer", i18n("Layer"), TQVariant::Int); + item = addItemInfo(group, "CRC", i18n("CRC"), TQVariant::Bool); + item = addItemInfo(group, "Bitrate", i18n("Bitrate"), TQVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Averaged); + setHint(item, KFileMimeTypeInfo::Bitrate); + setSuffix(item, i18n(" kbps")); + + item = addItemInfo(group, "Sample Rate", i18n("Sample Rate"), TQVariant::Int); + setSuffix(item, i18n("Hz")); + + item = addItemInfo(group, "Channels", i18n("Channels"), TQVariant::Int); + item = addItemInfo(group, "Copyright", i18n("Copyright"), TQVariant::Bool); + item = addItemInfo(group, "Original", i18n("Original"), TQVariant::Bool); + item = addItemInfo(group, "Length", i18n("Length"), TQVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Cummulative); + setUnit(item, KFileMimeTypeInfo::Seconds); + item = addItemInfo(group, "Emphasis", i18n("Emphasis"), TQVariant::String); +} + +bool KMp3Plugin::readInfo(KFileMetaInfo &info, uint what) +{ + kdDebug(7034) << "mp3 plugin readInfo\n"; + + bool readId3 = false; + bool readTech = false; + + typedef enum KFileMetaInfo::What What; + + if(what & (KFileMetaInfo::Fastest | + KFileMetaInfo::DontCare | + KFileMetaInfo::ContentInfo)) + { + readId3 = true; + } + + if(what & (KFileMetaInfo::Fastest | + KFileMetaInfo::DontCare | + KFileMetaInfo::TechnicalInfo)) + { + readTech = true; + } + + if(!readId3 && !readTech) + return true; + + if ( info.path().isEmpty() ) // remote file + return false; + + TagLib::MPEG::File file(TQFile::encodeName(info.path()).data(), readTech); + + if(!file.isOpen()) + { + kdDebug(7034) << "Couldn't open " << file.name() << endl; + return false; + } + + if(readId3) + { + KFileMetaInfoGroup id3group = appendGroup(info, "id3"); + + TQString date = file.tag()->year() > 0 ? TQString::number(file.tag()->year()) : TQString(); + TQString track = file.tag()->track() > 0 ? TQString::number(file.tag()->track()) : TQString(); + + TQString title = TQString(TStringToQString(file.tag()->title())).stripWhiteSpace(); + if (!title.isEmpty()) + appendItem(id3group, "Title", title); + TQString artist = TQString(TStringToQString(file.tag()->artist())).stripWhiteSpace(); + if (!artist.isEmpty()) + appendItem(id3group, "Artist", artist); + TQString album = TQString(TStringToQString(file.tag()->album())).stripWhiteSpace(); + if (!album.isEmpty()) + appendItem(id3group, "Album", album); + appendItem(id3group, "Date", date); + TQString comment = TQString(TStringToQString(file.tag()->comment())).stripWhiteSpace(); + if (!comment.isEmpty()) + appendItem(id3group, "Comment", comment); + appendItem(id3group, "Tracknumber", track); + TQString genre = TQString(TStringToQString(file.tag()->genre())).stripWhiteSpace(); + if (!genre.isEmpty()) + appendItem(id3group, "Genre", genre); + } + + if(readTech) + { + KFileMetaInfoGroup techgroup = appendGroup(info, "Technical"); + + TQString version; + switch(file.audioProperties()->version()) + { + case TagLib::MPEG::Header::Version1: + version = "1.0"; + break; + case TagLib::MPEG::Header::Version2: + version = "2.0"; + break; + case TagLib::MPEG::Header::Version2_5: + version = "2.5"; + break; + } + + static const int dummy = 0; // TQVariant's bool constructor requires a dummy int value. + + // CRC and Emphasis aren't yet implemented in TagLib (not that I think anyone cares) + + appendItem(techgroup, "Version", version); + appendItem(techgroup, "Layer", file.audioProperties()->layer()); + // appendItem(techgroup, "CRC", file.audioProperties()->crc()); + appendItem(techgroup, "Bitrate", file.audioProperties()->bitrate()); + appendItem(techgroup, "Sample Rate", file.audioProperties()->sampleRate()); + appendItem(techgroup, "Channels", file.audioProperties()->channels()); + appendItem(techgroup, "Copyright", TQVariant(file.audioProperties()->isCopyrighted(), dummy)); + appendItem(techgroup, "Original", TQVariant(file.audioProperties()->isOriginal(), dummy)); + appendItem(techgroup, "Length", file.audioProperties()->length()); + // appendItem(techgroup, "Emphasis", file.audioProperties()->empahsis()); + } + + kdDebug(7034) << "reading finished\n"; + + return true; +} + +/** + * Do translation between KFileMetaInfo items and TagLib::String in a tidy way. + */ + +class Translator +{ +public: + Translator(const KFileMetaInfo &info) : m_info(info) {} + TagLib::String operator[](const char *key) const + { + return QStringToTString(m_info["id3"][key].value().toString()); + } + int toInt(const char *key) const + { + return m_info["id3"][key].value().toInt(); + } +private: + const KFileMetaInfo &m_info; +}; + +bool KMp3Plugin::writeInfo(const KFileMetaInfo &info) const +{ + TagLib::ID3v2::FrameFactory::instance()->setDefaultTextEncoding(TagLib::String::UTF8); + TagLib::MPEG::File file(TQFile::encodeName(info.path()).data(), false); + + if(!file.isOpen() || !TagLib::File::isWritable(file.name())) + { + kdDebug(7034) << "couldn't open " << info.path() << endl; + return false; + } + + Translator t(info); + + file.tag()->setTitle(t["Title"]); + file.tag()->setArtist(t["Artist"]); + file.tag()->setAlbum(t["Album"]); + file.tag()->setYear(t.toInt("Date")); + file.tag()->setComment(t["Comment"]); + file.tag()->setTrack(t.toInt("Tracknumber")); + file.tag()->setGenre(t["Genre"]); + + file.save(); + + return true; +} + +/** + * A validator that will suggest a list of strings, but allow for free form + * strings as well. + */ + +class ComboValidator : public KStringListValidator +{ +public: + ComboValidator(const TQStringList &list, bool rejecting, + bool fixupEnabled, TQObject *parent, const char *name) : + KStringListValidator(list, rejecting, fixupEnabled, parent, name) + { + + } + + virtual TQValidator::State validate(TQString &, int &) const + { + return TQValidator::Acceptable; + } +}; + +TQValidator *KMp3Plugin::createValidator(const TQString & /* mimetype */, + const TQString &group, const TQString &key, + TQObject *parent, const char *name) const +{ + kdDebug(7034) << "making a validator for " << group << "/" << key << endl; + + if(key == "Tracknumber" || key == "Date") + { + return new TQIntValidator(0, 9999, parent, name); + } + + if(key == "Genre") + { + TQStringList l; + TagLib::StringList genres = TagLib::ID3v1::genreList(); + for(TagLib::StringList::ConstIterator it = genres.begin(); it != genres.end(); ++it) + { + l.append(TStringToQString((*it))); + } + return new ComboValidator(l, false, true, parent, name); + } + + return 0; +} + +#include "tdefile_mp3.moc" diff --git a/tdefile-plugins/mp3/tdefile_mp3.desktop b/tdefile-plugins/mp3/tdefile_mp3.desktop new file mode 100644 index 00000000..2f83b875 --- /dev/null +++ b/tdefile-plugins/mp3/tdefile_mp3.desktop @@ -0,0 +1,70 @@ +[Desktop Entry] +Type=Service +Name=MP3 Info +Name[af]=Mp3 Inligting +Name[ar]=معلومات MP3 +Name[bg]=Информация за MP3 +Name[bn]=এম-পি-৩ (MP3) তথ্য +Name[br]=Titouroù MP3 +Name[bs]=MP3 informacije +Name[ca]=Informació MP3 +Name[cs]=MP3 info +Name[cy]=Gwybodaeth MP3 +Name[da]=MP3-info +Name[de]=MP3-Info +Name[el]=Πληροφορίες MP3 +Name[eo]=MP3-informo +Name[es]=Info MP3 +Name[et]=MP3 info +Name[eu]=MP3 informazioa +Name[fa]=اطلاعات MP3 +Name[fi]=MP3-tiedot +Name[fr]=Informations Mpeg3 +Name[gl]=Información MP3 +Name[he]=מידע MP3 +Name[hi]=MP3 जानकारी +Name[hr]=Informacije o MP3 datoteci +Name[hu]=MP3-jellemzők +Name[is]=MP3 upplýsingar +Name[it]=Informazioni MP3 +Name[ja]=MP3 情報 +Name[kk]=MP3 мәліметі +Name[km]=ព័ត៌មាន MP3 +Name[ko]=MP3 정보 +Name[lt]=MP3 informacija +Name[mk]=MP3 информации +Name[nb]=MP3 informasjon +Name[nds]=MP3-Info +Name[ne]=MP3 सूचना +Name[nl]=MP3-informatie +Name[nn]=MP3-info +Name[pa]=MP3 ਜਾਣਕਾਰੀ +Name[pl]=Informacja o pliku MP3 +Name[pt]=Informação do MP3 +Name[pt_BR]=Informações sobre MP3 +Name[ro]=Informaţii MP3 +Name[ru]=Сведения о MP3 +Name[rw]=Amakuru MP3 +Name[se]=MP3-dieđut +Name[sl]=Podatki o MP3 +Name[sr]=Информације о MP3-ју +Name[sr@Latn]=Informacije o MP3-ju +Name[sv]=MP3-information +Name[ta]=MP3 தகவல் +Name[tg]=MP3 Ахборот +Name[th]=ข้อมูล MP3 +Name[tr]=MP3 Bilgisi +Name[uk]=Інформація по MP3 +Name[uz]=MP3 haqida maʼlumot +Name[uz@cyrillic]=MP3 ҳақида маълумот +Name[wa]=Infôrmåcion MP3 +Name[xh]=MP3 ulwazi +Name[zh_CN]=MP3 信息 +Name[zh_HK]=MP3 資訊 +Name[zh_TW]=MP3 資訊 +Name[zu]=Ulwazi lwe-MP3 +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_mp3 +MimeType=audio/x-mp3 +PreferredGroups=id3,Technical +PreferredItems=Title,Artist,Album,Tracknumber,Genre,Bitrate,Length,Date,Comment,Sample Rate,Channels,Version,Layer,Copyright,Original,CRC diff --git a/tdefile-plugins/mp3/tdefile_mp3.h b/tdefile-plugins/mp3/tdefile_mp3.h new file mode 100644 index 00000000..209c81a6 --- /dev/null +++ b/tdefile-plugins/mp3/tdefile_mp3.h @@ -0,0 +1,42 @@ +/* This file is part of the KDE project + * Copyright (C) 2001, 2002 Rolf Magnus <ramagnus@kde.org> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation version 2. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __KFILE_MP3_H__ +#define __KFILE_MP3_H__ + +#include <tdefilemetainfo.h> + +class TQStringList; + +class KMp3Plugin: public KFilePlugin +{ + Q_OBJECT + + +public: + KMp3Plugin(TQObject *parent, const char *name, const TQStringList &args); + + virtual bool readInfo( KFileMetaInfo& info, uint what ); + virtual bool writeInfo( const KFileMetaInfo& info) const; + virtual TQValidator *createValidator(const TQString &mimetype, + const TQString &group, + const TQString &key, + TQObject *parent, const char *name) const; +}; + +#endif |