/src/vlc/modules/meta_engine/ID3Meta.h
Line | Count | Source (jump to first uncovered line) |
1 | | /***************************************************************************** |
2 | | * ID3Meta.h : ID3v2 Meta Helper |
3 | | ***************************************************************************** |
4 | | * Copyright (C) 2016 VLC authors and VideoLAN |
5 | | * |
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. |
10 | | * |
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. |
15 | | * |
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 |
22 | | |
23 | | #include <vlc_meta.h> |
24 | | #include "ID3Text.h" |
25 | | |
26 | | #define vlc_meta_extra vlc_meta_Title |
27 | | static struct |
28 | | { |
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" }, |
43 | | }; |
44 | | #undef vlc_meta_extra |
45 | | |
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 ) |
49 | 0 | { |
50 | 0 | if( p_meta == NULL ) |
51 | 0 | return false; |
52 | | |
53 | 0 | char *p_alloc; |
54 | 0 | const char *psz = ID3TextConvert( p_buf, i_buf, &p_alloc ); |
55 | 0 | if( psz && *psz ) |
56 | 0 | { |
57 | 0 | const char *psz_old = ( psz_extra ) ? vlc_meta_GetExtra( p_meta, psz_extra ): |
58 | 0 | vlc_meta_Get( p_meta, type ); |
59 | 0 | if( !psz_old || strcmp( psz_old, psz ) ) |
60 | 0 | { |
61 | 0 | if( pb_updated ) |
62 | 0 | *pb_updated = true; |
63 | 0 | if( psz_extra ) |
64 | 0 | vlc_meta_AddExtra( p_meta, psz_extra, psz ); |
65 | 0 | else |
66 | 0 | vlc_meta_Set( p_meta, type, psz ); |
67 | 0 | } |
68 | 0 | } |
69 | 0 | free( p_alloc ); |
70 | |
|
71 | 0 | return (psz != NULL); |
72 | 0 | } Unexecuted instantiation: es.c:ID3TextTagHandler Unexecuted instantiation: meta.c:ID3TextTagHandler |
73 | | |
74 | | static bool ID3LinkFrameTagHandler( const uint8_t *p_buf, size_t i_buf, |
75 | | vlc_meta_t *p_meta, bool *pb_updated ) |
76 | 0 | { |
77 | 0 | if( i_buf > 13 && p_meta ) |
78 | 0 | { |
79 | 0 | const char *psz = (const char *)&p_buf[1]; |
80 | 0 | size_t i_len = i_buf - 1; |
81 | 0 | size_t i_desclen = strnlen(psz, i_len); |
82 | 0 | if( i_desclen < i_len - 1 && i_desclen > 11 && |
83 | 0 | !strncmp( "artworkURL_", psz, 11 ) ) |
84 | 0 | { |
85 | 0 | const char *psz_old = vlc_meta_Get( p_meta, vlc_meta_ArtworkURL ); |
86 | 0 | if( !psz_old || strncmp( psz_old, &psz[i_desclen], i_len - i_desclen ) ) |
87 | 0 | { |
88 | 0 | char *p_alloc = strndup(&psz[i_desclen + 1], i_len - i_desclen - 1); |
89 | 0 | vlc_meta_Set( p_meta, vlc_meta_ArtworkURL, p_alloc ); |
90 | 0 | free( p_alloc ); |
91 | 0 | *pb_updated = true; |
92 | 0 | } |
93 | 0 | } |
94 | 0 | return true; |
95 | 0 | } |
96 | 0 | return false; |
97 | 0 | } Unexecuted instantiation: es.c:ID3LinkFrameTagHandler Unexecuted instantiation: meta.c:ID3LinkFrameTagHandler |
98 | | |
99 | | static bool ID3HandleTag( const uint8_t *p_buf, size_t i_buf, |
100 | | uint32_t i_tag, |
101 | | vlc_meta_t *p_meta, bool *pb_updated ) |
102 | 0 | { |
103 | 0 | if( i_tag == VLC_FOURCC('W', 'X', 'X', 'X') ) |
104 | 0 | { |
105 | 0 | return ID3LinkFrameTagHandler( p_buf, i_buf, p_meta, pb_updated ); |
106 | 0 | } |
107 | 0 | else if( i_tag == VLC_FOURCC('T', 'X', 'X', 'X') ) |
108 | 0 | { |
109 | 0 | char *psz_key_alloc; |
110 | 0 | const char *psz_key = ID3TextConvert( p_buf, i_buf, &psz_key_alloc ); |
111 | 0 | if( psz_key ) |
112 | 0 | { |
113 | 0 | const size_t i_len = strlen( psz_key ) + 2; |
114 | 0 | if( i_len < i_buf ) |
115 | 0 | { |
116 | | /* Only set those which are known as non binary */ |
117 | 0 | if( !strncasecmp( psz_key, "REPLAYGAIN_", 11 ) ) |
118 | 0 | { |
119 | 0 | char *psz_val_alloc; |
120 | 0 | const char *psz_val = ID3TextConv( &p_buf[i_len], i_buf - i_len, |
121 | 0 | p_buf[0], &psz_val_alloc ); |
122 | 0 | if( psz_val ) |
123 | 0 | { |
124 | 0 | vlc_meta_AddExtra( p_meta, psz_key, psz_val ); |
125 | 0 | free( psz_val_alloc ); |
126 | 0 | } |
127 | 0 | } |
128 | 0 | } |
129 | 0 | free( psz_key_alloc ); |
130 | 0 | return (vlc_meta_GetExtraCount( p_meta ) > 0); |
131 | 0 | } |
132 | 0 | } |
133 | 0 | else if ( ((const char *) &i_tag)[0] == 'T' ) |
134 | 0 | { |
135 | 0 | for( size_t i=0; i<ARRAY_SIZE(ID3_tag_to_metatype); i++ ) |
136 | 0 | { |
137 | 0 | if( ID3_tag_to_metatype[i].i_tag == i_tag ) |
138 | 0 | return ID3TextTagHandler( p_buf, i_buf, |
139 | 0 | ID3_tag_to_metatype[i].type, |
140 | 0 | ID3_tag_to_metatype[i].psz, |
141 | 0 | p_meta, pb_updated ); |
142 | 0 | } |
143 | 0 | } |
144 | | |
145 | 0 | return false; |
146 | 0 | } Unexecuted instantiation: es.c:ID3HandleTag Unexecuted instantiation: meta.c:ID3HandleTag |
147 | | |
148 | | #endif |