File: do_display.c

package info (click to toggle)
libcddb 1.3.2-7.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,376 kB
  • sloc: sh: 10,958; ansic: 4,722; makefile: 44
file content (101 lines) | stat: -rw-r--r-- 3,555 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
    $Id: do_display.c,v 1.9 2006/10/15 06:50:15 airborne Exp $

    Copyright (C) 2003, 2004, 2005 Kris Verbeeck <airborne@advalvas.be>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA  02111-1307, USA.
*/

#include "main.h"

#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif

#ifdef HAVE_STRING_H
#include <string.h> /* strlen */
#endif

#define STR_OR_NULL(s) ((s) ? s : "(null)")

void do_display(cddb_disc_t *disc)
{
    cddb_track_t *track = NULL; /* libcddb track structure */
    int length;
    const char *s;

    /* 1. The artist name, disc title and extended data. */
    printf("Artist:   %s\n", STR_OR_NULL(cddb_disc_get_artist(disc)));
    printf("Title:    %s\n", STR_OR_NULL(cddb_disc_get_title(disc)));
    s = cddb_disc_get_ext_data(disc);
    if (s) {
        printf("Ext.data: %s\n", s);
    }

    /* 2. The music genre.  This field is similar to the category
       field initialized above.  It can be the same but it does not
       have to be.  The category can only be come from a set of CDDB
       predefined categories.  The genre can be any string. */
    printf("Genre:    %s\n", STR_OR_NULL(cddb_disc_get_genre(disc)));

    /* 3. The disc year. */
    printf("Year:     %d\n", cddb_disc_get_year(disc));

    /* 4. The disc length and the number of tracks.  The length field
       is given in seconds. */
    length = cddb_disc_get_length(disc);
    printf("Length:   %d:%02d (%d seconds)\n", (length / 60), (length % 60), length);
    printf("%d tracks\n", cddb_disc_get_track_count(disc));

    /* 5. The tracks.  Track iteration can either be done by counting
       from 0 to (track_count - 1) and using the cddb_disc_get_track
       function.  Or by using the built-in iterator functions
       cddb_disc_get_track_first and cddb_disc_get_track_next.  We'll
       use the latter approach in this example. */

    for (track = cddb_disc_get_track_first(disc); 
         track != NULL; 
         track = cddb_disc_get_track_next(disc)) {

        /* 5.a. The track number on the disc.  This track number
           starts counting at 1.  So this is not the same number as
           the one used in cddb_disc_get_track. */
        printf("  [%02d]", cddb_track_get_number(track));

        /* 5.b. The track artist name and title. */
        printf(" '%s'", cddb_track_get_title(track));
        s = cddb_track_get_artist(track);
        if (s) {
            printf(" by %s", s); 
        }

        /* 5.c. The track length. */
        length = cddb_track_get_length(track);
        if (length != -1) {
            printf(" (%d:%02d)", (length / 60), (length % 60));
        } else {
            printf(" (unknown)");
        }

        /* 5.d. The extended track data. */
        s = cddb_track_get_ext_data(track);
        if (s) {
            printf(" [%s]\n", s);
        } else {
            printf("\n");
        }
    }
}