[vlc-devel] [PATCH 2/3] Save album art to id3 tag.
Rafaël Carré
funman at videolan.org
Sat Jul 28 16:48:40 CEST 2012
Hello, a few small remarks:
Le 2012-07-28 16:39, vlc-devel at szanni.org a écrit :
^^^^^^^^^^^^^^^^^^^^
Can you check your git setup to add your name?
> ---
> modules/meta_engine/taglib.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 63 insertions(+)
>
>
> 0002-Save-album-art-to-id3-tag.patch
>
>
> diff --git a/modules/meta_engine/taglib.cpp b/modules/meta_engine/taglib.cpp
> index 148401b..3c20540 100644
> --- a/modules/meta_engine/taglib.cpp
> +++ b/modules/meta_engine/taglib.cpp
> @@ -32,6 +32,8 @@
> #include <vlc_demux.h> /* demux_meta_t */
> #include <vlc_strings.h> /* vlc_b64_decode_binary */
> #include <vlc_input.h> /* for attachment_new */
> +#include <vlc_url.h> /* make_path */
> +#include <vlc_httpd.h> /* mime content-type */
>
> #ifdef WIN32
> # include <vlc_charset.h>
> @@ -40,6 +42,7 @@
> # include <unistd.h>
> #endif
>
> +#include <stdio.h>
This is not needed (see below)
>
> // Taglib headers
> #include <taglib.h>
> @@ -709,6 +712,66 @@ static void WriteMetaToId3v2( ID3v2::Tag* tag, input_item_t* p_item )
> WRITE( Publisher, "TPUB" );
>
> #undef WRITE
> +
> + //Write album art
> + char *psz_url = input_item_GetArtworkURL( p_item );
> + if( psz_url )
> + {
> + ID3v2::FrameList frames = tag->frameList( "APIC" );
> + ID3v2::AttachedPictureFrame *frame = NULL;
> + if( frames.isEmpty() )
> + {
> + frame = new TagLib::ID3v2::AttachedPictureFrame;
> + tag->addFrame( frame );
> + }
> + else
> + {
> + frame = static_cast<ID3v2::AttachedPictureFrame *>( frames.back() );
> + }
> +
> + FILE *p_file = fopen( make_path( psz_url ), "rb" );
Please use vlc_fopen() and similar which work on all OS (see vlc_fs.h
header).
> + if( p_file == NULL )
> + {
> + free( psz_url );
> + return;
> + }
> +
> + fseek( p_file, 0, SEEK_END );
> + long l_buffer = ftell( p_file );
> + rewind( p_file );
> +
> + if( l_buffer == -1 )
> + {
> + fclose( p_file );
> + free( psz_url );
> + return;
> + }
> +
> + char *p_buffer = new (std::nothrow) char[l_buffer];
> + if ( !p_buffer )
> + {
> + fclose( p_file );
> + free( psz_url );
> + return;
> + }
> +
> + long l_read = fread( p_buffer, 1, l_buffer, p_file );
> + if ( l_read != l_buffer )
> + {
> + fclose( p_file );
> + free( psz_url );
> + delete[] p_buffer;
> + return;
> + }
> + fclose( p_file );
> +
> + ByteVector data( p_buffer, l_buffer );
> + delete[] p_buffer;
> +
> + frame->setPicture( data );
> + frame->setMimeType( httpd_MimeFromUrl( psz_url ) );
> + }
> + free ( psz_url );
> }
More information about the vlc-devel
mailing list