[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gmediaserver-devel] Ugly (but working) single day coding TagLib hac
From: |
Harry ten Berge |
Subject: |
Re: [gmediaserver-devel] Ugly (but working) single day coding TagLib hack |
Date: |
Sat, 17 Dec 2005 19:06:15 +0100 |
User-agent: |
KMail/1.9 |
Amazing... Truly amazing! :-)
Not enough time myself to figure this out, but you did it... Great!
I will experiment with it on my Philips device.
PS.: does this mean that every wish I've got in mind for GMediaServer is
implemented by you? :-)
Regards Harry
On Saturday 17 December 2005 14:25, Jiri Wichern wrote:
> Hi guys,
>
> I was thinking about TagLib, mentioned by Harry ten Berge.
> I dearly wanted sensible titles in my SMC ezstream and because ID3Lib
> didn't want to compile at my server i looked into TagLib.
> It did give me some problems (primarilly because TagLib is written in C++
> and gmediaserver is C) but I do now have working song titles. Why my SMC
> ezstream only shows the song title and not stuff like the album im still
> looking into.
> One warning for purist coders: THIS CODE IS UGLY AS H*LL. I won't be
> responsible for your PC catching fire, your brain getting fried and your
> girlfriend leaving as a result of reading this.
>
> I also tried some configuring stuff. Got detection of TagLib right but i
> lack the knowledge to correctly modify the makefile.in and makefile.am ...
> so i won't bother you with that stuff...
> I used gmediaserver-0.8.2. Affected files so far:
>
> /:
> configure
> config.h.in
>
> src/:
> main.c
> gmediaserver.h
> metadata.c
> makefile.am
> makefile.in
> (new)taglib_wrapper.h
> (new)taglib_wrapper.cpp
>
> $$main.c diff:
> 71c71
> < #ifdef HAVE_ID3LIB
> ---
>
> > #if (defined HAVE_ID3LIB || defined HAVE_TAGLIB)
>
> 172c172
> < #ifdef HAVE_ID3LIB
> ---
>
> > #if (defined HAVE_ID3LIB || defined HAVE_TAGLIB)
>
> 250c250
> < #ifdef HAVE_ID3LIB
> ---
>
> > #if (defined HAVE_ID3LIB || defined HAVE_TAGLIB)
>
> $$gmediaserver.h diff:
> 191c191
> < #ifdef HAVE_ID3LIB
> ---
>
> > #if (defined HAVE_ID3LIB || defined HAVE_TAGLIB)
>
> $$metadata.c diff:
> 27a28,30
>
> > #ifdef HAVE_TAGLIB
> > #include "taglib_wrapper.h"
> > #endif
>
> 118c121
> < #ifdef HAVE_ID3LIB
> ---
>
> > #if (defined HAVE_ID3LIB || defined HAVE_TAGLIB)
>
> 553c556
> < #ifdef HAVE_ID3LIB
> ---
>
> > #if (defined HAVE_ID3LIB || defined HAVE_TAGLIB)
>
> 592c595
> < #ifdef HAVE_ID3LIB
> ---
>
> > #if (defined HAVE_ID3LIB || defined HAVE_TAGLIB)
>
> 674c677
> < #ifdef HAVE_ID3LIB
> ---
>
> > #if (defined HAVE_ID3LIB || defined HAVE_TAGLIB)
>
> $$taglib_wrapper.h:
> #include <config.h>
>
> #ifdef HAVE_TAGLIB
>
> #ifdef __cplusplus
> extern "C"
> {
> #endif
> typedef struct
> {
> void **vppFileRef;
> } ID3Tag;
>
> typedef enum
> {
> ID3FID_TITLE,
> ID3FID_ALBUM,
> ID3FID_LEADARTIST,
> ID3FID_CONTENTTYPE
> } ID3FrameID ;
>
> ID3Tag *ID3Tag_New();
> void ID3Tag_Delete(ID3Tag *pTag);
> void ID3Tag_Clear(ID3Tag *pTag);
>
> void ID3Tag_Link(ID3Tag *pTag, const char *cpPath);
> int ID3Tag_NumFrames(ID3Tag *pTag);
>
> char *get_id3_string(ID3Tag *pTag, ID3FrameID frame_id);
> #ifdef __cplusplus
> }
> #endif
>
>
> #endif
>
> $$taglib_wrapper.cpp:
> #include "taglib_wrapper.h"
>
> #ifdef HAVE_TAGLIB
> #include <fileref.h>
> #include <tag.h>
> extern "C"
> {
> #include "gmediaserver.h"
> }
>
> using namespace std;
>
> TagLib::FileRef ***pppFileList = NULL;
> unsigned int uiNrOfFiles = 0;
>
> ID3Tag *ID3Tag_New()
> {
> say(4, "Creating ID3Tag. ");
> uiNrOfFiles++;
> pppFileList = (TagLib::FileRef***)realloc(pppFileList, uiNrOfFiles *
> sizeof(TagLib::FileRef**));
> pppFileList[uiNrOfFiles] = new TagLib::FileRef*;
> *pppFileList[uiNrOfFiles] = NULL;
>
> ID3Tag *pReturnTag = new ID3Tag;
> pReturnTag->vppFileRef = (void**)pppFileList[uiNrOfFiles];
> say(4, "Taglib pointer: %d\n", *(pReturnTag->vppFileRef));
> return pReturnTag;
> }
>
> void ID3Tag_Delete(ID3Tag *pTag)
> {
> if((pTag == NULL)
>
> || (pTag->vppFileRef == NULL) )
>
> return;
>
> say(4, "Deleting ID3Tag. ");
> say(4, "Taglib pointer: %d\n", *(pTag->vppFileRef));
>
> for(unsigned int uiTemp = 0; uiTemp < uiNrOfFiles; uiTemp++)
> {
> if(*(pTag->vppFileRef) == (void*)pppFileList[uiTemp])
> {
> delete *pppFileList[uiTemp];
> delete pppFileList[uiTemp];
> for(; uiTemp < uiNrOfFiles - 1; uiTemp++)
> {
> pppFileList[uiTemp] = pppFileList[uiTemp + 1];
> }
> uiNrOfFiles--;
> pppFileList = (TagLib::FileRef***)realloc(pppFileList, uiNrOfFiles
> * sizeof(TagLib::FileRef**));
> break;
> }
> }
> delete pTag;
> }
>
> void ID3Tag_Clear(ID3Tag *pTag)
> {
> if((pTag == NULL)
>
> || (pTag->vppFileRef == NULL) )
>
> return;
>
> say(4, "Clearing ID3Tag. ");
> say(4, "Taglib pointer: %d\n", *(pTag->vppFileRef));
>
> delete (TagLib::FileRef*) *(pTag->vppFileRef);
> *(pTag->vppFileRef) = NULL;
>
> }
>
> void ID3Tag_Link(ID3Tag *pTag, const char *cpPath)
> {
> if((pTag == NULL)
>
> || (pTag->vppFileRef == NULL)
> || (cpPath == NULL) )
>
> return;
>
> say(4, "Linking ID3Tag. ");
>
> TagLib::FileRef *pFileRef = new TagLib::FileRef(cpPath);
>
> if(!pFileRef->isNull() && pFileRef->tag())
> {
> *(pTag->vppFileRef) = pFileRef;
> say(4, "Taglib pointer: %d\n", *(pTag->vppFileRef));
> }
> else
> {
> say(4, "Incorrect file or empty tag.\n");
> delete pFileRef;
> }
> }
>
> int ID3Tag_NumFrames(ID3Tag *pTag)
> {
> if((pTag == NULL)
>
> || (pTag->vppFileRef == NULL) )
>
> return 0;
>
> say(4, "Getting number of ID3Tags. ");
> say(4, "Taglib pointer: %d\n", *(pTag->vppFileRef));
>
> const char *cpString =
> ((TagLib::FileRef*)*(pTag->vppFileRef))->tag()->title().toCString();
> say(4, "check: %s.\n", cpString);
> /**/int iReturn = 1;
>
> say(4, "Returning: %d\n", iReturn);
> return iReturn;
> }
>
> char *get_id3_string(ID3Tag *pTag, ID3FrameID frame_id)
> {
> const char *cpString = "<ERROR>";
>
> do
> {
> if((pTag == NULL)
>
> || (pTag->vppFileRef == NULL) )
>
> break;
>
> say(4, "Getting string from ID3Tags");
> say(4, "Taglib pointer: %d", *(pTag->vppFileRef));
>
> TagLib::Tag *pLTag =
> ((TagLib::FileRef*)*(pTag->vppFileRef))->tag();
>
> switch(frame_id)
> {
> case ID3FID_TITLE:
> cpString = pLTag->title().toCString();
> break;
> case ID3FID_ALBUM:
> cpString = pLTag->album().toCString();
> break;
> case ID3FID_LEADARTIST:
> cpString = pLTag->artist().toCString();
> break;
> case ID3FID_CONTENTTYPE:
> cpString = "???";//pLTag->title().toCString();
> break;
> }
> } while(0);
>
> char *cpBuffer = new char[strlen(cpString) + 1];
> strcpy(cpBuffer, cpString);
>
> say(4, "Returning: %s\n", cpBuffer);
> return cpBuffer;
> }
> #endif
--
Harry ten Berge <address@hidden>
OpenSUSE 10.0
KMail 1.9