~ubuntu-branches/ubuntu/trusty/sound-juicer/trusty

« back to all changes in this revision

Viewing changes to tests/mb-test.c

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2008-12-15 13:16:02 UTC
  • mfrom: (1.1.35 upstream) (2.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20081215131602-0bezbep7s4w4zy0s
Tags: 2.25.1-0ubuntu1
* Sync on Debian
* debian/control.in:
  - Build-depends on libcdio-dev and liblaunchpad-integration-dev
* debian/patches/01_lpi.patch,
  debian/patches/02_autoconf.patch:
  - lpi changes and configure update
* New upstream version (LP: #308165)
  - Chain the metadata lookups (Bastien Nocera)
  - Finish the libmusicbrainz3 metadata fetcher (BN)
  - Add a GVFS metadata fetcher as fallback (BN)
  - Make libcdio option, as it breaks the GPL+Exception license (BN)
  - Export ASIN, Discogs, Wikipedia in the internal metadata (BN)
  - Lots of other cleanups to the metadata code (BN)
  - Remove copy of the id3mux plugin, assume it exists now (BN)
  - Remove Encoding field from desktop file (Pacho Ramos)
  - Add Audio to desktop categories (Patryk Zawadzki)
  - Correctly parse CDDA URLs (Matthew Martin)
  - Don't free the option context
* debian/control.in:
  - Change build-dep on libmusicbrainz3-dev
  - Also build-dep on libneon26-gnutls-dev and libdiscid0-dev for lmb3
* debian/watch:
  - Update for 2.25.x releases

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#include <stdlib.h>
3
3
#include "sj-structures.h"
4
4
#include "sj-metadata.h"
5
 
#include "sj-metadata-musicbrainz.h"
 
5
#include "sj-metadata-getter.h"
 
6
 
 
7
static const char *
 
8
source_to_str (MetadataSource source)
 
9
{
 
10
        const char * strs[] = {
 
11
                "Unknown",
 
12
                "CD-Text",
 
13
                "FreeDB",
 
14
                "MusicBrainz",
 
15
                "Fallback"
 
16
        };
 
17
        return strs[source];
 
18
}
 
19
 
 
20
static const char *
 
21
release_type_to_id (const char *type)
 
22
{
 
23
        /* CD 2 of a multi-CD set
 
24
         * Beastie Boys - Anthology: The Sounds of Science (disc 2)
 
25
         * http://musicbrainz.org/release/0f15fc15-9538-44b6-aa19-4074934fc5ba.html */
 
26
        if (g_str_equal (type, "commercial"))
 
27
          return "rg4F4Od5EgOwfDaI0niQ2TnCaxk-";
 
28
        /* Non-existant CD
 
29
         * http://musicbrainz.org/bare/cdlookup.html?discid=aaaaaaaaaaaaaaaaaaaaaaaaaaaa */
 
30
        if (g_str_equal (type, "fake"))
 
31
          return "aaaaaaaaaaaaaaaaaaaaaaaaaaaa";
 
32
        /* Audio book
 
33
         * Harry Potter and the Sorcerer's Stone (feat. narrator: Jim Dale) (disc 1)
 
34
         * http://musicbrainz.org/release/947c6cdd-1188-4e3e-a53b-21bb3a49b79e.html */
 
35
        if (g_str_equal (type, "audiobook"))
 
36
          return "VJ0lpdqHGE7r8wr.N8D6Q0G.pCs-";
 
37
 
 
38
        return NULL;
 
39
}
6
40
 
7
41
static void
8
 
metadata_cb (SjMetadata *metadata, GList *albums, GError *error)
 
42
metadata_cb (SjMetadataGetter *metadata, GList *albums, GError *error)
9
43
{
 
44
  char *url;
 
45
 
10
46
  if (error != NULL) {
11
47
    g_print ("Error: %s\n", error->message);
12
 
    g_error_free (error);
13
48
    g_object_unref (metadata);
14
49
    exit (1);
15
50
  }
16
51
 
 
52
  url = sj_metadata_getter_get_submit_url (metadata);
 
53
  g_print ("Submit URL: %s\n", url);
 
54
  g_free (url);
 
55
 
17
56
  while (albums) {
18
57
    AlbumDetails *album;
19
58
    album = (AlbumDetails*)albums->data;
20
 
    g_print ("'%s', by %s\n", album->title, album->artist);
 
59
    char *disc_number;
 
60
    g_print ("Source: %s\n", source_to_str(album->metadata_source));
 
61
    if (album->metadata_source == SOURCE_MUSICBRAINZ)
 
62
      g_print ("Album ID: %s\n", album->album_id);
 
63
    if (album->asin != NULL)
 
64
      g_print ("ASIN: %s\n", album->asin);
 
65
    if (album->discogs != NULL)
 
66
      g_print ("Discogs: %s\n", album->discogs);
 
67
    if (album->wikipedia != NULL)
 
68
      g_print ("Wikipedia: %s\n", album->wikipedia);
 
69
    if (album->is_spoken_word)
 
70
      g_print ("Is spoken word\n");
 
71
    disc_number = g_strdup_printf (" (Disc %d)", album->disc_number);
 
72
    g_print ("'%s', by %s%s\n", album->title, album->artist, album->disc_number ? disc_number : "");
 
73
    g_free (disc_number);
21
74
    while (album->tracks) {
22
75
      TrackDetails *track = (TrackDetails*)album->tracks->data;
23
76
      g_print (" Track %d; Title: %s; Artist: %s Duration: %d sec\n", track->number, track->title, track->artist, track->duration);
32
85
 
33
86
int main (int argc, char** argv)
34
87
{
35
 
  SjMetadata *metadata;
 
88
  SjMetadataGetter *metadata;
36
89
  GMainLoop *loop;
 
90
  GError *error = NULL;
37
91
 
38
92
  g_type_init ();
39
93
  g_thread_init (NULL);
40
94
  
41
 
  metadata = (SjMetadata*)sj_metadata_musicbrainz_new ();
 
95
  metadata = sj_metadata_getter_new ();
42
96
 
43
97
  if (argc == 2) {
44
 
    sj_metadata_set_cdrom (metadata, argv[1]);
 
98
    sj_metadata_getter_set_cdrom (metadata, argv[1]);
 
99
  } else if (argc == 3) {
 
100
    const char *id;
 
101
    sj_metadata_getter_set_cdrom (metadata, argv[1]);
 
102
    id = release_type_to_id (argv[2]);
 
103
    g_message ("argv %s id %s", argv[2], id);
 
104
    if (id == NULL) {
 
105
      g_print ("The faked type of disc must be one of: commercial, fake, audiobook\n");
 
106
      exit(1);
 
107
    }
 
108
    g_setenv ("MUSICBRAINZ_FORCE_DISC_ID", id, TRUE);
45
109
  } else {
46
 
    g_print ("Usage: %s [CD device]\n", argv[0]);
 
110
    g_print ("Usage: %s [CD device] [commercial|fake|audiobook]\n", argv[0]);
47
111
    exit (1);
48
112
  }
49
113
 
50
114
  g_signal_connect (G_OBJECT (metadata), "metadata",
51
115
                    G_CALLBACK (metadata_cb), NULL);
52
 
  sj_metadata_list_albums (metadata, NULL);
 
116
  if (sj_metadata_getter_list_albums (metadata, &error) == FALSE) {
 
117
    g_warning ("Couldn't list tracks on album: %s", error->message);
 
118
    g_error_free (error);
 
119
    return 1;
 
120
  }
53
121
 
54
122
  loop = g_main_loop_new (NULL, FALSE);
55
123
  g_main_loop_run (loop);