lib: vlm: privatize libvlc_vlm_t
[vlc.git] / modules / meta_engine / ID3Meta.h
blob5c841cb8d07354699eb9d94fb48391c7e0fb2dd4
1 /*****************************************************************************
2 * ID3Meta.h : ID3v2 Meta Helper
3 *****************************************************************************
4 * Copyright (C) 2016 VLC authors and VideoLAN
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
20 #ifndef ID3META_H
21 #define ID3META_H
23 #include <vlc_meta.h>
24 #include <vlc_charset.h>
26 #define vlc_meta_extra vlc_meta_Title
27 struct
29 uint32_t i_tag;
30 vlc_meta_type_t type;
31 const char *psz;
32 } const ID3_tag_to_metatype[] = {
33 { VLC_FOURCC('T', 'A', 'L', 'B'), vlc_meta_Album, NULL },
34 { VLC_FOURCC('T', 'D', 'R', 'C'), vlc_meta_Date, NULL },
35 { VLC_FOURCC('T', 'E', 'N', 'C'), vlc_meta_extra, "Encoder" },
36 { VLC_FOURCC('T', 'I', 'T', '2'), vlc_meta_Title, NULL },
37 { VLC_FOURCC('T', 'O', 'P', 'E'), vlc_meta_extra, "Original Artist" },
38 { VLC_FOURCC('T', 'O', 'R', 'Y'), vlc_meta_extra, "Original Release Year" },
39 { VLC_FOURCC('T', 'P', 'E', '1'), vlc_meta_Artist, NULL },
40 { VLC_FOURCC('T', 'P', 'E', '2'), vlc_meta_AlbumArtist, NULL },
41 { VLC_FOURCC('T', 'R', 'S', 'N'), vlc_meta_Publisher, NULL },
42 { VLC_FOURCC('T', 'R', 'S', 'O'), vlc_meta_extra, "Radio Station Owner" },
44 #undef vlc_meta_extra
46 static bool ID3TextTagHandler( const uint8_t *p_buf, size_t i_buf,
47 vlc_meta_type_t type, const char *psz_extra,
48 vlc_meta_t *p_meta, bool *pb_updated )
50 char *p_alloc = NULL;
51 const char *psz;
52 if( i_buf > 3 && p_meta && p_buf[0] < 0x04 )
54 switch( p_buf[0] )
56 case 0x00:
57 psz = p_alloc = FromCharset( "ISO_8859-1", &p_buf[1], i_buf - 1 );
58 break;
59 case 0x01:
60 psz = p_alloc = FromCharset( "UTF-16LE", &p_buf[1], i_buf - 1 );
61 break;
62 case 0x02:
63 psz = p_alloc = FromCharset( "UTF-16BE", &p_buf[1], i_buf - 1 );
64 break;
65 default:
66 case 0x03:
67 if( p_buf[ i_buf - 1 ] != 0x00 )
69 psz = p_alloc = (char *) malloc( i_buf );
70 if( p_alloc )
72 memcpy( p_alloc, &p_buf[1], i_buf - 1 );
73 p_alloc[i_buf - 1] = 0;
76 else
78 psz = (const char *) &p_buf[1];
80 break;
83 if( psz && *psz )
85 const char *psz_old = ( psz_extra ) ? vlc_meta_GetExtra( p_meta, psz_extra ):
86 vlc_meta_Get( p_meta, type );
87 if( !psz_old || strcmp( psz_old, psz ) )
89 if( pb_updated )
90 *pb_updated = true;
91 if( psz_extra )
92 vlc_meta_AddExtra( p_meta, psz_extra, psz );
93 else
94 vlc_meta_Set( p_meta, type, psz );
98 free( p_alloc );
99 return true;
101 return false;
104 static bool ID3LinkFrameTagHandler( const uint8_t *p_buf, size_t i_buf,
105 vlc_meta_t *p_meta, bool *pb_updated )
107 if( i_buf > 13 && p_meta )
109 const char *psz = (const char *)&p_buf[1];
110 size_t i_len = i_buf - 1;
111 size_t i_desclen = strnlen(psz, i_len);
112 if( i_desclen < i_len - 1 && i_desclen > 11 &&
113 !strncmp( "artworkURL_", psz, 11 ) )
115 const char *psz_old = vlc_meta_Get( p_meta, vlc_meta_ArtworkURL );
116 if( !psz_old || strncmp( psz_old, &psz[i_desclen], i_len - i_desclen ) )
118 char *p_alloc = strndup(&psz[i_desclen + 1], i_len - i_desclen - 1);
119 vlc_meta_Set( p_meta, vlc_meta_ArtworkURL, p_alloc );
120 free( p_alloc );
121 *pb_updated = true;
124 return true;
126 return false;
129 static bool ID3HandleTag( const uint8_t *p_buf, size_t i_buf,
130 uint32_t i_tag,
131 vlc_meta_t *p_meta, bool *pb_updated )
133 if( ((const char *) &i_tag)[0] == 'T' )
135 for( size_t i=0; i<ARRAY_SIZE(ID3_tag_to_metatype); i++ )
137 if( ID3_tag_to_metatype[i].i_tag == i_tag )
138 return ID3TextTagHandler( p_buf, i_buf,
139 ID3_tag_to_metatype[i].type,
140 ID3_tag_to_metatype[i].psz,
141 p_meta, pb_updated );
144 else if( i_tag == VLC_FOURCC('W', 'X', 'X', 'X') )
146 return ID3LinkFrameTagHandler( p_buf, i_buf, p_meta, pb_updated );
149 return false;
152 #endif