/*---------------------------------------------------------------------------- libtunepimp -- The MusicBrainz tagging library. Let a thousand taggers bloom! Copyright (C) Robert Kaye 2003 This file is part of libtunepimp. libtunepimp 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. libtunepimp 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 libtunepimp; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: puid.c 7959 2006-06-29 00:48:30Z luks $ ----------------------------------------------------------------------------*/ #include #include #include #ifdef WIN32 #include #else #include #endif #include #include #include "../config.h" char *EscapeFormValue(const char *form_value) { int i, form_value_length, extra_length; char *escaped_value, *ptr; form_value_length = strlen(form_value); for (i = 0, extra_length = 0; i < form_value_length; ++i) { switch(form_value[i]) { case '"': extra_length += 5; break; case '&': extra_length += 4; break; case '<': case '>': extra_length += 3; break; } } if (extra_length == 0) { // This is necessary since the caller must free the memory. return strdup(form_value); } escaped_value = (char *)malloc(form_value_length + extra_length + 1); for (i = 0, ptr = escaped_value; i < form_value_length; ++i) { switch(form_value[i]) { case '"': strcpy(ptr, """); ptr += 6; break; case '&': strcpy(ptr, "&"); ptr += 5; break; case '<': strcpy(ptr, "<"); ptr += 4; break; case '>': strcpy(ptr, ">"); ptr += 4; break; default: *(ptr++) = form_value[i]; } } *ptr = 0; return escaped_value; } int CreateLookupPage(const char *outFile, track_t *track, metadata_t *data, const char *server) { FILE *out; char *temp, srcFile[1024], puid[255]; tr_GetFileName(track, srcFile, 1024); tr_GetPUID(track, puid, 255); out = fopen(outFile, "wt"); if (!out) return 0; fprintf(out, "\n" "MusicBrainz Lookup\n" "\n" "
\n" "

MusicBrainz Loookup

\n" "Looking up file at MusicBrainz.\n" "

\n", server); temp = EscapeFormValue(data->artist); fprintf(out, " \n", temp); free(temp); temp = EscapeFormValue(data->album); fprintf(out, " \n", temp); free(temp); temp = EscapeFormValue(data->track); fprintf(out, " \n", temp); free(temp); temp = EscapeFormValue(data->trackId); fprintf(out, " \n", temp); free(temp); temp = EscapeFormValue(srcFile); fprintf(out, " \n", temp); free(temp); temp = EscapeFormValue(puid); fprintf(out, " \n", temp); free(temp); fprintf(out, " \n" " \n" "
\n" "
\n" "\n" "\n", data->duration, data->trackNum); fclose(out); return 1; } void LookupMetadata(track_t track, const char *fileName) { metadata_t *data; char *server; char *outFile = "/tmp/lookup.html"; char *url = "file:///tmp/lookup.html"; if (getenv("MB_SERVER")) server = getenv("MB_SERVER"); else server = "musicbrainz.org"; data = md_New(); tr_GetLocalMetadata(track, data); CreateLookupPage(outFile, track, data, server); md_Delete(data); LaunchBrowser(url, "mozilla"); } void PrintMetadata(track_t *track) { metadata_t *data; char puid[255]; data = md_New(); tr_GetPUID(track, puid, 255); tr_GetLocalMetadata(track, data); printf(" Artist: '%s'\n", data->artist); printf(" Album: '%s'\n", data->album); printf(" Track: '%s'\n", data->track); printf("TrackNum: '%d'\n", data->trackNum); printf("Duration: '%lu'\n", data->duration); printf(" PUID: %s\n", puid); md_Delete(data); } int main(int argc, char *argv[]) { int index = 1, isLookup = 0, printID3 = 0; tunepimp_t pimp; track_t track; int done, fileId, i; TPCallbackEnum type; TPFileStatus status; char puid[255], clientId[128]; int analyzed = 0; #ifdef WIN32 WSADATA sGawdIHateMicrosoft; #endif if (argc < 2) { int num; char ext[10][32]; fprintf(stderr,"usage: puid [-i|-l]