Commit 2660b318 authored by Scott Wheeler's avatar Scott Wheeler
Browse files

id3lib is no more; long live taglib. More to come soon.

svn path=/trunk/kdemultimedia/juk/; revision=262517
parent e93b8512
...@@ -4,7 +4,7 @@ check_PROGRAMS = tagguessertest mbtest ...@@ -4,7 +4,7 @@ check_PROGRAMS = tagguessertest mbtest
juk_SOURCES = directorylistbase.ui \ juk_SOURCES = directorylistbase.ui \
gstreamerplayer.cpp artsplayer.cpp directorylist.cpp stringhash.cpp \ gstreamerplayer.cpp artsplayer.cpp directorylist.cpp stringhash.cpp \
sortedstringlist.cpp systemtray.cpp splashscreen.cpp \ sortedstringlist.cpp systemtray.cpp splashscreen.cpp \
statuslabel.cpp cachedtag.cpp oggtag.cpp id3tag.cpp collectionlist.cpp \ statuslabel.cpp cachedtag.cpp collectionlist.cpp \
playlistitem.cpp playlist.cpp playlistsplitter.cpp \ playlistitem.cpp playlist.cpp playlistsplitter.cpp \
playlistbox.cpp tageditor.cpp cache.cpp genrelistreader.cpp \ playlistbox.cpp tageditor.cpp cache.cpp genrelistreader.cpp \
genrelistlist.cpp genrelist.cpp genre.cpp player.cpp tag.cpp customaction.cpp \ genrelistlist.cpp genrelist.cpp genre.cpp player.cpp tag.cpp customaction.cpp \
...@@ -20,7 +20,7 @@ juk_SOURCES = directorylistbase.ui \ ...@@ -20,7 +20,7 @@ juk_SOURCES = directorylistbase.ui \
tagguessertest_SOURCES = tagguessertest.cpp tagguesser.cpp tagguessertest_SOURCES = tagguessertest.cpp tagguesser.cpp
mbtest_SOURCES = mbtest.cpp musicbrainzquery.cpp mbtest_SOURCES = mbtest.cpp musicbrainzquery.cpp
INCLUDES= $(all_includes) -I$(arts_includes) INCLUDES= $(all_includes) -I$(arts_includes) $(taglib_includes)
################################################## ##################################################
# check to see if GStreamer is available # check to see if GStreamer is available
...@@ -38,7 +38,7 @@ mblibs = -lmusicbrainz ...@@ -38,7 +38,7 @@ mblibs = -lmusicbrainz
endif endif
################################################## ##################################################
juk_LDADD = $(gstlibs) $(mblibs) -lid3 -lartskde $(LIB_KIO) juk_LDADD = $(gstlibs) $(mblibs) -lartskde $(LIB_KIO) $(taglib_libs)
juk_LDFLAGS = $(all_libraries) $(KDE_RPATH) juk_LDFLAGS = $(all_libraries) $(KDE_RPATH)
tagguessertest_LDADD = $(LIB_KDECORE) tagguessertest_LDADD = $(LIB_KDECORE)
......
...@@ -119,7 +119,7 @@ void Cache::load() ...@@ -119,7 +119,7 @@ void Cache::load()
QString fileName; QString fileName;
s >> fileName; s >> fileName;
fileName.squeeze(); //fileName.squeeze();
CachedTag *t = new CachedTag(fileName); CachedTag *t = new CachedTag(fileName);
s >> *t; s >> *t;
......
...@@ -196,7 +196,7 @@ QDataStream &CachedTag::read(QDataStream &s) ...@@ -196,7 +196,7 @@ QDataStream &CachedTag::read(QDataStream &s)
>> m_tagLengthString >> m_tagLengthString
>> m_tagSeconds >> m_tagSeconds
>> dummyString // TODO: remove >> dummyString // TODO: remove
>> m_modificationTime; >> m_modificationTime;
//Try to reduce memory usage: share tags that frequently repeat, squeeze others //Try to reduce memory usage: share tags that frequently repeat, squeeze others
...@@ -208,7 +208,6 @@ QDataStream &CachedTag::read(QDataStream &s) ...@@ -208,7 +208,6 @@ QDataStream &CachedTag::read(QDataStream &s)
m_tagYearString = StringShare::tryShare(m_tagYearString); m_tagYearString = StringShare::tryShare(m_tagYearString);
m_tagBitrateString = StringShare::tryShare(m_tagBitrateString); m_tagBitrateString = StringShare::tryShare(m_tagBitrateString);
m_tagLengthString.squeeze(); m_tagLengthString.squeeze();
return s; return s;
} }
......
if test "x$have_id3lib" = "xfalse"; then if test "x$have_taglib" = "xfalse"; then
echo "**************************************************" echo "**************************************************"
echo "*" echo "*"
echo "* id3lib 3.8.0 or greater is required by JuK." echo "* JuK will not be built without TagLib. TagLib"
echo "* JuK will be disabled from compilation." echo "* replaces the id3lib dependancy. See the notice"
echo "* id3lib is available at http://id3lib.sf.net/" echo "* above for where to find TagLib."
echo "* or as part of most Linux distributions."
echo "*" echo "*"
echo "**************************************************" echo "**************************************************"
fi fi
......
#MIN_CONFIG(3) #MIN_CONFIG(3)
have_id3lib=true
AM_INIT_AUTOMAKE(juk,1.0) AM_INIT_AUTOMAKE(juk,1.0)
AC_DEFUN(AC_NO_ID3LIB, if test "x$have_taglib" = "xfalse"; then
[
have_id3lib=false
DO_NOT_COMPILE="$DO_NOT_COMPILE juk" DO_NOT_COMPILE="$DO_NOT_COMPILE juk"
]) fi
KDE_CHECK_HEADER(id3/tag.h,
,
AC_NO_ID3LIB
)
AC_DEFUN(AC_HAVE_GST, AC_DEFUN(AC_HAVE_GST,
[ [
......
/***************************************************************************
id3tag.cpp - description
-------------------
begin : Sun Feb 17 2002
copyright : (C) 2002 by Scott Wheeler
email : 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; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <kdebug.h>
#include <qdir.h>
#include <qregexp.h>
#include <id3/misc_support.h>
#include "id3tag.h"
#include "genrelistlist.h"
// Warning: Some of this code is really old (~2 years) and may reflect some of
// my C days and or general bad design. However, I haven't gone to great length
// to replace it since it will be replaced when TagLib is ready to drop in.
// Basically, if you are looking for an example of my programming style -- look
// into the other classes. This is a leftover from QTagger 0.1. ;-)
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
ID3Tag::ID3Tag(const QString &fileName) : Tag(fileName),
m_fileName(fileName), m_changed(false)
{
m_metaInfo = KFileMetaInfo(fileName, QString::null, KFileMetaInfo::Fastest);
m_tag.Link(m_fileName.latin1());
// the easy ones -- these are supported in the id3 class
char *temp;
temp = ID3_GetArtist(&m_tag);
m_tagArtist = temp;
delete [] temp;
temp = ID3_GetAlbum(&m_tag);
m_tagAlbum = temp;
delete [] temp;
temp = ID3_GetTitle(&m_tag);
m_tagTrack = temp;
delete [] temp;
temp = ID3_GetTrack(&m_tag);
m_tagTrackNumberString = temp;
delete [] temp;
m_tagTrackNumberString.replace(QRegExp("^0+"), QString::null);
m_tagTrackNumber = ID3_GetTrackNum(&m_tag);
temp = ID3_GetComment(&m_tag);
m_tagComment = temp;
delete [] temp;
temp = ID3_GetGenre(&m_tag);
m_tagGenre.setName(temp);
delete [] temp;
m_tagGenre.setID3v1(int(ID3_GetGenreNum(&m_tag)));
temp = ID3_GetYear(&m_tag);
m_tagYearString = temp;
delete [] temp;
m_tagExists = (m_tag.HasV2Tag() || m_tag.HasV1Tag());
if(m_tagTrack.length() <= 0) {
m_tagTrack = m_fileName;
while((m_tagTrack.right(4)).lower() == ".mp3")
m_tagTrack = m_tagTrack.left(m_tagTrack.length() - 4);
m_tagTrack = m_tagTrack.right(m_tagTrack.length() - m_tagTrack.findRev(QDir::separator(), -1) -1);
}
// parse the genre string for (<ID3v1 number>)
if(m_tagGenre.name() == "(" + QString::number(m_tagGenre.ID3v1()) + ")" || m_tagGenre.name().isNull())
m_tagGenre.setName(GenreListList::ID3v1List().ID3v1Name(m_tagGenre.ID3v1()));
else if(m_tagGenre.name().find(QRegExp("\\([0-9]+\\)")) == 0)
m_tagGenre.setName(m_tagGenre.name().mid(m_tagGenre.name().find(")") + 1));
// convert the year
m_tagYear = m_tagYearString.toInt();
if(m_tagYear <= 0)
m_tagYearString = QString::null;
}
ID3Tag::~ID3Tag()
{
}
void ID3Tag::save()
{
if(m_changed) {
if(m_tagArtist.length() > 0)
ID3_AddArtist(&m_tag, m_tagArtist.latin1(), true);
else
ID3_RemoveArtists(&m_tag);
if(m_tagAlbum.length() > 0)
ID3_AddAlbum(&m_tag, m_tagAlbum.latin1(), true);
else
ID3_RemoveAlbums(&m_tag);
if(m_tagTrack.length() > 0)
ID3_AddTitle(&m_tag, m_tagTrack.latin1(), true);
else
ID3_RemoveTitles(&m_tag);
if(m_tagTrackNumber > 0)
ID3_AddTrack(&m_tag, uchar(m_tagTrackNumber), uchar(0), true);
else
ID3_RemoveTracks(&m_tag);
if(m_tagGenre.ID3v1() >= 0 && m_tagGenre.ID3v1() < int(GenreListList::ID3v1List().count())) {
QString genreString;
if(m_tagGenre.name() != GenreListList::ID3v1List().ID3v1Name(m_tagGenre.ID3v1()))
genreString = "(" + QString::number(m_tagGenre.ID3v1()) + ")" + m_tagGenre.name();
else
genreString = "(" + QString::number(m_tagGenre.ID3v1()) + ")";
ID3_AddGenre(&m_tag, genreString.latin1(), true);
}
else
ID3_RemoveGenres(&m_tag);
if(m_tagYear > 0)
ID3_AddYear(&m_tag, m_tagYearString.latin1(), true);
else
ID3_RemoveYears(&m_tag);
ID3_RemoveComments(&m_tag);
if(m_tagComment.length()>0)
ID3_AddComment(&m_tag, m_tagComment.latin1(), true);
m_tag.Update();
m_changed = false;
}
}
QString ID3Tag::track() const // The song's name, not it's track number
{
return m_tagTrack;
}
QString ID3Tag::artist() const
{
return m_tagArtist;
}
QString ID3Tag::album() const
{
return m_tagAlbum;
}
Genre ID3Tag::genre() const
{
return m_tagGenre;
}
int ID3Tag::trackNumber() const
{
return m_tagTrackNumber;
}
QString ID3Tag::trackNumberString() const
{
return m_tagTrackNumberString;
}
int ID3Tag::year() const
{
return m_tagYear;
}
QString ID3Tag::yearString() const
{
return m_tagYearString;
}
QString ID3Tag::comment() const
{
return m_tagComment;
}
/////////////////////////////////////////////////////
// functions that set information
/////////////////////////////////////////////////////
void ID3Tag::setTrack(const QString &value)
{
m_changed = true;
m_tagTrack = value;
}
void ID3Tag::setArtist(const QString &value)
{
m_changed = true;
m_tagArtist = value;
}
void ID3Tag::setAlbum(const QString &value)
{
m_changed = true;
m_tagAlbum = value;
}
void ID3Tag::setGenre(const Genre &value)
{
m_changed = true;
m_tagGenre = value;
}
void ID3Tag::setTrackNumber(int value)
{
m_changed = true;
m_tagTrackNumber = value;
if(m_tagTrackNumber > 0)
m_tagTrackNumberString.setNum(value);
else
m_tagTrackNumberString = QString::null;
}
void ID3Tag::setYear(int value)
{
m_changed = true;
m_tagYear = value;
if(m_tagYear > 0)
m_tagYearString.setNum(value);
else
m_tagYearString = QString::null;
}
void ID3Tag::setComment(const QString &value)
{
m_changed = true;
m_tagComment = value;
}
QString ID3Tag::bitrateString() const
{
return readBitrate(m_metaInfo);
}
QString ID3Tag::lengthString() const
{
return readLength(m_metaInfo);
}
int ID3Tag::seconds() const
{
return readSeconds(m_metaInfo);
}
/***************************************************************************
id3tag.h - description
-------------------
begin : Sun Feb 17 2002
copyright : (C) 2002 by Scott Wheeler
email : 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; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef ID3TAG_H
#define ID3TAG_H
#include <qstring.h>
#include <id3/tag.h>
#include "tag.h"
class ID3Tag : public Tag
{
public:
ID3Tag(const QString &fileName);
virtual ~ID3Tag();
virtual void save();
virtual QString track() const;
virtual QString artist() const;
virtual QString album() const;
virtual Genre genre() const;
virtual int trackNumber() const;
virtual QString trackNumberString() const;
virtual int year() const;
virtual QString yearString() const;
virtual QString comment() const;
virtual void setTrack(const QString &value);
virtual void setArtist(const QString &value);
virtual void setAlbum(const QString &value);
virtual void setGenre(const Genre &value);
virtual void setTrackNumber(int value);
virtual void setYear(int value);
virtual void setComment(const QString &value);
virtual QString bitrateString() const;
virtual QString lengthString() const;
virtual int seconds() const;
private:
ID3_Tag m_tag;
QString m_fileName;
bool m_changed;
QString m_tagTrack;
QString m_tagArtist;
QString m_tagAlbum;
Genre m_tagGenre;
int m_tagTrackNumber;
QString m_tagTrackNumberString;
int m_tagYear;
QString m_tagYearString;
QString m_tagComment;
bool m_tagExists;
KFileMetaInfo m_metaInfo;
};
#endif
/***************************************************************************
oggtag.cpp - description
-------------------
begin : Sat Oct 5 2002
copyright : (C) 2002 by Scott Wheeler
email : 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; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <kdebug.h>
#include <qregexp.h>
#include "oggtag.h"
#include "genrelistlist.h"
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
OggTag::OggTag(const QString &fileName) : Tag(fileName)
{
m_fileInfo.setFile(fileName);
m_metaInfo = KFileMetaInfo(fileName);
m_commentGroup = KFileMetaInfoGroup(m_metaInfo.group("Comment"));
}
OggTag::~OggTag()
{
}
void OggTag::save()
{
m_metaInfo.applyChanges();
}
QString OggTag::track() const
{
QString s = readCommentString("Title");
if(s.stripWhiteSpace().isEmpty())
s = m_fileInfo.baseName();
return s;
}
QString OggTag::artist() const
{
return readCommentString("Artist");
}
QString OggTag::album() const
{
return readCommentString("Album");
}
Genre OggTag::genre() const
{
QString genreName = readCommentString("Genre");
int index = GenreListList::ID3v1List().findIndex(genreName);
return Genre(genreName, index);
}
int OggTag::trackNumber() const
{
return readCommentInt("Tracknumber");
}
QString OggTag::trackNumberString() const
{
QString s = readCommentString("Tracknumber");
return s.replace(QRegExp("^0+"), QString::null);
}
int OggTag::year() const
{
QDateTime d = QDateTime::fromString(readCommentString("Date"), Qt::ISODate);
if(d.isValid())
return d.date().year();
else
return 0;
}
QString OggTag::yearString() const
{
QDateTime d = QDate::fromString(readCommentString("Date"), Qt::ISODate);
if(d.isValid())
return QString::number(d.date().year());
else
return QString::null;
}
QString OggTag::comment() const
{
return readCommentString("Description");
}
void OggTag::setTrack(const QString &value)
{
writeCommentItem("Title", value);
}
void OggTag::setArtist(const QString &value)
{
writeCommentItem("Artist", value);
}
void OggTag::setAlbum(const QString &value)
{
writeCommentItem("Album", value);
}
void OggTag::setGenre(const Genre &value)
{
writeCommentItem("Genre", value.name());
}
void OggTag::setTrackNumber(int value)
{
writeCommentItem("Tracknumber", value);
}
void OggTag::setYear(int value)
{
if(value == 0) {
writeCommentItem("Date", QString::null);
return;
}
QDate d = QDate::fromString(readCommentString("Date"), Qt::ISODate);
if(d.setYMD(value, d.month(), d.day())) {
QDateTime dt = d;
writeCommentItem("Date", dt.toString(Qt::ISODate));
}
}
void OggTag::setComment(const QString &value)
{
writeCommentItem("Description", value);
}
QString OggTag::bitrateString() const
{
return readBitrate(m_metaInfo);
}
QString OggTag::lengthString() const
{
return readLength(m_metaInfo);
}