libsaria: Tag files to add to the library
I collect the artist / album / title / ... tags and add them to a class.
This commit is contained in:
parent
65c04585a3
commit
333a3a4b04
|
@ -20,8 +20,10 @@ if ARGUMENTS.get('VERBOSE') != "1":
|
|||
env.Append(CXXCOMSTR = "CXX $TARGET")
|
||||
env.Append(LINKCOMSTR = "Linking $TARGET")
|
||||
env.Append(CPPPATH = "include")
|
||||
|
||||
env.ParseConfig('pkg-config --cflags --libs gtk+-2.0')
|
||||
env.ParseConfig('pkg-config --cflags --libs gstreamer-0.10')
|
||||
env.ParseConfig('pkg-config --cflags --libs taglib')
|
||||
|
||||
def version_h():
|
||||
f = open("include/version.h", "w")
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef LIBSARIA_TAGS_H
|
||||
#define LIBSARIA_TAGS_H
|
||||
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
class TrackTag
|
||||
{
|
||||
private:
|
||||
string filepath;
|
||||
string title;
|
||||
string artist;
|
||||
string album;
|
||||
string comment;
|
||||
string genre;
|
||||
unsigned int year;
|
||||
unsigned int track;
|
||||
|
||||
public:
|
||||
TrackTag(string);
|
||||
~TrackTag();
|
||||
void print_tag();
|
||||
};
|
||||
|
||||
#endif /* LIBSARIA_TAGS_H */
|
|
@ -23,6 +23,7 @@ class ScanTask : public IdleTask
|
|||
private:
|
||||
string library;
|
||||
string dir;
|
||||
void tag_file(string);
|
||||
|
||||
public:
|
||||
ScanTask(string, string);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <libsaria/print.h>
|
||||
#include <libsaria/idle.h>
|
||||
#include <libsaria/path.h>
|
||||
#include <libsaria/tags.h>
|
||||
|
||||
#include "library.h"
|
||||
#include "path.h"
|
||||
|
@ -40,6 +41,15 @@ ScanTask::~ScanTask()
|
|||
{
|
||||
}
|
||||
|
||||
void ScanTask::tag_file(string filepath)
|
||||
{
|
||||
try {
|
||||
TrackTag tag(filepath);
|
||||
} catch (string message) {
|
||||
println(message);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 1) Read a directory
|
||||
* 2) Create and queue a new UpdateTask for each subdirectory
|
||||
|
@ -49,12 +59,11 @@ void ScanTask::run_task()
|
|||
{
|
||||
vector<file> files;
|
||||
vector<file> dirs;
|
||||
|
||||
readdir(dir, files, dirs);
|
||||
|
||||
for (unsigned int i = 0; i < files.size(); i++)
|
||||
print("File: " + files[i].name);
|
||||
for (unsigned int i = 0; i < dirs.size(); i++) {
|
||||
println("Dir: " + dirs[i].name);
|
||||
tag_file(dir + "/" + files[i].name);
|
||||
|
||||
for (unsigned int i = 0; i < dirs.size(); i++)
|
||||
queue_dir_scan(library, dir + "/" + dirs[i].name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
#include <libsaria/tags.h>
|
||||
#include <libsaria/print.h>
|
||||
|
||||
#include <taglib/tag.h>
|
||||
#include <taglib/fileref.h>
|
||||
using namespace TagLib;
|
||||
|
||||
void TrackTag::print_tag()
|
||||
{
|
||||
println("Title:\t" + title);
|
||||
println("Artist:\t" + artist);
|
||||
println("Album:\t" + album);
|
||||
println("Comment:\t" + comment);
|
||||
println("Genre:\t" + genre);
|
||||
print("Year:\t");
|
||||
println(year);
|
||||
print("Track:\t");
|
||||
println(track);
|
||||
}
|
||||
|
||||
TrackTag::TrackTag(string file)
|
||||
{
|
||||
Tag *tag;
|
||||
FileRef ref(file.c_str());
|
||||
|
||||
if (ref.isNull())
|
||||
throw "Error tagging file: " + file;
|
||||
|
||||
tag = ref.tag();
|
||||
filepath = file;
|
||||
title = tag->title().to8Bit();
|
||||
artist = tag->artist().to8Bit();
|
||||
album = tag->album().to8Bit();
|
||||
comment = tag->comment().to8Bit();
|
||||
genre = tag->genre().to8Bit();
|
||||
year = tag->year();
|
||||
track = tag->track();
|
||||
}
|
||||
|
||||
TrackTag::~TrackTag()
|
||||
{
|
||||
}
|
Loading…
Reference in New Issue