Tricky implementing taglib's APIC extracting/saving feature, but I got it. Left some TODO's on where to pick up #56

This commit is contained in:
kdeng00
2019-08-11 17:51:42 -04:00
parent 023c467a9d
commit 51d40f270d
11 changed files with 183 additions and 68 deletions
+2
View File
@@ -7,11 +7,13 @@ set(CMAKE_CXX_STANDARD 17)
set(SOURCES
src/directory_manager.cpp
src/imageFile.cpp
src/metadata_retriever.cpp
)
set(HEADERS
include/models.h
include/directory_manager.h
include/imageFile.h
include/metadata_retriever.h
)
+38
View File
@@ -0,0 +1,38 @@
#include <iostream>
#include <taglib/attachedpictureframe.h>
#include <taglib/mpegfile.h>
#include <taglib/tag.h>
#include <taglib/tfile.h>
#include <taglib/tfilestream.h>
#include <taglib/fileref.h>
#include <taglib/tbytevector.h>
#include <taglib/tbytevectorstream.h>
#include <taglib/tpropertymap.h>
#include <taglib/id3v2tag.h>
class imageFile : public TagLib::File
{
public:
imageFile(const char *file);
/**
imageFile(const char *file) : TagLib::File(file)
{
}
*/
TagLib::ByteVector data();
/**
TagLib::ByteVector data()
{
return readBlock(length());
}
*/
private:
virtual TagLib::Tag *tag() const { return 0; }
virtual TagLib::AudioProperties *audioProperties() const { return 0; }
virtual bool save() { return false; }
};
+7
View File
@@ -10,3 +10,10 @@ struct Song
int Duration;
char SongPath[1024];
};
struct Cover
{
int Id;
char SongTitle[1024];
char ImagePath[1024];
};
+10
View File
@@ -0,0 +1,10 @@
#include "imageFile.h"
imageFile::imageFile(const char *file) : TagLib::File(file)
{
}
TagLib::ByteVector imageFile::data()
{
return readBlock(length());
}
+19 -2
View File
@@ -1,10 +1,12 @@
#include <iostream>
#include <string>
#include <taglib/tag.h>
#include <taglib/fileref.h>
#include <string.h>
#include <taglib/tag.h>
#include <taglib/fileref.h>
#include "metadata_retriever.h"
#include "imageFile.h"
extern "C"
{
@@ -48,5 +50,20 @@ void update_metadata(Song *sng_updated, Song *sng_old)
file.save();
}
void update_cover_art(Cover *cov, const char *stock_path, const char *song_path)
{
const std::string img_frame = "APIC";
TagLib::MPEG::File sngF(song_path);
TagLib::ID3v2::Tag *tag = sngF.ID3v2Tag();
auto frameList = tag->frameListMap()[img_frame.c_str()];
if (frameList.isEmpty()) {
// TODO: Apply stock cover art
imageFile stock_img(stock_path);
} else {
// TODO: Extract cover art from song and store it in
// cov->ImagePath
}
}
}