~ubuntu-branches/ubuntu/raring/libcddb/raring

« back to all changes in this revision

Viewing changes to examples/do_album.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-01-17 18:24:43 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100117182443-lnkwqi0fvdc5c4jg
Tags: 1.3.2-0ubuntu1
* New upstream release.
 - Fix a crash on aqualung (LP: #316056)
* debian/control:
 - Build-depends on libcdio-dev (>= 0.76).
 - Add Section libs.
 - Use ${binary:Version} instead of ${Source-Version} substvar.
 - Add missing ${misc:Depends}.
 - Build-depends on debhelper (>= 5.0.0).
* debian/rules:
 - Update SONAME minor version.
 - Don't ignore error on distclean.
 - Use debian/compat instead of using export DH_COMPAT.
* debian/*.install:
 - Remove unused /usr/lib/include/* location.
* debian/libcddb2.postinst & libcddb2.postrm:
 - Remove, it's automatically handle by debhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    $Id: do_album.c,v 1.1 2006/10/15 09:04:08 airborne Exp $
 
3
 
 
4
    Copyright (C) 2006 Kris Verbeeck <airborne@advalvas.be>
 
5
 
 
6
    This library is free software; you can redistribute it and/or
 
7
    modify it under the terms of the GNU Library General Public
 
8
    License as published by the Free Software Foundation; either
 
9
    version 2 of the License, or (at your option) any later version.
 
10
 
 
11
    This library is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
    Library General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU Library General Public
 
17
    License along with this library; if not, write to the
 
18
    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
19
    Boston, MA  02111-1307, USA.
 
20
*/
 
21
 
 
22
#include "main.h"
 
23
 
 
24
 
 
25
void do_album(cddb_conn_t *conn, cddb_disc_t *disc, int quiet)
 
26
{
 
27
    int matches, i;
 
28
 
 
29
    /* Try searching the database for information about the provided
 
30
       album and/or artits.  This function will return the number of
 
31
       matches that were found.  A return value of 0 means that no
 
32
       matches were found.  The data of the first match (when found)
 
33
       will be filled in into the disc structure passed to it. */
 
34
    matches = cddb_album(conn, disc);
 
35
 
 
36
    /* If an error occured then the return value will be -1 and the
 
37
       internal libcddb error number will be set. */
 
38
    if (matches == -1) {
 
39
        /* Print an explanatory message on stderr.  Other routines are
 
40
           available for retrieving the message without printing it or
 
41
           printing it on a stream other than stderr. */
 
42
        if (!quiet) {
 
43
            cddb_error_print(cddb_errno(conn));
 
44
        }
 
45
        /* Return to calling fucntion. */
 
46
        return;
 
47
    }
 
48
 
 
49
    printf("Number of matches: %d\n", matches);
 
50
    /* A CDDB album command will not return all the disc information.
 
51
       It will return a subset that can afterwards be used to do a
 
52
       CDDB read.  This enables you to first show a pop-up listing the
 
53
       found matches before doing further reads for the full data.
 
54
       The data that is returned for each match is: the disc CDDB
 
55
       category, the disc ID as known by the server, the disc title
 
56
       and the artist's name. */
 
57
 
 
58
    /* Let's loop over the matches. */
 
59
    i = 0;
 
60
    while (i < matches) {
 
61
        /* Increment the match counter. */
 
62
        i++;
 
63
 
 
64
        /* Print out the information for the current match. */
 
65
        printf("Match %d\n", i);
 
66
        /* Retrieve and print the category and disc ID. */
 
67
        printf("  category: %s (%d)\t%08x\n", cddb_disc_get_category_str(disc),
 
68
               cddb_disc_get_category(disc), cddb_disc_get_discid(disc));
 
69
        /* Retrieve and print the disc title and artist name. */
 
70
        printf("  '%s' by %s\n", cddb_disc_get_title(disc),
 
71
               cddb_disc_get_artist(disc));
 
72
 
 
73
        /* Get the next match, if there is one left. */
 
74
        if (i < matches) {
 
75
            /* If there are multiple matches, then you can use the
 
76
               following function to retrieve the matches beyond the
 
77
               first.  This function will overwrite any data that
 
78
               might be present in the disc structure passed to it.
 
79
               So if you still need that disc for anything else, then
 
80
               first create a new disc and use that to call this
 
81
               function.  If there are no more matches left, false
 
82
               (i.e. 0) will be returned. */
 
83
            if (!cddb_album_next(conn, disc)) {
 
84
                error_exit(cddb_errno(conn), "album index out of bounds");
 
85
            }
 
86
        }
 
87
    }
 
88
}