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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
/*****************************************************************
* gmerlin - a general purpose multimedia framework and applications
*
* Copyright (c) 2001 - 2024 Members of the Gmerlin project
* http://github.com/bplaum
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* *****************************************************************/
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <gmerlin/utils.h>
#include <cddb/cddb.h>
#include <gavl/metatags.h>
#include "cdaudio.h"
//#define DUMP
int bg_cdaudio_get_metadata_cddb(bg_cdaudio_index_t * idx,
gavl_dictionary_t * mi,
char * cddb_host,
int cddb_port,
char * cddb_path,
char * cddb_proxy_host,
int cddb_proxy_port,
char * cddb_proxy_user,
char * cddb_proxy_pass,
int cddb_timeout)
{
int i, success;
int num_matches;
unsigned int disc_id_call, date;
gavl_dictionary_t *m;
char *genre;
const char *album;
cddb_disc_t * disc = NULL;
cddb_conn_t * conn = NULL;
cddb_track_t * track = NULL;
/* create a new disk */
disc = cddb_disc_new();
if (disc == NULL)
{
return 0;
}
/* create new tracks and add to disk */
for( i = 0; i < idx->num_tracks; i++ )
{
/* create a new track */
track = cddb_track_new();
if (track == NULL)
{
return 0;
}
cddb_track_set_frame_offset( track, idx->tracks[i].first_sector+150);
cddb_disc_add_track(disc, track);
}
cddb_disc_set_length(disc, (idx->tracks[idx->num_tracks-1].last_sector+1+150)/75);
/* create new connection */
conn = cddb_new();
if (conn == NULL)
{
return 0;
}
if(cddb_disc_calc_discid(disc) == 1)
{
disc_id_call = cddb_disc_get_discid(disc);
}
/* HTTP settings */
cddb_http_enable(conn);
cddb_set_server_port(conn, cddb_port);
cddb_set_server_name(conn, cddb_host);
cddb_set_http_path_query(conn, cddb_path);
cddb_set_timeout(conn, cddb_timeout);
if(cddb_proxy_host)
{
/* HTTP settings with proxy */
cddb_http_proxy_enable(conn);
cddb_set_http_proxy_server_name(conn, cddb_proxy_host);
cddb_set_http_proxy_server_port(conn, cddb_proxy_port);
if(cddb_proxy_user && cddb_proxy_pass)
cddb_set_http_proxy_credentials(conn, cddb_proxy_user, cddb_proxy_pass);
}
/* connect cddb to find similar discs */
cddb_cache_only(conn);
num_matches = cddb_query(conn, disc);
if (num_matches == -1)
{
/* something went wrong, print error */
cddb_error_print(cddb_errno(conn));
return 0;
}
if(num_matches == 0)
{
cddb_cache_disable(conn);
num_matches = cddb_query(conn, disc);
if (num_matches == -1)
{
/* something went wrong, print error */
cddb_error_print(cddb_errno(conn));
return 0;
}
cddb_cache_enable(conn);
}
/* info for gmerlin from the first match */
genre = gavl_strdup(cddb_disc_get_category_str(disc));
genre[0] = toupper(genre[0]);
disc_id_call = cddb_disc_get_discid(disc);
cddb_disc_set_category_str(disc, genre);
cddb_disc_set_discid(disc, disc_id_call);
success = cddb_read(conn, disc);
if(!success)
{
cddb_error_print(cddb_errno(conn));
return 0;
}
album = cddb_disc_get_title(disc);
date = cddb_disc_get_year(disc);
for(i = 0; i < idx->num_tracks; i++)
{
if(!idx->tracks[i].is_audio)
continue;
m = gavl_get_track_nc(mi, idx->tracks[i].index);
m = gavl_track_get_metadata_nc(m);
track = cddb_disc_get_track(disc, i);
gavl_dictionary_set_string(m, GAVL_META_ARTIST, cddb_track_get_artist(track));
gavl_dictionary_set_string(m, GAVL_META_TITLE, cddb_track_get_title(track));
gavl_dictionary_set_string(m, GAVL_META_GENRE, genre);
gavl_dictionary_set_string(m, GAVL_META_ALBUM, album);
if(date)
gavl_dictionary_set_int(m, GAVL_META_YEAR, date);
}
/* clean up all trash */
if(genre)
free(genre);
cddb_destroy(conn);
cddb_disc_destroy(disc);
return 1;
}
static void __cleanup() __attribute__ ((destructor));
static void __cleanup()
{
libcddb_shutdown();
}
|