cstring returning invalid encoding? mp3's

Caleb Cushing xenoterracide at gmail.com
Mon Sep 21 09:07:09 CEST 2009


incomplete program... basically this functions job is to scan the
filesystem and build a database of tags...


// std
#include <iostream>
#include <string>

// boost
#include <boost/filesystem.hpp>

// libpqxx
#include <pqxx/pqxx>

// TagLib
#include <fileref.h>
#include <tag.h>
#include <tstring.h>

using namespace std;
using namespace boost::filesystem;
using namespace pqxx;

int scanner(const path &cpath)
{
        if ( !exists(cpath)) {
                cerr << cpath.filename() << " does not exists.\n";
                return 1;
        }
        if ( !is_directory(cpath) ) {
                cerr << cpath.filename() << " is not a directory.\n";
                return 2;
        }
        directory_iterator iter(cpath), iter_end;

        connection conn("user=xenoterracide dbname=xenoterracide");
        work tran(conn);
        for (; iter != iter_end; ++iter) {
                if ( is_directory(*iter)) {
                        scanner(*iter);
                }
                if ( is_regular_file(*iter)) {
                        const char *tpath = iter->path().string().c_str();
                        TagLib::FileRef tfile(tpath);

                        const char *ttitle = tfile.tag()->title().toCString();

                        cout
                                << iter->path() << "\n"
                                << ttitle << endl;
                        stringstream sql;
                        sql << "INSERT INTO korama.tracks ( file_path,
title ) VALUES ('"
                                << tran.esc(iter->path().string())
                                << "','"
                                << tran.esc(ttitle)
                                << "');";
                        tran.exec(sql.str());
                }
        }
        tran.commit();
        return 0;
}

This all seems to working ok with the flac's it's scanning... however
when it hit's mp3's

/home/music/R/Rush/The_Spirit_of_Radio_-_Greatest_Hits_1974-1987/03-2112_Overture___The_Temples_of_Syrinx-Rush-The_Spirit_of_Radio_-_Greatest_Hits_1974-1987.flac
2112 Overture / The Temples of Syrinx
/home/music/R/Rihanna/Music_of_the_Sun/12-Now_I_Know-Rihanna-Music_of_the_Sun.mp3
0'
/home/music/R/Rihanna/Music_of_the_Sun/05-That_La,_La,_La-Rihanna-Music_of_the_Sun.mp3
�
terminate called after throwing an instance of 'pqxx::data_exception'
  what():  ERROR:  invalid byte sequence for encoding "UTF8": 0x90
HINT:  This error can also happen if the byte sequence does not match
the encoding expected by the server, which is controlled by
"client_encoding"

it seems to be changing what it finds on those mp3's with each run...
am I doing something wrong?
-- 
Caleb Cushing

http://xenoterracide.blogspot.com


More information about the taglib-devel mailing list