read/parse file tags
import audiofiles
This commit is contained in:
@@ -1 +1,3 @@
|
|||||||
|
*.o
|
||||||
|
build/
|
||||||
data/
|
data/
|
||||||
|
|||||||
+2
-1
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Metadata.h"
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -19,3 +18,5 @@ class File {
|
|||||||
std::string fileName_;
|
std::string fileName_;
|
||||||
fs::path fp_ = musicFolder_ / fileName_;
|
fs::path fp_ = musicFolder_ / fileName_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string_view parseFiletype( std::string_view path );
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ struct Metadata {
|
|||||||
TagLib::String album;
|
TagLib::String album;
|
||||||
TagLib::String albumArtist;
|
TagLib::String albumArtist;
|
||||||
unsigned int year;
|
unsigned int year;
|
||||||
std::string artwork;
|
TagLib::VariantList artwork;
|
||||||
TagLib::String genre;
|
TagLib::String genre;
|
||||||
unsigned int trackNr;
|
unsigned int trackNr;
|
||||||
double length;
|
double length;
|
||||||
|
|||||||
+4
-1
@@ -1,8 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Metadata.h"
|
#include "Metadata.h"
|
||||||
|
#include <memory>
|
||||||
#include <taglib/tstring.h>
|
#include <taglib/tstring.h>
|
||||||
#include <taglib/fileref.h>
|
#include <taglib/fileref.h>
|
||||||
|
#include <taglib/tvariant.h>
|
||||||
|
|
||||||
|
|
||||||
class Tag {
|
class Tag {
|
||||||
@@ -10,7 +12,8 @@ class Tag {
|
|||||||
void readTag( TagLib::FileName fileName );
|
void readTag( TagLib::FileName fileName );
|
||||||
Metadata getMetadata() const;
|
Metadata getMetadata() const;
|
||||||
|
|
||||||
std::string& getFilePath() const;
|
const std::string& getFilePath() const;
|
||||||
|
const auto getArtwork() const;
|
||||||
private:
|
private:
|
||||||
Metadata metadata_;
|
Metadata metadata_;
|
||||||
std::string filePath_;
|
std::string filePath_;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "include/Tag.h"
|
#include "include/Tag.h"
|
||||||
#include "include/File.h"
|
#include "include/File.h"
|
||||||
|
//#include "include/Metadata.h"
|
||||||
|
|
||||||
//#include <filesystem>
|
//#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -9,10 +10,10 @@
|
|||||||
//namespace fs = std::filesystem;
|
//namespace fs = std::filesystem;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
File file;
|
|
||||||
Tag tag;
|
Tag tag;
|
||||||
|
File file;
|
||||||
//fs::path folderPath{ "data" };
|
//fs::path folderPath{ "data" };
|
||||||
file.importFolder( "/home/fegger/Projects/soundServe/data/" );
|
file.importFolder( "/home/fegger/Code/projects/soundServe/data/" );
|
||||||
for ( auto& fp : file.filenames_) {
|
for ( auto& fp : file.filenames_) {
|
||||||
std::cout << fp << "\n";
|
std::cout << fp << "\n";
|
||||||
}
|
}
|
||||||
@@ -29,6 +30,7 @@ int main() {
|
|||||||
<< "\nGenre: " << meta.genre
|
<< "\nGenre: " << meta.genre
|
||||||
<< "\nSamplerate: " << meta.sampleRate
|
<< "\nSamplerate: " << meta.sampleRate
|
||||||
<< "\nBitrate: " << meta.bitRate
|
<< "\nBitrate: " << meta.bitRate
|
||||||
|
<< "\nFormat: " << meta.format
|
||||||
<< "\nLength: " << meta.length;
|
<< "\nLength: " << meta.length;
|
||||||
std::cout << "\n----------------------------------------------------------------------\n";
|
std::cout << "\n----------------------------------------------------------------------\n";
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
Binary file not shown.
@@ -19,3 +19,11 @@ void File::importFile( std::string fileName ) {
|
|||||||
fs::path fp = fp_;
|
fs::path fp = fp_;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string_view parseFiletype( std::string_view path ){
|
||||||
|
|
||||||
|
size_t length = path.size();
|
||||||
|
size_t dot = path.find_last_of( ".");
|
||||||
|
|
||||||
|
return path.substr( dot + 1, length-dot );
|
||||||
|
}
|
||||||
|
|||||||
BIN
Binary file not shown.
+4
-1
@@ -1,9 +1,10 @@
|
|||||||
#include "../include/Metadata.h"
|
|
||||||
#include "../include/Tag.h"
|
#include "../include/Tag.h"
|
||||||
|
#include "../include/File.h"
|
||||||
|
|
||||||
#include <taglib/tag.h>
|
#include <taglib/tag.h>
|
||||||
#include <taglib/fileref.h>
|
#include <taglib/fileref.h>
|
||||||
|
|
||||||
|
|
||||||
void Tag::readTag( TagLib::FileName fileName ){
|
void Tag::readTag( TagLib::FileName fileName ){
|
||||||
TagLib::FileRef f( fileName );
|
TagLib::FileRef f( fileName );
|
||||||
if ( !f.isNull() ) {
|
if ( !f.isNull() ) {
|
||||||
@@ -16,11 +17,13 @@ void Tag::readTag( TagLib::FileName fileName ){
|
|||||||
metadata_.sampleRate = f.audioProperties()->sampleRate();
|
metadata_.sampleRate = f.audioProperties()->sampleRate();
|
||||||
metadata_.bitRate = f.audioProperties()->bitrate();
|
metadata_.bitRate = f.audioProperties()->bitrate();
|
||||||
metadata_.length = f.audioProperties()->lengthInSeconds();
|
metadata_.length = f.audioProperties()->lengthInSeconds();
|
||||||
|
metadata_.format = parseFiletype( fileName );
|
||||||
// TODO
|
// TODO
|
||||||
// file format
|
// file format
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Metadata Tag::getMetadata() const {
|
Metadata Tag::getMetadata() const {
|
||||||
return metadata_;
|
return metadata_;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user