コード例 #1
0
ファイル: cue_utils.c プロジェクト: BG2BKK/cmus
int cue_get_ntracks(const char *filename)
{
	int n;
	FILE *cue;
	Cd *cd;

	cue = fopen(filename, "r");
	if (cue == NULL)
		return -1;

	disable_stdio();
	cd = cue_parse_file(cue);
	enable_stdio();
	if (cd == NULL) {
		fclose(cue);
		return -1;
	}

	n = cd_get_ntrack(cd);

	cd_delete(cd);
	fclose(cue);

	return n;
}
コード例 #2
0
ファイル: issue10.c プロジェクト: Runcy/libcue
static char* cue_test()
{
   FILE *cue = fopen("issue10.cue", "r");
   assert(cue);
   Cd *cd = cue_parse_file(cue);
   assert(cd);
   cd_delete(cd);

   return NULL;
}
コード例 #3
0
ファイル: cuefile.cpp プロジェクト: abenea/fubar
CueFile::CueFile(QString path)
{
    f_ = fopen(path.toStdString().c_str(), "rt");
    if (!f_) {
        qDebug() << "Cannot open CUE" << path;
        throw std::runtime_error("");
    }
    cd_ = cue_parse_file(f_);
    if (!cd_) {
        qDebug() << "CUE file" << path << "is not valid";
        throw std::runtime_error("");
    }
}
struct Cd *cue_get_cd(const char *pathname)
{
    struct Cd *cd=NULL;
    // extract name of cue file
    FILE *cs_file = fopen(pathname, "rt");

    cd = cue_parse_file(cs_file);
    fclose(cs_file);

    if(cd==NULL)
        return NULL;
    else
        return cd;
}
char * cue_file_get_filename(const char *filename,unsigned tnum)
{
    struct Cd *cd;


    FILE *cue_file = fopen(filename, "rt");
    if (cue_file == NULL)
        return NULL;

    cd = cue_parse_file(cue_file);
    fclose (cue_file);

    if ( cd == NULL)
        return NULL;

    // no container directory if there is only one track
    int ntrack =cd_get_ntrack(cd);
    if (ntrack == 1)
        return NULL;

    return track_get_filename( cd_get_track( cd,tnum));
}
コード例 #6
0
ファイル: cue.c プロジェクト: RobertAudi/mpfc
/* Parse playlist and handle its contents */
plp_status_t cue_for_each_item( char *pl_name, void *ctx, plp_func_t f )
{
	/* Load cue sheet */
	FILE *fd = fopen(pl_name, "rt");
	if (!fd)
	{
		logger_error(cue_log, 0, _("cue: failed to load cue sheet %s"), pl_name);
		return PLP_STATUS_FAILED;
	}
	Cd *cd = cue_parse_file(fd, pl_name);
	if (!cd)
	{
		logger_error(cue_log, 0, _("cue: failed to load cue sheet %s"), pl_name);
		fclose(fd);
		return PLP_STATUS_FAILED;
	}
	fclose(fd);

	/* Handle tracks */
	int num_tracks = cd_get_ntrack(cd);
	plp_status_t res = PLP_STATUS_OK;
	for ( int i = 1; i <= num_tracks; ++i )
	{
		Track *track = cd_get_track(cd, i);
		char *filename = track_get_filename(track);
		if (!filename)
			continue;

		song_metadata_t metadata = SONG_METADATA_EMPTY;

		/* Set bounds */
		long start = cue_get_track_begin(track);
		long end = -1;
		if (i < num_tracks)
		{
			Track *next_track = cd_get_track(cd, i + 1);
			char *next_name = track_get_filename(next_track);
			if (next_name && !strcmp(filename, next_name))
				end = cue_get_track_begin(next_track);
		}
		metadata.m_start_time = SECONDS_TO_TIME(start) / 75;
		metadata.m_end_time = (end < 0 ? -1 : SECONDS_TO_TIME(end) / 75);

		/* Set song info */
		song_info_t *si = si_new();
		si_set_album(si, cdtext_get(PTI_TITLE, cd_get_cdtext(cd)));
		si_set_year(si, rem_get(REM_DATE, cd_get_rem(cd)));
		si_set_artist(si, cdtext_get(PTI_PERFORMER, cd_get_cdtext(cd)));
		si_set_name(si, cdtext_get(PTI_TITLE, track_get_cdtext(track)));
		si_set_genre(si, cue_get_genre(cd, track));
		si_set_comments(si, cue_get_comment(cd, track));

		char track_num_str[10];
		snprintf(track_num_str, sizeof(track_num_str), "%02d", i);
		si_set_track(si, track_num_str);
		metadata.m_song_info = si;

		plp_status_t st = f(ctx, filename, &metadata);
		if (st != PLP_STATUS_OK)
		{
			res = st;
			break;
		}
	}

	/* Free memory */
	cd_delete(cd);
	return res;
} /* End of 'cue_for_each_item' function */