libtaginfo / tests / lyrics_mp3 / main.cc

#include "taginfo.h"
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

using namespace TagInfo;
//using namespace std;


int main( void ) {
    Info * info;
    std::string val   = TESTDIR "samples/sample_v2_only.mp3";
    
    //std::cout << std::endl << "val: " << val << std::endl;
    std::string target = "/tmp/out_01.mp3";
    
    std::ifstream  src(val.c_str());
    std::ofstream  dst(target.c_str());
    dst << src.rdbuf();
    
    char* data;
    int data_length;
    
    struct stat filestatus;
    
    
    std::string lyrics = "these are lyrics öäüß\n ldskjfslkd\n öäüß";
    
    info = Info::create_tag_info(target);
    if(info) {
        if(!info->set_lyrics(lyrics.c_str())) {
            delete info;
            return EXIT_FAILURE;
        }
        info->write();
    }
    delete info;
    info = NULL;
    
    info = Info::create_tag_info(target);
    char* read;
    if(info) {
        if(info->read()) {
            const char* res = info->get_lyrics().toCString(false);
            if(strcmp(lyrics.c_str(), res) != 0) {
                delete info;
                if(remove(target.c_str()) != 0 ) {
                    return EXIT_FAILURE;
                }
            }
            if(remove(target.c_str()) != 0 )
                return EXIT_FAILURE;
            return EXIT_SUCCESS;
        }
        delete info;
        if(remove(target.c_str()) != 0 )
            return EXIT_FAILURE;
        return EXIT_FAILURE;
    }
    else {
        delete info;
        if(remove(target.c_str()) != 0 )
            return EXIT_FAILURE;
        return EXIT_FAILURE;
    }
    return EXIT_FAILURE;
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.