static Tuple * get_tuple_for_vorbisfile(OggVorbis_File * vorbisfile, const gchar *filename) { Tuple *tuple; gint length; vorbis_comment *comment = NULL; tuple = tuple_new_from_filename(filename); length = vfs_is_streaming (vorbisfile->datasource) ? -1 : ov_time_total (vorbisfile, -1) * 1000; /* associate with tuple */ tuple_set_int(tuple, FIELD_LENGTH, length); if ((comment = ov_comment(vorbisfile, -1)) != NULL) { gchar *tmps; set_tuple_str(tuple, FIELD_TITLE, comment, "title"); set_tuple_str(tuple, FIELD_ARTIST, comment, "artist"); set_tuple_str(tuple, FIELD_ALBUM, comment, "album"); set_tuple_str(tuple, FIELD_GENRE, comment, "genre"); set_tuple_str(tuple, FIELD_COMMENT, comment, "comment"); if ((tmps = vorbis_comment_query(comment, "tracknumber", 0)) != NULL) tuple_set_int(tuple, FIELD_TRACK_NUMBER, atoi(tmps)); if ((tmps = vorbis_comment_query (comment, "date", 0)) != NULL) tuple_set_int (tuple, FIELD_YEAR, atoi (tmps)); } vorbis_info * info = ov_info (vorbisfile, -1); tuple_set_format (tuple, "Ogg Vorbis", info->channels, info->rate, info->bitrate_nominal / 1000); tuple_set_str(tuple, FIELD_MIMETYPE, "application/ogg"); return tuple; }
/* thread safe */ static Tuple * make_tuple (const gchar * filename, VFSFile * file) { Tuple *tuple = NULL; gint trackno; g_mutex_lock (mutex); if (trackinfo == NULL) refresh_trackinfo (TRUE); if (trackinfo == NULL) goto DONE; if (!strcmp (filename, "cdda://")) { tuple = tuple_new_from_filename (filename); gint subtunes[n_audio_tracks]; gint i = 0; /* only add the audio tracks to the playlist */ for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) if (cdda_track_audiop (pcdrom_drive, trackno)) subtunes[i ++] = trackno; tuple_set_subtunes (tuple, n_audio_tracks, subtunes); goto DONE; } trackno = find_trackno_from_filename (filename); if (trackno < firsttrackno || trackno > lasttrackno) { warn ("Track %d not found.\n", trackno); goto DONE; } if (!cdda_track_audiop (pcdrom_drive, trackno)) { warn ("Track %d is a data track.\n", trackno); goto DONE; } tuple = tuple_new_from_filename (filename); tuple_set_format (tuple, _("Audio CD"), 2, 44100, 1411); if (strlen (trackinfo[trackno].performer)) { tuple_set_str (tuple, FIELD_ARTIST, NULL, trackinfo[trackno].performer); } if (strlen (trackinfo[0].name)) { tuple_set_str (tuple, FIELD_ALBUM, NULL, trackinfo[0].name); } if (strlen (trackinfo[trackno].name)) { tuple_set_str (tuple, FIELD_TITLE, NULL, trackinfo[trackno].name); } tuple_set_int (tuple, FIELD_TRACK_NUMBER, NULL, trackno); tuple_set_int (tuple, FIELD_LENGTH, NULL, calculate_track_length (trackinfo[trackno]. startlsn, trackinfo[trackno]. endlsn)); if (strlen (trackinfo[trackno].genre)) { tuple_set_str (tuple, FIELD_GENRE, NULL, trackinfo[trackno].genre); } DONE: g_mutex_unlock (mutex); return tuple; }