Add taglib to project to get extra cover data(and possibly replace libgroove for this function). Remove oggs from accepted files until I can figure out cover data for them better. Add non-persisted field for this to audiotrack object and method to add this data to it in memory.
This commit is contained in:
@@ -28,6 +28,10 @@
|
||||
#include <Wt/Dbo/Transaction>
|
||||
#include <groovefingerprinter/fingerprinter.h>
|
||||
#include <grooveplayer/player.h>
|
||||
#include <taglib/fileref.h>
|
||||
#include <taglib/mpegfile.h>
|
||||
#include <taglib/id3v2tag.h>
|
||||
#include <taglib/attachedpictureframe.h>
|
||||
|
||||
GroovePlayerMgr::GroovePlayerMgr (std::string dbFile)
|
||||
{
|
||||
@@ -412,6 +416,7 @@ bool GroovePlayerMgr::addFileToTrackDBIfTagged(Wt::Dbo::Session* session, std::f
|
||||
if(artist_tag == nullptr || album_tag == nullptr || name_tag == nullptr || genre_tag == nullptr)
|
||||
{
|
||||
//Only accept song with all metadata for DB.
|
||||
Wt::log("info") << "Audio track " << file << " did not have all required tags.";
|
||||
groove_file_close(gfile);
|
||||
return false;
|
||||
}
|
||||
@@ -451,6 +456,16 @@ bool GroovePlayerMgr::addFileToTrackDBIfTagged(Wt::Dbo::Session* session, std::f
|
||||
newTrack->trackLengthSeconds = trackLen;
|
||||
newTrack->trackFingerprint = fingerprint;
|
||||
newTrack->trackPath = file.string();
|
||||
|
||||
//Quickly see if there is cover artist
|
||||
getPictureFromTrack(newTrack);
|
||||
if(newTrack->coverArt.size() == 0)
|
||||
{
|
||||
Wt::log("info") << "Audio track " << newTrack->trackPath << " did not have cover art in the file.";
|
||||
groove_file_close(gfile);
|
||||
return false;
|
||||
}
|
||||
|
||||
session->add(newTrack);
|
||||
transaction.commit();
|
||||
groove_file_close(gfile);
|
||||
@@ -473,6 +488,32 @@ void GroovePlayerMgr::removeOrphanedTracks(Wt::Dbo::Session* session)
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
void GroovePlayerMgr::getPictureFromTrack(AudioTrack* trackToFill)
|
||||
{
|
||||
if(trackToFill->trackPath != "")
|
||||
{
|
||||
TagLib::String file = TagLib::String(trackToFill->trackPath);
|
||||
if(file.substr(file.size()-3).upper() == "MP3" && TagLib::MPEG::File(trackToFill->trackPath.c_str()).hasID3v2Tag())
|
||||
{
|
||||
TagLib::MPEG::File file(trackToFill->trackPath.c_str());
|
||||
TagLib::ID3v2::Tag* tag = file.ID3v2Tag();
|
||||
if(!tag->frameListMap()["APIC"].isEmpty() && dynamic_cast<TagLib::ID3v2::AttachedPictureFrame*>(tag->frameListMap()["APIC"].front()) != nullptr)
|
||||
{
|
||||
TagLib::ID3v2::AttachedPictureFrame* pic = dynamic_cast<TagLib::ID3v2::AttachedPictureFrame*>(tag->frameListMap()["APIC"].front());
|
||||
trackToFill->coverArt = TagLib::ByteVector(pic->picture().data(),pic->picture().size());
|
||||
trackToFill->coverMimeType = std::string(pic->mimeType().toCString(true));
|
||||
}
|
||||
}
|
||||
// else if(dynamic_cast<TagLib::Ogg::XiphComment*>(tagTrack.tag()) != nullptr && !dynamic_cast<TagLib::Ogg::XiphComment*>(tagTrack.tag())->isEmpty())
|
||||
// {
|
||||
// TagLib::Ogg::XiphComment* tag = dynamic_cast<TagLib::Ogg::XiphComment*>(tagTrack.tag());
|
||||
// if(tag->fieldListMap()["METADATA_BLOCK_PICTURE"].isEmpty())
|
||||
// {
|
||||
// tag->fieldListMap()["METADATA_BLOCK_PICTURE"];//TODO?
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GroovePlayerMgr::grooveAudioScannerLoop()
|
||||
@@ -497,7 +538,7 @@ void GroovePlayerMgr::grooveAudioScannerLoop()
|
||||
{
|
||||
extensionLowered.push_back(std::tolower(elem));
|
||||
}
|
||||
if(extensionLowered == ".mp3" || extensionLowered == ".ogg") //TODO:think about supporting more than mp3s and oggs.
|
||||
if(extensionLowered == ".mp3") //TODO:think about supporting more than mp3s.
|
||||
{
|
||||
if(addFileToTrackDBIfTagged(&sqlSession, p.path()))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user