Ejemplo n.º 1
0
/**
 * Open a file via taglib and add file type information
 *
 * Open files, that taglib supports but taggit doesn't have specific support
 * for using TagLibs generic interface only. That will stop us from working
 * with multi-artist files for those types, but it's better than nothing.
 *
 * @param   file    file name to open
 *
 * @return      copy of the generated struct taggit_file; *NOT* a pointer
 *              to it! Destroy using taggit_file_destroy().
 * @sideeffects none
 */
struct taggit_file
taggit_file_open(const char *file)
{
    struct taggit_file rc;
    char *ext;

    ext = (char *)strrchr(file, (int)'.');
    if (ext == NULL || *(ext + 1) == '\0')
        goto err;

    ext++;
    if (strcaseeq(ext, (char *)"mp3")) {
        rc.data = reinterpret_cast<TagLib_File *>
            (new TagLib::MPEG::File(file));
        rc.type = FT_MPEG;
    } else if (strcaseeq(ext, (char *)"ogg")) {
        rc.data = reinterpret_cast<TagLib_File *>
            (new TagLib::Ogg::Vorbis::File(file));
        rc.type = FT_OGGVORBIS;
    } else if (strcaseeq(ext, (char *)"oga")) {
        TagLib::File *f;

        f = new TagLib::Ogg::FLAC::File(file);
        if (f->isValid()) {
            rc.data = reinterpret_cast<TagLib_File *>(f);
            rc.type = FT_OGGFLAC;
        } else {
            delete f;
            rc.data = reinterpret_cast<TagLib_File *>
                (new TagLib::Ogg::Vorbis::File(file));
            rc.type = FT_OGGVORBIS;
        }
    } else if (strcaseeq(ext, (char *)"flac")) {
        rc.data = reinterpret_cast<TagLib_File *>
            (new TagLib::FLAC::File(file));
        rc.type = FT_FLAC;
    } else {
        TagLib_File *f;

        f = taglib_file_new(file);
        if (!taglib_file_is_valid(f)) {
            taglib_file_free(f);
            goto err;
        } else {
            rc.data = f;
            rc.type = FT_UNKNOWN;
        }
    }

    return rc;

err:
    fprintf(stderr, "Cannot handle file: \"%s\" - skipping.\n", file);
    rc.data = NULL;
    rc.type = FT_INVALID;
    return rc;
}
Ejemplo n.º 2
0
bool KMpcPlugin::writeInfo(const KFileMetaInfo& info) const
{
    TagLib::File *file;

    if (!TagLib::File::isWritable(QFile::encodeName(info.path()).data())) {
        kDebug(7034) << "can't write to " << info.path();
        return false;
    }

    file = new TagLib::MPC::File(QFile::encodeName(info.path()).data(), false);

    if(!file->isOpen())
    {
        kDebug(7034) << "couldn't open " << info.path();
        delete file;
        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();

    delete file;
    return true;
}
Ejemplo n.º 3
0
 uint read(TagLib::File &file, uint limit)
 {
   ByteVector data = file.readBlock(std::min(1U,limit));
   if(data.size() > 0) {
     value = data[0];
   }
   return data.size();
 }
Ejemplo n.º 4
0
 uint read(TagLib::File &file, uint limit)
 {
   ByteVector data = file.readBlock(std::min(m_size, limit));
   uint count = data.size();
   int index = data.find((char) 0);
   if(index > -1) {
     data.resize(index);
   }
   data.replace((char) 0xff, ' ');
   value = data;
   return count;
 }
Ejemplo n.º 5
0
bool KFlacPlugin::writeInfo(const KFileMetaInfo& info) const
{
    TagLib::File *file;

    if (!TagLib::File::isWritable(QFile::encodeName(info.path()).data())) {
        kdDebug(7034) << "can't write to " << info.path() << endl;
        return false;
    }

    if (info.mimeType() == "audio/x-flac")
        file = new TagLib::FLAC::File(QFile::encodeName(info.path()).data(), false);
#ifdef TAGLIB_1_2
    else
        file = new TagLib::Ogg::FLAC::File(QFile::encodeName(info.path()).data(), false);
#endif

    if(!file->isOpen())
    {
        kdDebug(7034) << "couldn't open " << info.path() << endl;
        delete file;
        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();

    delete file;
    return true;
}
Ejemplo n.º 6
0
bool CTagLoaderTagLib::Load(const std::string& strFileName, CMusicInfoTag& tag, const std::string& fallbackFileExtension, MUSIC_INFO::EmbeddedArt *art /* = NULL */)
{
  std::string strExtension = URIUtils::GetExtension(strFileName);
  StringUtils::TrimLeft(strExtension, ".");

  if (strExtension.empty())
  {
    strExtension = fallbackFileExtension;
    if (strExtension.empty())
      return false;
  }

  StringUtils::ToLower(strExtension);
  TagLibVFSStream*           stream = new TagLibVFSStream(strFileName, true);
  if (!stream)
  {
    CLog::Log(LOGERROR, "could not create TagLib VFS stream for: %s", strFileName.c_str());
    return false;
  }

  ID3v1::Tag::setStringHandler(&ID3v1StringHandler);
  ID3v2::Tag::setLatin1StringHandler(&ID3v2StringHandler);
  TagLib::File*              file = NULL;
  TagLib::APE::File*         apeFile = NULL;
  TagLib::ASF::File*         asfFile = NULL;
  TagLib::FLAC::File*        flacFile = NULL;
  TagLib::IT::File*          itFile = NULL;
  TagLib::Mod::File*         modFile = NULL;
  TagLib::MP4::File*         mp4File = NULL;
  TagLib::MPC::File*         mpcFile = NULL;
  TagLib::MPEG::File*        mpegFile = NULL;
  TagLib::Ogg::Vorbis::File* oggVorbisFile = NULL;
  TagLib::Ogg::FLAC::File*   oggFlacFile = NULL;
  TagLib::S3M::File*         s3mFile = NULL;
  TagLib::TrueAudio::File*   ttaFile = NULL;
  TagLib::WavPack::File*     wvFile = NULL;
  TagLib::XM::File*          xmFile = NULL;
  TagLib::RIFF::WAV::File *  wavFile = NULL;
  TagLib::RIFF::AIFF::File * aiffFile = NULL;

  if (strExtension == "ape")
    file = apeFile = new APE::File(stream);
  else if (strExtension == "asf" || strExtension == "wmv" || strExtension == "wma")
    file = asfFile = new ASF::File(stream);
  else if (strExtension == "flac")
    file = flacFile = new FLAC::File(stream, ID3v2::FrameFactory::instance());
  else if (strExtension == "it")
    file = itFile = new IT::File(stream);
  else if (strExtension == "mod" || strExtension == "module" || strExtension == "nst" || strExtension == "wow")
    file = modFile = new Mod::File(stream);
  else if (strExtension == "mp4" || strExtension == "m4a" ||
           strExtension == "m4r" || strExtension == "m4b" ||
           strExtension == "m4p" || strExtension == "3g2")
    file = mp4File = new MP4::File(stream);
  else if (strExtension == "mpc")
    file = mpcFile = new MPC::File(stream);
  else if (strExtension == "mp3" || strExtension == "aac")
    file = mpegFile = new MPEG::File(stream, ID3v2::FrameFactory::instance());
  else if (strExtension == "s3m")
    file = s3mFile = new S3M::File(stream);
  else if (strExtension == "tta")
    file = ttaFile = new TrueAudio::File(stream, ID3v2::FrameFactory::instance());
  else if (strExtension == "wv")
    file = wvFile = new WavPack::File(stream);
  else if (strExtension == "aif" || strExtension == "aiff")
    file = aiffFile = new RIFF::AIFF::File(stream);
  else if (strExtension == "wav")
    file = wavFile = new RIFF::WAV::File(stream);
  else if (strExtension == "xm")
    file = xmFile = new XM::File(stream);
  else if (strExtension == "ogg")
    file = oggVorbisFile = new Ogg::Vorbis::File(stream);
  else if (strExtension == "oga") // Leave this madness until last - oga container can have Vorbis or FLAC
  {
    file = oggFlacFile = new Ogg::FLAC::File(stream);
    if (!file || !file->isValid())
    {
      delete file;
      oggFlacFile = NULL;
      file = oggVorbisFile = new Ogg::Vorbis::File(stream);
    }
  }

  if (!file || !file->isOpen())
  {
    delete file;
    delete stream;
    CLog::Log(LOGDEBUG, "file could not be opened for tag reading");
    return false;
  }

  APE::Tag *ape = NULL;
  ASF::Tag *asf = NULL;
  MP4::Tag *mp4 = NULL;
  ID3v1::Tag *id3v1 = NULL;
  ID3v2::Tag *id3v2 = NULL;
  Ogg::XiphComment *xiph = NULL;
  Tag *generic = NULL;

  if (apeFile)
    ape = apeFile->APETag(false);
  else if (asfFile)
    asf = asfFile->tag();
  else if (flacFile)
  {
    xiph = flacFile->xiphComment(false);
    id3v2 = flacFile->ID3v2Tag(false);
  }
  else if (mp4File)
    mp4 = mp4File->tag();
  else if (mpegFile)
  {
    id3v1 = mpegFile->ID3v1Tag(false);
    id3v2 = mpegFile->ID3v2Tag(false);
    ape = mpegFile->APETag(false);
  }
  else if (oggFlacFile)
    xiph = dynamic_cast<Ogg::XiphComment *>(oggFlacFile->tag());
  else if (oggVorbisFile)
    xiph = dynamic_cast<Ogg::XiphComment *>(oggVorbisFile->tag());
  else if (ttaFile)
    id3v2 = ttaFile->ID3v2Tag(false);
  else if (aiffFile)
    id3v2 = aiffFile->tag();
  else if (wavFile)
#if TAGLIB_MAJOR_VERSION > 1 || TAGLIB_MINOR_VERSION > 8
    id3v2 = wavFile->ID3v2Tag();
#else
    id3v2 = wavFile->tag();
#endif
  else if (wvFile)
Ejemplo n.º 7
0
bool SoundSource::processTaglibFile(TagLib::File& f) {
    if (s_bDebugMetadata)
        qDebug() << "Parsing" << getFilename();

    if (f.isValid()) {
        TagLib::Tag *tag = f.tag();
        if (tag) {
            QString title = TStringToQString(tag->title());
            setTitle(title);

            QString artist = TStringToQString(tag->artist());
            setArtist(artist);

            QString album = TStringToQString(tag->album());
            setAlbum(album);

            QString comment = TStringToQString(tag->comment());
            setComment(comment);

            QString genre = TStringToQString(tag->genre());
            setGenre(genre);

            int iYear = tag->year();
            QString year = "";
            if (iYear > 0) {
                year = QString("%1").arg(iYear);
                setYear(year);
            }

            int iTrack = tag->track();
            QString trackNumber = "";
            if (iTrack > 0) {
                trackNumber = QString("%1").arg(iTrack);
                setTrackNumber(trackNumber);
            }

            if (s_bDebugMetadata)
                qDebug() << "TagLib" << "title" << title << "artist" << artist << "album" << album << "comment" << comment << "genre" << genre << "year" << year << "trackNumber" << trackNumber;
        }

        TagLib::AudioProperties *properties = f.audioProperties();
        if (properties) {
            int lengthSeconds = properties->length();
            int bitrate = properties->bitrate();
            int sampleRate = properties->sampleRate();
            int channels = properties->channels();

            if (s_bDebugMetadata)
                qDebug() << "TagLib" << "length" << lengthSeconds << "bitrate" << bitrate << "sampleRate" << sampleRate << "channels" << channels;

            setDuration(lengthSeconds);
            setBitrate(bitrate);
            setSampleRate(sampleRate);
            setChannels(channels);
        }

        // If we didn't get any audio properties, this was a failure.
        return (properties!=NULL);
    }
    return false;
}
Ejemplo n.º 8
0
TagLib::File *Meta::Tag::FileTypeResolver::createFile(TagLib::FileName fileName,
        bool readProperties,
        TagLib::AudioProperties::ReadStyle propertiesStyle) const
{
    TagLib::File* result = 0;

    QString fn = QFile::decodeName(fileName);
    QString suffix = QFileInfo(fn).suffix();

    #ifdef ENABLE_KDE_SUPPORT
    KMimeType::Ptr mimetype = KMimeType::findByPath(fn);

    // -- check by mime type
    if (mimetype->is(QLatin1String("audio/mpeg")) || mimetype->is(QLatin1String("audio/x-mpegurl"))
            || mimetype->is(QLatin1String("audio/mpeg"))) {
        result = new TagLib::MPEG::File(fileName, readProperties, propertiesStyle);
    } else if (mimetype->is(QLatin1String("audio/mp4")) || mimetype->is(QLatin1String("video/mp4"))) {
        result = new TagLib::MP4::File(fileName, readProperties, propertiesStyle);
    } else if (mimetype->is(QLatin1String("audio/x-ms-wma")) /*|| mimetype->is(QLatin1String("video/x-ms-asf"))
            || mimetype->is(QLatin1String("video/x-msvideo")) || mimetype->is(QLatin1String("video/x-ms-wmv"))*/) {
        result = new TagLib::ASF::File(fileName, readProperties, propertiesStyle);
    }
    #ifdef TAGLIB_EXTRAS_FOUND
    else if (mimetype->is(QLatin1String("audio/vnd.rn-realaudio")) || mimetype->is(QLatin1String("audio/x-pn-realaudioplugin"))
            /*|| mimetype->is(QLatin1String("audio/vnd.rn-realvideo"))*/) {
        result = new TagLibExtras::RealMedia::File(fileName, readProperties, propertiesStyle);
    }
    #endif
    #ifdef TAGLIB_OPUS_FOUND
    else if (mimetype->is(QLatin1String("audio/opus")) || mimetype->is(QLatin1String("audio/x-opus+ogg"))) {
        result = new TagLib::Ogg::Opus::File(fileName, readProperties, propertiesStyle);
    }
    #endif
    else if (mimetype->is(QLatin1String("audio/x-vorbis+ogg"))) {
        result = new TagLib::Ogg::Vorbis::File(fileName, readProperties, propertiesStyle);
    } else if (mimetype->is(QLatin1String("audio/x-flac+ogg"))) {
        result = new TagLib::Ogg::FLAC::File(fileName, readProperties, propertiesStyle);
    } else if (mimetype->is(QLatin1String("audio/x-aiff"))) {
        result = new TagLib::RIFF::AIFF::File(fileName, readProperties, propertiesStyle);
    } else if (mimetype->is(QLatin1String("audio/x-flac"))) {
        result = new TagLib::FLAC::File(fileName, readProperties, propertiesStyle);
    } else if (mimetype->is(QLatin1String("audio/x-musepack"))) {
        result = new TagLib::MPC::File(fileName, readProperties, propertiesStyle);
    } else if (mimetype->is(QLatin1String("audio/x-wav"))) {
        result = new TagLib::RIFF::WAV::File(fileName, readProperties, propertiesStyle);
    } else if (mimetype->is(QLatin1String("audio/x-wavpack"))) {
        result = new TagLib::WavPack::File(fileName, readProperties, propertiesStyle);
    } else if (mimetype->is(QLatin1String("audio/x-tta"))) {
        result = new TagLib::TrueAudio::File(fileName, readProperties, propertiesStyle);
    } else if (mimetype->is(QLatin1String("audio/x-speex")) || mimetype->is(QLatin1String("audio/x-speex+ogg"))) {
        result = new TagLib::TrueAudio::File(fileName, readProperties, propertiesStyle);
    } else if (mimetype->is(QLatin1String("audio/x-speex")) || mimetype->is(QLatin1String("audio/x-speex+ogg"))) {
        result = new TagLib::TrueAudio::File(fileName, readProperties, propertiesStyle);
    } else if (mimetype->is(QLatin1String("audio/x-ape"))) {
        result = new TagLib::APE::File(fileName, readProperties, propertiesStyle);
    }

    // -- check by extension
    #else // ENABLE_KDE_SUPPORT
    if (suffix == QLatin1String("mp3")) {
        result = new TagLib::MPEG::File(fileName, readProperties, propertiesStyle);
    } else if (suffix == QLatin1String("flac")) {
        result = new TagLib::FLAC::File(fileName, readProperties, propertiesStyle);
    } else if (suffix == QLatin1String("ogg")) {
        result = new TagLib::Ogg::Vorbis::File(fileName, readProperties, propertiesStyle);
        if (!result->isValid()) {
            delete result;
            result = new TagLib::Ogg::FLAC::File(fileName, readProperties, propertiesStyle);
        }
        if (!result->isValid()) {
            delete result;
            result = new TagLib::TrueAudio::File(fileName, readProperties, propertiesStyle);
        }
        #ifdef TAGLIB_OPUS_FOUND
        if (!result->isValid()) {
            delete result;
            result = new TagLib::Ogg::Opus::File(fileName, readProperties, propertiesStyle);
        }
        #endif
    }
    #endif //
    else if (suffix == QLatin1String("m4a") || suffix == QLatin1String("m4b")
        || suffix == QLatin1String("m4p") || suffix == QLatin1String("mp4")
        /*|| suffix == QLatin1String("m4v") || suffix == QLatin1String("mp4v") */) {
        result = new TagLib::MP4::File(fileName, readProperties, propertiesStyle);
    } else if (suffix == QLatin1String("wav")) {
        result = new TagLib::RIFF::WAV::File(fileName, readProperties, propertiesStyle);
    } else if (suffix == QLatin1String("wma") /*|| suffix == QLatin1String("asf")*/) {
        result = new TagLib::ASF::File(fileName, readProperties, propertiesStyle);
    } else if (suffix == QLatin1String("wvp") || suffix == QLatin1String("wv")) {
        result = new TagLib::WavPack::File(fileName, readProperties, propertiesStyle);
    } else if (suffix == QLatin1String("ape")) {
        result = new TagLib::APE::File(fileName, readProperties, propertiesStyle);
    } else if (suffix == QLatin1String("spx")) {
        result = new TagLib::TrueAudio::File(fileName, readProperties, propertiesStyle);
    } else if (suffix == QLatin1String("tta")) {
        result = new TagLib::TrueAudio::File(fileName, readProperties, propertiesStyle);
    } else if (suffix == QLatin1String("aiff") || suffix == QLatin1String("aif") || suffix == QLatin1String("aifc")) {
        result = new TagLib::RIFF::AIFF::File(fileName, readProperties, propertiesStyle);
    } else if (suffix == QLatin1String("mpc") || suffix == QLatin1String("mpp") || suffix == QLatin1String("mp+")) {
        result = new TagLib::MPC::File(fileName, readProperties, propertiesStyle);
    }
    #ifdef TAGLIB_OPUS_FOUND
    else if (suffix == QLatin1String("opus")) {
        result = new TagLib::Ogg::Opus::File(fileName, readProperties, propertiesStyle);
    }
    #endif

    if (result && !result->isValid()) {
        delete result;
        result = 0;
    }

    return result;
}
Ejemplo n.º 9
0
bool CTagLoaderTagLib::Load(const string& strFileName, CMusicInfoTag& tag, EmbeddedArt *art /* = NULL */)
{  
  CStdString strExtension;
  URIUtils::GetExtension(strFileName, strExtension);
  strExtension.ToLower();
  strExtension.TrimLeft('.');

  if (strExtension.IsEmpty())
    return false;

  TagLibVFSStream*           stream = new TagLibVFSStream(strFileName, true);
  if (!stream)
  {
    CLog::Log(LOGERROR, "could not create TagLib VFS stream for: %s", strFileName.c_str());
    return false;
  }
  
  TagLib::File*              file = NULL;
  TagLib::APE::File*         apeFile = NULL;
  TagLib::ASF::File*         asfFile = NULL;
  TagLib::FLAC::File*        flacFile = NULL;
  TagLib::IT::File*          itFile = NULL;
  TagLib::Mod::File*         modFile = NULL;
  TagLib::MP4::File*         mp4File = NULL;
  TagLib::MPC::File*         mpcFile = NULL;
  TagLib::MPEG::File*        mpegFile = NULL;
  TagLib::Ogg::Vorbis::File* oggVorbisFile = NULL;
  TagLib::Ogg::FLAC::File*   oggFlacFile = NULL;
  TagLib::S3M::File*         s3mFile = NULL;
  TagLib::TrueAudio::File*   ttaFile = NULL;
  TagLib::WavPack::File*     wvFile = NULL;
  TagLib::XM::File*          xmFile = NULL;

  if (strExtension == "ape")
    file = apeFile = new APE::File(stream);
  else if (strExtension == "asf" || strExtension == "wmv" || strExtension == "wma")
    file = asfFile = new ASF::File(stream);
  else if (strExtension == "flac")
    file = flacFile = new FLAC::File(stream, ID3v2::FrameFactory::instance());
  else if (strExtension == "it")
    file = itFile = new IT::File(stream);
  else if (strExtension == "mod" || strExtension == "module" || strExtension == "nst" || strExtension == "wow")
    file = modFile = new Mod::File(stream);
  else if (strExtension == "mp4" || strExtension == "m4a" || 
           strExtension == "m4r" || strExtension == "m4b" || 
           strExtension == "m4p" || strExtension == "3g2")
    file = mp4File = new MP4::File(stream);
  else if (strExtension == "mpc")
    file = mpcFile = new MPC::File(stream);
  else if (strExtension == "mp3" || strExtension == "aac")
    file = mpegFile = new MPEG::File(stream, ID3v2::FrameFactory::instance());
  else if (strExtension == "s3m")
    file = s3mFile = new S3M::File(stream);
  else if (strExtension == "tta")
    file = ttaFile = new TrueAudio::File(stream, ID3v2::FrameFactory::instance());
  else if (strExtension == "wv")
    file = wvFile = new WavPack::File(stream);
  else if (strExtension == "xm")
    file = xmFile = new XM::File(stream);
  else if (strExtension == "ogg")
    file = oggVorbisFile = new Ogg::Vorbis::File(stream);
  else if (strExtension == "oga") // Leave this madness until last - oga container can have Vorbis or FLAC
  {
    file = oggFlacFile = new Ogg::FLAC::File(stream);
    if (!file || !file->isValid())
    {
      delete file;
      file = oggVorbisFile = new Ogg::Vorbis::File(stream);
    }
  }

  if (!file || !file->isOpen())
  {
    delete file;
    delete stream;
    CLog::Log(LOGDEBUG, "file could not be opened for tag reading");
    return false;
  }

  APE::Tag *ape = NULL;
  ASF::Tag *asf = NULL;
  MP4::Tag *mp4 = NULL;
  ID3v2::Tag *id3v2 = NULL;
  Ogg::XiphComment *xiph = NULL;
  Tag *generic = NULL;

  if (apeFile)
    ape = apeFile->APETag(false);
  else if (asfFile)
    asf = asfFile->tag();
  else if (flacFile)
  {
    xiph = flacFile->xiphComment(false);
    id3v2 = flacFile->ID3v2Tag(false);
  }
  else if (mp4File)
    mp4 = mp4File->tag();
  else if (mpegFile)
  {
    id3v2 = mpegFile->ID3v2Tag(false);
    ape = mpegFile->APETag(false);
  }
  else if (oggFlacFile)
    xiph = dynamic_cast<Ogg::XiphComment *>(oggFlacFile->tag());
  else if (oggVorbisFile)
    xiph = dynamic_cast<Ogg::XiphComment *>(oggVorbisFile->tag());
  else if (ttaFile)
    id3v2 = ttaFile->ID3v2Tag(false);
  else if (wvFile)
    ape = wvFile->APETag(false);
  else    // This is a catch all to get generic information for other files types (s3m, xm, it, mod, etc)
    generic = file->tag();

  if (file->audioProperties())
    tag.SetDuration(file->audioProperties()->length());

  if (ape && !g_advancedSettings.m_prioritiseAPEv2tags)
    ParseAPETag(ape, art, tag);

  if (asf)
    ParseASF(asf, art, tag);
  else if (id3v2)
    ParseID3v2Tag(id3v2, art, tag);
  else if (generic)
    ParseGenericTag(generic, art, tag);
  else if (mp4)
    ParseMP4Tag(mp4, art, tag);
  else if (xiph)
    ParseXiphComment(xiph, art, tag);

  // art for flac files is outside the tag
  if (flacFile)
    SetFlacArt(flacFile, art, tag);

  // Add APE tags over the top of ID3 tags if we want to prioritize them
  if (ape && g_advancedSettings.m_prioritiseAPEv2tags)
    ParseAPETag(ape, art, tag);

  if (!tag.GetTitle().IsEmpty() || !tag.GetArtist().empty() || !tag.GetAlbum().IsEmpty())
    tag.SetLoaded();
  tag.SetURL(strFileName);

  delete file;
  delete stream;
  
  return true;
}
Ejemplo n.º 10
0
Tags *TagUtils::load(const QString &filename) {
#ifdef Q_OS_WIN
    const wchar_t * encodedName = reinterpret_cast<const wchar_t*>(filename.utf16());
    TagLib::FileStream readOnlyStream(encodedName, true);
#else
    TagLib::FileStream readOnlyStream((TagLib::FileName)filename.toUtf8(), true);
#endif

    TagLib::FileRef fileref(&readOnlyStream);
    if (fileref.isNull()) {
        qDebug() << "Taglib cannot parse" << filename;
        return nullptr;
    }

    Tags *tags = new Tags();
    tags->setFilename(filename);

    TagLib::Tag *tag = fileref.tag();
    if (tag) {
        tags->setTitle(TagUtils::qString(tag->title()));
        tags->setArtistString(TagUtils::qString(tag->artist()));
        tags->setAlbumString(TagUtils::qString(tag->album()));
        tags->setGenre(TagUtils::qString(tag->genre()));
        tags->setTrackNumber(tag->track());
        tags->setYear(tag->year());
        tags->setComment(TagUtils::qString(tag->comment()));
        TagLib::AudioProperties *audioProperties = fileref.audioProperties();
        if (audioProperties)
            tags->setDuration(audioProperties->length());
    }

    /*
    TagLib::PropertyMap map = tag->properties();
    for (TagLib::PropertyMap::ConstIterator i = map.begin(); i != map.end(); ++i) {
        for (TagLib::StringList::ConstIterator j = i->second.begin(); j != i->second.end(); ++j) {
            const QString tagName = TagLibUtils::toQString(i->first);
            qDebug() << "PropertyMap" << tagName << TagLibUtils::toQString(*j);
            if (tagName == QLatin1String("ALBUMARTIST"))
                tags->setAlbumArtist(TagLibUtils::toQString(*j));
            else if (tagName == QLatin1String("DISCNUMBER"))
                tags->setDiskNumber(TagLibUtils::toQString(*j).toInt());
            // else if (tagName == QLatin1String("COMPOSER"))
            // tags->setComposer(toQString(*j));
            else if (tagName == QLatin1String("LYRICS"))
                tags->setLyrics(TagLibUtils::toQString(*j));
            //else if (tagName == QLatin1String("BPM"))
            //    tags->bpm = toQString(*j).toInt();
            // else qDebug() << "Unused tag" << tagName << toQString(*j);
        }
    }
    */

    // Handle file types where TagLibf:::File::tag() returns a "TagUnion"
    TagLib::File *file = fileref.file();

    if (TagLib::MPEG::File *f = dynamic_cast<TagLib::MPEG::File*>(file)) {
        if (TagLib::ID3v2::Tag *t = f->ID3v2Tag()) Id3Utils::load(t, tags);

    } else if (TagLib::TrueAudio::File *f = dynamic_cast<TagLib::TrueAudio::File*>(file)) {
        if (TagLib::ID3v2::Tag *t = f->ID3v2Tag()) Id3Utils::load(t, tags);

    } else if (TagLib::FLAC::File *f = dynamic_cast<TagLib::FLAC::File*>(file)) {
        if (TagLib::Ogg::XiphComment *t = f->xiphComment()) VorbisUtils::load(t, tags);
        else if (TagLib::ID3v2::Tag *t = f->ID3v2Tag()) Id3Utils::load(t, tags);

    } else if (TagLib::APE::File *f = dynamic_cast<TagLib::APE::File*>(file)) {
        if (TagLib::APE::Tag *t = f->APETag()) ApeUtils::load(t, tags);

    } else if (TagLib::MPC::File *f = dynamic_cast<TagLib::MPC::File*>(file)) {
        if (TagLib::APE::Tag *t = f->APETag()) ApeUtils::load(t, tags);

    } else if (TagLib::WavPack::File *f = dynamic_cast<TagLib::WavPack::File*>(file)) {
        if (TagLib::APE::Tag *t = f->APETag()) ApeUtils::load(t, tags);

    } else {

        // Fallback to casting tag() for any other file type
        TagLib::Tag *tag = file->tag();

        if (TagLib::ID3v2::Tag *t = dynamic_cast<TagLib::ID3v2::Tag*>(tag))
            Id3Utils::load(t, tags);

        else if (TagLib::Ogg::XiphComment *t = dynamic_cast<TagLib::Ogg::XiphComment*>(tag))
            VorbisUtils::load(t, tags);

        else if (TagLib::APE::Tag *t = dynamic_cast<TagLib::APE::Tag*>(tag))
            ApeUtils::load(t, tags);

        else if (TagLib::MP4::Tag *t = dynamic_cast<TagLib::MP4::Tag*>(tag))
            Mp4Utils::load(t, tags);

        else if (TagLib::ASF::Tag *t = dynamic_cast<TagLib::ASF::Tag*>(tag))
            AsfUtils::load(t, tags);
    }

    return tags;
}
Ejemplo n.º 11
0
 uint read(TagLib::File &file, uint limit)
 {
   uint count = std::min(m_size, limit);
   file.seek(count, TagLib::File::Current);
   return count;
 }
Ejemplo n.º 12
0
 uint read(TagLib::File &file, uint limit)
 {
   ByteVector data = file.readBlock(std::min(4U,limit));
   value = data.toUInt(bigEndian);
   return data.size();
 }
Ejemplo n.º 13
0
//Adds dir & its contents to the library
void libraryDialog::addDir2Lib(QDir dir)
{
	dir.setFilter(QDir::Files | QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
	QDirIterator di(dir, QDirIterator::Subdirectories);	

	while(di.hasNext())
	{
		di.next();		
		QString fpath = di.filePath();
		QFileInfo f = di.fileInfo();
		if(isAudioFile(f))//Add this song to the database
		{
			wchar_t wname[250]; //TODO: Dynamic. Need to figure out wchar length from QStr length
			wname[fpath.toWCharArray(wname)] = 0;
			TagLib::FileName fname(wname);
			//We'll store tag information in these:
			QMap<QString, QString> stmap;
			QMap<QString, int> itmap;
			
			TagLib::File* file = NULL;
			//MP3 Means we can check for additional info in ID3v2 tags
			if(f.suffix() == "mp3")
			{				
				TagLib::MPEG::File* fr = new TagLib::MPEG::File(fname, true, TagLib::AudioProperties::ReadStyle::Fast);				
				if(fr->ID3v2Tag())
				{					
					//Somehow this means album artist / band. http://www.id3.org/id3v2.4.0-frames
					TagLib::ID3v2::FrameList l = fr->ID3v2Tag()->frameList("TPE2");
					if(!l.isEmpty())
						stmap["albumartist"] = l.front()->toString().toCString();
				}
				file = dynamic_cast<TagLib::File*>(fr);
			}
			if(file == NULL)
			{
				qDebug() << "ERR: " + fpath;
				continue; //TODO: Error out here
			}
			//Try to get audio properties
			TagLib::AudioProperties* ap = file->audioProperties();			
			
			TagLib::Tag* genTag = file->tag();			
			stmap["name"] = genTag->title().toCString();
			stmap["genre"] = genTag->genre().toCString();
			itmap["year"] = genTag->year();
			itmap["tracknum"] = genTag->track();
			stmap["album"] = genTag->album().toCString();						
			stmap["artist"] = genTag->artist().toCString();			
			if(ap != NULL)
				itmap["length"] = ap->length();
			stmap["path"] = fpath;	
			//Add collected info to db
			DBItem s;
			s.strVals = stmap;
			s.intVals = itmap;

			myparent->dbi->addSong(s);
			delete file;
		}
		else if(f.isDir())
			ui.curDirLbl->setText(fpath);
		//if(top) //If we're the top level of recursion update prog bar
		//	ui.progressBar->setValue(di./siz * 100);		
		qApp->processEvents();
	}
}
Ejemplo n.º 14
0
bool KFlacPlugin::readInfo( KFileMetaInfo& info, uint what )
{
    if ( info.path().isEmpty() ) // remote file
        return false;

    bool readComment = false;
    bool readTech = false;
    if (what & (KFileMetaInfo::Fastest |
                KFileMetaInfo::DontCare |
                KFileMetaInfo::ContentInfo)) readComment = true;

    if (what & (KFileMetaInfo::Fastest |
                KFileMetaInfo::DontCare |
                KFileMetaInfo::TechnicalInfo)) readTech = true;

    TagLib::File *file = 0;

    if (info.mimeType() == "audio/x-flac")
        file = new TagLib::FLAC::File(QFile::encodeName(info.path()).data(), readTech);
#ifdef TAGLIB_1_2
    else
        file = new TagLib::Ogg::FLAC::File(QFile::encodeName(info.path()).data(), readTech);
#endif

    if (!file || !file->isValid())
    {
        kdDebug(7034) << "Couldn't open " << file->name() << endl;
        delete file;
        return false;
    }

    if(readComment && file->tag())
    {
        KFileMetaInfoGroup commentgroup = appendGroup(info, "Comment");

        QString date  = file->tag()->year() > 0 ? QString::number(file->tag()->year()) : QString::null;
        QString track = file->tag()->track() > 0 ? QString::number(file->tag()->track()) : QString::null;

        appendItem(commentgroup, "Title",       TStringToQString(file->tag()->title()).stripWhiteSpace());
        appendItem(commentgroup, "Artist",      TStringToQString(file->tag()->artist()).stripWhiteSpace());
        appendItem(commentgroup, "Album",       TStringToQString(file->tag()->album()).stripWhiteSpace());
        appendItem(commentgroup, "Date",        date);
        appendItem(commentgroup, "Comment",     TStringToQString(file->tag()->comment()).stripWhiteSpace());
        appendItem(commentgroup, "Tracknumber", track);
        appendItem(commentgroup, "Genre",       TStringToQString(file->tag()->genre()).stripWhiteSpace());
    }

    if (readTech && file->audioProperties())
    {
        KFileMetaInfoGroup techgroup = appendGroup(info, "Technical");
        TagLib::FLAC::Properties *properties =
                   (TagLib::FLAC::Properties*)(file->audioProperties());

        appendItem(techgroup, "Bitrate",      properties->bitrate());
        appendItem(techgroup, "Sample Rate",  properties->sampleRate());
        appendItem(techgroup, "Sample Width", properties->sampleWidth());
        appendItem(techgroup, "Channels",     properties->channels());
        appendItem(techgroup, "Length",       properties->length());
    }

    delete file;
    return true;

}
Ejemplo n.º 15
0
bool AudioTagger::save () {
    TagLib::File* file = NULL;

    if (m_file.endsWith(".mp3", Qt::CaseInsensitive)) {
        file =  new TagLib::MPEG::File(m_file.toUtf8().constData());
        //process special ID3 fields, APEv2 fiels, etc

        //If the mp3 has no ID3v2 tag, we create a new one and add the TBPM and TKEY frame
        addID3v2Tag( ((TagLib::MPEG::File*) file)->ID3v2Tag(true)  );
        //If the mp3 has an APE tag, we update
        addAPETag( ((TagLib::MPEG::File*) file)->APETag(false)  );

    }
    if (m_file.endsWith(".m4a", Qt::CaseInsensitive)) {
        file =  new TagLib::MP4::File(m_file.toUtf8().constData());
        //process special ID3 fields, APEv2 fiels, etc
        processMP4Tag(((TagLib::MP4::File*) file)->tag());

    }
    if (m_file.endsWith(".ogg", Qt::CaseInsensitive)) {
        file =  new TagLib::Ogg::Vorbis::File(m_file.toUtf8().constData());
        //process special ID3 fields, APEv2 fiels, etc
        addXiphComment( ((TagLib::Ogg::Vorbis::File*) file)->tag()   );

    }
    if (m_file.endsWith(".wav", Qt::CaseInsensitive)) {
        file =  new TagLib::RIFF::WAV::File(m_file.toUtf8().constData());
        //If the flac has no ID3v2 tag, we create a new one and add the TBPM and TKEY frame
        addID3v2Tag( ((TagLib::RIFF::WAV::File*) file)->tag()  );

    }
    if (m_file.endsWith(".flac", Qt::CaseInsensitive)) {
        file =  new TagLib::FLAC::File(m_file.toUtf8().constData());

        //If the flac has no ID3v2 tag, we create a new one and add the TBPM and TKEY frame
        addID3v2Tag( ((TagLib::FLAC::File*) file)->ID3v2Tag(true)  );
        //If the flac has no APE tag, we create a new one and add the TBPM and TKEY frame
        addXiphComment( ((TagLib::FLAC::File*) file)->xiphComment (true)   );

    }
    if (m_file.endsWith(".aif", Qt::CaseInsensitive) || m_file.endsWith(".aiff", Qt::CaseInsensitive)) {
        file =  new TagLib::RIFF::AIFF::File(m_file.toUtf8().constData());
        //If the flac has no ID3v2 tag, we create a new one and add the TBPM and TKEY frame
        addID3v2Tag( ((TagLib::RIFF::AIFF::File*) file)->tag()  );

    }

    //process standard tags
    if (file) {
        TagLib::Tag *tag = file->tag();
        if (tag) {
            tag->setArtist(m_artist.toStdString());
            tag->setTitle(m_title.toStdString());
            tag->setAlbum(m_album.toStdString());
            tag->setGenre(m_genre.toStdString());
            tag->setComment(m_comment.toStdString());
            uint year =  m_year.toUInt();
            if (year >  0)
                tag->setYear(year);
            uint tracknumber = m_tracknumber.toUInt();
            if (tracknumber > 0)
                tag->setTrack(tracknumber);

        }
        //write audio tags to file
        int success = file->save();
        if (success) {
            qDebug() << "Successfully updated metadata of track " << m_file;
        } else {
             qDebug() << "Could not update metadata of track " << m_file;
        }
        //delete file and return
        delete file;
        return success;
    } else {
        return false;
    }
}
Ejemplo n.º 16
0
bool KMpcPlugin::readInfo( KFileMetaInfo& info, uint what )
{

    bool readComment = false;
    bool readTech = false;
    if (what & (KFileMetaInfo::Fastest |
                KFileMetaInfo::DontCare |
                KFileMetaInfo::ContentInfo)) readComment = true;

    if (what & (KFileMetaInfo::Fastest |
                KFileMetaInfo::DontCare |
                KFileMetaInfo::TechnicalInfo)) readTech = true;

    if ( info.path().isEmpty() ) // remote file
        return false;

    TagLib::File *file = new TagLib::MPC::File(QFile::encodeName(info.path()).data(), readTech);

    if (!file->isOpen())
    {
        kDebug(7034) << "Couldn't open " << file->name();
        delete file;
        return false;
    }

    if(readComment)
    {
        KFileMetaInfoGroup commentgroup = appendGroup(info, "Comment");

        QString date  = file->tag()->year() > 0 ? QString::number(file->tag()->year()) : QString();
        QString track = file->tag()->track() > 0 ? QString::number(file->tag()->track()) : QString();

        appendItem(commentgroup, "Title",       TStringToQString(file->tag()->title()).trimmed());
        appendItem(commentgroup, "Artist",      TStringToQString(file->tag()->artist()).trimmed());
        appendItem(commentgroup, "Album",       TStringToQString(file->tag()->album()).trimmed());
        appendItem(commentgroup, "Date",        date);
        appendItem(commentgroup, "Comment",     TStringToQString(file->tag()->comment()).trimmed());
        appendItem(commentgroup, "Tracknumber", track);
        appendItem(commentgroup, "Genre",       TStringToQString(file->tag()->genre()).trimmed());
    }

    if (readTech)
    {
        KFileMetaInfoGroup techgroup = appendGroup(info, "Technical");
        TagLib::MPC::Properties *properties =
                   (TagLib::MPC::Properties*)(file->audioProperties());

        appendItem(techgroup, "Bitrate",      properties->bitrate());
        appendItem(techgroup, "Sample Rate",  properties->sampleRate());
        appendItem(techgroup, "Channels",     properties->channels());
        appendItem(techgroup, "Length",       properties->length());
        appendItem(techgroup, "Version",      properties->mpcVersion());
    }

    delete file;
    return true;

}