diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2012-08-22 06:55:46 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2012-08-22 06:55:46 +0200 |
commit | 11d02cffc6bdd6bf3ae7fc13b6109fe48cadd7e3 (patch) | |
tree | 7f8480eeb8fce58e9a01dd0790f50371cc203324 | |
parent | Transliterator optimizations. (diff) | |
download | music-file-organizer-11d02cffc6bdd6bf3ae7fc13b6109fe48cadd7e3.tar.xz music-file-organizer-11d02cffc6bdd6bf3ae7fc13b6109fe48cadd7e3.zip |
Add library display tool.
-rw-r--r-- | AudioFile.cpp | 13 | ||||
-rw-r--r-- | AudioFile.h | 2 | ||||
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | displaylibrary.cpp | 63 |
4 files changed, 81 insertions, 2 deletions
diff --git a/AudioFile.cpp b/AudioFile.cpp index 1e5e6fb..bbe1526 100644 --- a/AudioFile.cpp +++ b/AudioFile.cpp @@ -166,3 +166,16 @@ AudioFile::AudioFile(const std::string &filename) : m_isValid = true; } +bool AudioFile::operator<(const AudioFile &other) const +{ + int comp; + if (comp = m_artist.compare(other.m_artist)) + return comp < 0; + if (m_year != other.m_year) + return m_year < other.m_year; + if (comp = m_album.compare(other.m_album)) + return comp < 0; + if (m_track != other.m_track) + return m_track < other.m_track; + return m_title.compare(other.m_title) < 0; +} diff --git a/AudioFile.h b/AudioFile.h index f44c741..1fa4ce4 100644 --- a/AudioFile.h +++ b/AudioFile.h @@ -24,6 +24,8 @@ public: inline unsigned int channels() const { return m_channels; }; inline bool compilation() const { return m_compilation; }; + bool operator<(const AudioFile &other) const; + private: bool m_isValid; std::string m_filename; @@ -2,10 +2,11 @@ LDFLAGS += $(shell pkg-config --libs taglib icu-i18n) CXXFLAGS ?= -O3 -pipe -fomit-frame-pointer -march=native CXXFLAGS += $(shell pkg-config --cflags taglib icu-i18n) -all: readmusictags organizemusic +all: readmusictags organizemusic displaylibrary readmusictags: AudioFile.cpp AudioFile.h readmusictags.cpp organizemusic: AudioFile.cpp AudioFile.h organizemusic.cpp +displaylibrary: AudioFile.cpp AudioFile.h displaylibrary.cpp clean: - rm -vf readmusictags organizemusic + rm -vf readmusictags organizemusic displaylibrary diff --git a/displaylibrary.cpp b/displaylibrary.cpp new file mode 100644 index 0000000..7fee280 --- /dev/null +++ b/displaylibrary.cpp @@ -0,0 +1,63 @@ +#include "AudioFile.h" +#include <vector> +#include <algorithm> +#include <iostream> +#include <cstring> +#include <cstdio> +#include <dirent.h> +#include <sys/types.h> +#include <sys/stat.h> + +using namespace std; + +vector<AudioFile> songs; + +void process_path(const char *path); + +void process_file(const char *filename) +{ + AudioFile audio(filename); + if (audio.isValid()) + songs.push_back(audio); +} + +void process_directory(const char *directory) +{ + DIR *dir = opendir(directory); + if (!dir) + return; + while (struct dirent *entry = readdir(dir)) { + if (entry->d_name[0] == '.' && (entry->d_name[1] == '\0' || + (entry->d_name[1] == '.' && strlen(entry->d_name) == 2))) + continue; + + char joined[strlen(directory) + strlen(entry->d_name) + 2]; + sprintf(joined, "%s/%s", directory, entry->d_name); + process_path(joined); + } + closedir(dir); +} + +void process_path(const char *path) +{ + struct stat sbuf; + if (stat(path, &sbuf)) + return; + if (S_ISREG(sbuf.st_mode)) + process_file(path); + else if (S_ISDIR(sbuf.st_mode)) + process_directory(path); +} + +int main(int argc, char *argv[]) +{ + for (int i = 1; i < argc; ++i) + process_path(argv[i]); + + sort(songs.begin(), songs.end()); + + for (vector<AudioFile>::const_iterator i = songs.begin(); i != songs.end(); ++i) + cout << i->track() << "\t" << i->year() << "\t" << i->artist() << " - " << i->album() << " - " << i->title() << endl; + + return 0; +} |