libsaria: Add tags to the library
I add each scanned track to the library for use later.
This commit is contained in:
parent
a685023bcb
commit
7aff13f382
|
@ -24,6 +24,8 @@ class TrackTag
|
|||
void make_lenstr();
|
||||
|
||||
public:
|
||||
TrackTag();
|
||||
TrackTag(const TrackTag &);
|
||||
TrackTag(string);
|
||||
~TrackTag();
|
||||
};
|
||||
|
|
|
@ -9,3 +9,8 @@ LibraryPath::LibraryPath(string dir)
|
|||
LibraryPath::~LibraryPath()
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int LibraryPath::size()
|
||||
{
|
||||
return file_map.size();
|
||||
}
|
||||
|
|
|
@ -2,31 +2,38 @@
|
|||
#define LIBSARIA_LIBRARY_PATH_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
using namespace std;
|
||||
|
||||
#include <libsaria/path.h>
|
||||
#include <libsaria/idle.h>
|
||||
#include <libsaria/tags.h>
|
||||
|
||||
class LibraryPath
|
||||
{
|
||||
private:
|
||||
string path;
|
||||
map <ino_t, TrackTag> file_map;
|
||||
|
||||
public:
|
||||
LibraryPath(string);
|
||||
~LibraryPath();
|
||||
|
||||
void update();
|
||||
void insert_track(ino_t, TrackTag &);
|
||||
unsigned int size();
|
||||
};
|
||||
|
||||
class ScanTask : public IdleTask
|
||||
{
|
||||
private:
|
||||
string library;
|
||||
LibraryPath *library;
|
||||
string dir;
|
||||
void tag_file(string);
|
||||
bool end_dir;
|
||||
void tag_file(file);
|
||||
|
||||
public:
|
||||
ScanTask(string, string);
|
||||
ScanTask(LibraryPath *, string, bool);
|
||||
~ScanTask();
|
||||
void run_task();
|
||||
};
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
#include "library.h"
|
||||
#include "path.h"
|
||||
|
||||
static void queue_dir_scan(string lib_dir, string scan_dir)
|
||||
static void queue_dir_scan(LibraryPath *lib_path, string scan_dir, bool end)
|
||||
{
|
||||
ScanTask *task = new ScanTask(lib_dir, scan_dir);
|
||||
ScanTask *task = new ScanTask(lib_path, scan_dir, end);
|
||||
libsaria_queue_task(task);
|
||||
}
|
||||
|
||||
|
@ -26,25 +26,32 @@ void Library::update_path(string dir)
|
|||
it->second.update();
|
||||
}
|
||||
|
||||
void LibraryPath::update()
|
||||
void LibraryPath::insert_track(ino_t inode, TrackTag & tag)
|
||||
{
|
||||
queue_dir_scan(path, path);
|
||||
file_map[inode] = tag;
|
||||
}
|
||||
|
||||
ScanTask::ScanTask(string base_dir, string scan_dir)
|
||||
void LibraryPath::update()
|
||||
{
|
||||
library = base_dir;
|
||||
queue_dir_scan(this, path, true);
|
||||
}
|
||||
|
||||
ScanTask::ScanTask(LibraryPath *lib_path, string scan_dir, bool end)
|
||||
{
|
||||
library = lib_path;
|
||||
dir = scan_dir;
|
||||
end_dir = end;
|
||||
}
|
||||
|
||||
ScanTask::~ScanTask()
|
||||
{
|
||||
}
|
||||
|
||||
void ScanTask::tag_file(string filepath)
|
||||
void ScanTask::tag_file(file filepath)
|
||||
{
|
||||
try {
|
||||
TrackTag tag(filepath);
|
||||
TrackTag tag(dir + "/" + filepath.name);
|
||||
library->insert_track(filepath.d_ino, tag);
|
||||
} catch (string message) {
|
||||
println(message);
|
||||
}
|
||||
|
@ -62,8 +69,13 @@ void ScanTask::run_task()
|
|||
readdir(dir, files, dirs);
|
||||
|
||||
for (unsigned int i = 0; i < files.size(); i++)
|
||||
tag_file(dir + "/" + files[i].name);
|
||||
tag_file(files[i]);
|
||||
|
||||
for (unsigned int i = 0; i < dirs.size(); i++)
|
||||
queue_dir_scan(library, dir + "/" + dirs[i].name);
|
||||
queue_dir_scan(library, dir + "/" + dirs[i].name, i == dirs.size() - 1);
|
||||
|
||||
if (end_dir == true) {
|
||||
print("Library path size: ");
|
||||
println(library->size());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,20 +9,25 @@ using namespace TagLib;
|
|||
#include <sstream>
|
||||
using namespace std;
|
||||
|
||||
void TrackTag::make_lenstr()
|
||||
TrackTag::TrackTag()
|
||||
{
|
||||
int minutes;
|
||||
int seconds;
|
||||
stringstream stream;
|
||||
}
|
||||
|
||||
/* Convert length into mm:ss format */
|
||||
minutes = length / 60;
|
||||
seconds = length - (minutes * 60);
|
||||
stream << minutes << ":";
|
||||
if (seconds < 10)
|
||||
stream << "0";
|
||||
stream << seconds;
|
||||
lenstr = stream.str();
|
||||
TrackTag::TrackTag(const TrackTag &tag)
|
||||
{
|
||||
filepath = tag.filepath;
|
||||
title = tag.title;
|
||||
artist = tag.artist;
|
||||
album = tag.album;
|
||||
comment = tag.comment;
|
||||
genre = tag.genre;
|
||||
lenstr = tag.lenstr;
|
||||
year = tag.year;
|
||||
track = tag.track;
|
||||
length = tag.length;
|
||||
bitrate = tag.bitrate;
|
||||
sample = tag.sample;
|
||||
channels = tag.channels;
|
||||
}
|
||||
|
||||
TrackTag::TrackTag(string file)
|
||||
|
@ -58,3 +63,19 @@ TrackTag::TrackTag(string file)
|
|||
TrackTag::~TrackTag()
|
||||
{
|
||||
}
|
||||
|
||||
void TrackTag::make_lenstr()
|
||||
{
|
||||
int minutes;
|
||||
int seconds;
|
||||
stringstream stream;
|
||||
|
||||
/* Convert length into mm:ss format */
|
||||
minutes = length / 60;
|
||||
seconds = length - (minutes * 60);
|
||||
stream << minutes << ":";
|
||||
if (seconds < 10)
|
||||
stream << "0";
|
||||
stream << seconds;
|
||||
lenstr = stream.str();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue