PASTEBIN
| #1 paste tool since 2002
create new paste
tools
api
archive
faq
PASTEBIN
create new paste
trending pastes
sign up
login
my alerts
my settings
my profile
Don't like ads?
PRO users
don't see any ads ;-)
Public Pastes
Untitled
1 sec ago
Untitled
6 sec ago
Untitled
7 sec ago
sources.list
18 sec ago
Untitled
9 sec ago
Untitled
11 sec ago
Untitled
3 min ago
Untitled
17 sec ago
Untitled
By: a guest on
May 11th, 2012
| syntax:
C
| size: 14.55 KB | hits: 20 | expires: Never
download
|
raw
|
embed
|
report abuse
|
print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
#include <stdio.h>
#include <stdlib.h>
/*
Orden de los campos en ID3v1:
Titulo (30)
Artista (30)
Album (30)
Año (4)
Compositor/Comentario (28)
Byte en cero (1)
Numero de pista (1)
Byte con genero (1)
Total: 125.
+ bytes 'T','A','G'
-------
128
*/
/*
Codigo de genero:
0 => 'Blues',
1 => 'Classic Rock',
2 => 'Country',
3 => 'Dance',
4 => 'Disco',
5 => 'Funk',
6 => 'Grunge',
7 => 'Hip-Hop',
8 => 'Jazz',
9 => 'Metal',
10 => 'New Age',
11 => 'Oldies',
12 => 'Other',
13 => 'Pop',
14 => 'R&B',
15 => 'Rap',
16 => 'Reggae',
17 => 'Rock',
18 => 'Techno',
19 => 'Industrial',
20 => 'Alternative',
21 => 'Ska',
22 => 'Death Metal',
23 => 'Pranks',
24 => 'Soundtrack',
25 => 'Euro-Techno',
26 => 'Ambient',
27 => 'Trip-Hop',
28 => 'Vocal',
29 => 'Jazz+Funk',
30 => 'Fusion',
31 => 'Trance',
32 => 'Classical',
33 => 'Instrumental',
34 => 'Acid',
35 => 'House',
36 => 'Game',
37 => 'Sound Clip',
38 => 'Gospel',
39 => 'Noise',
40 => 'Alt. Rock',
41 => 'Bass',
42 => 'Soul',
43 => 'Punk',
44 => 'Space',
45 => 'Meditative',
46 => 'Instrumental Pop',
47 => 'Instrumental Rock',
48 => 'Ethnic',
49 => 'Gothic',
50 => 'Darkwave',
51 => 'Techno-Industrial',
52 => 'Electronic',
53 => 'Pop-Folk',
54 => 'Eurodance',
55 => 'Dream',
56 => 'Southern Rock',
57 => 'Comedy',
58 => 'Cult',
59 => 'Gangsta Rap',
60 => 'Top 40',
61 => 'Christian Rap',
62 => 'Pop/Funk',
63 => 'Jungle',
64 => 'Native American',
65 => 'Cabaret',
66 => 'New Wave',
67 => 'Psychedelic',
68 => 'Rave',
69 => 'Showtunes',
70 => 'Trailer',
71 => 'Lo-Fi',
72 => 'Tribal',
73 => 'Acid Punk',
74 => 'Acid Jazz',
75 => 'Polka',
76 => 'Retro',
77 => 'Musical',
78 => 'Rock & Roll',
79 => 'Hard Rock',
80 => 'Folk',
81 => 'Folk/Rock',
82 => 'National Folk',
83 => 'Swing',
84 => 'Fast-Fusion',
85 => 'Bebob',
86 => 'Latin',
87 => 'Revival',
88 => 'Celtic',
89 => 'Bluegrass',
90 => 'Avantgarde',
91 => 'Gothic Rock',
92 => 'Progressive Rock',
93 => 'Psychedelic Rock',
94 => 'Symphonic Rock',
95 => 'Slow Rock',
96 => 'Big Band',
97 => 'Chorus',
98 => 'Easy Listening',
99 => 'Acoustic',
100 => 'Humour',
101 => 'Speech',
102 => 'Chanson',
103 => 'Opera',
104 => 'Chamber Music',
105 => 'Sonata',
106 => 'Symphony',
107 => 'Booty Bass',
108 => 'Primus',
109 => 'Porn Groove',
110 => 'Satire',
111 => 'Slow Jam',
112 => 'Club',
113 => 'Tango',
114 => 'Samba',
115 => 'Folklore',
116 => 'Ballad',
117 => 'Power Ballad',
118 => 'Rhythmic Soul',
119 => 'Freestyle',
120 => 'Duet',
121 => 'Punk Rock',
122 => 'Drum Solo',
123 => 'A Cappella',
124 => 'Euro-House',
125 => 'Dance Hall',
126 => 'Goa',
127 => 'Drum & Bass',
128 => 'Club-House',
129 => 'Hardcore',
130 => 'Terror',
131 => 'Indie',
132 => 'BritPop',
133 => 'Negerpunk',
134 => 'Polsk Punk',
135 => 'Beat',
136 => 'Christian Gangsta Rap',
137 => 'Heavy Metal',
138 => 'Black Metal',
139 => 'Crossover',
140 => 'Contemporary Christian',
141 => 'Christian Rock',
142 => 'Merengue',
143 => 'Salsa',
144 => 'Trash Metal',
145 => 'Anime',
146 => 'JPop',
147 => 'Synthpop',
255 => 'Unknown',
*/
/*publicar:*/
typedef
struct
tags_t
{
char
Titulo
[
30
]
;
char
Artista
[
30
]
;
char
Album
[
30
]
;
char
Year
[
4
]
;
char
compositor
[
28
]
;
char
Ubyte
;
char
NPista
;
unsigned
char
genero
;
}
tags_t
;
char
*
genres
[
149
]
=
{
"Blues"
,
"Classic Rock"
,
"Country"
,
"Dance"
,
"Disco"
,
"Funk"
,
"Grunge"
,
"Hip-Hop"
,
"Jazz"
,
"Metal"
,
"New Age"
,
"Oldies"
,
"Other"
,
"Pop"
,
"R&B"
,
"Rap"
,
"Reggae"
,
"Rock"
,
"Techno"
,
"Industrial"
,
"Alternative"
,
"Ska"
,
"Death Metal"
,
"Pranks"
,
"Soundtrack"
,
"Euro-Techno"
,
"Ambient"
,
"Trip-Hop"
,
"Vocal"
,
"Jazz+Funk"
,
"Fusion"
,
"Trance"
,
"Classical"
,
"Instrumental"
,
"Acid"
,
"House"
,
"Game"
,
"Sound Clip"
,
"Gospel"
,
"Noise"
,
"Alt. Rock"
,
"Bass"
,
"Soul"
,
"Punk"
,
"Space"
,
"Meditative"
,
"Instrumental Pop"
,
"Instrumental Rock"
,
"Ethnic"
,
"Gothic"
,
"Darkwave"
,
"Techno-Industrial"
,
"Electronic"
,
"Pop-Folk"
,
"Eurodance"
,
"Dream"
,
"Southern Rock"
,
"Comedy"
,
"Cult"
,
"Gangsta Rap"
,
"Top 40"
,
"Christian Rap"
,
"Pop/Funk"
,
"Jungle"
,
"Native American"
,
"Cabaret"
,
"New Wave"
,
"Psychedelic"
,
"Rave"
,
"Showtunes"
,
"Trailer"
,
"Lo-Fi"
,
"Tribal"
,
"Acid Punk"
,
"Acid Jazz"
,
"Polka"
,
"Retro"
,
"Musical"
,
"Rock & Roll"
,
"Hard Rock"
,
"Folk"
,
"Folk/Rock"
,
"National Folk"
,
"Swing"
,
"Fast-Fusion"
,
"Bebob"
,
"Latin"
,
"Revival"
,
"Celtic"
,
"Bluegrass"
,
"Avantgarde"
,
"Gothic Rock"
,
"Progressive Rock"
,
"Psychedelic Rock"
,
"Symphonic Rock"
,
"Slow Rock"
,
"Big Band"
,
"Chorus"
,
"Easy Listening"
,
"Acoustic"
,
"Humour"
,
"Speech"
,
"Chanson"
,
"Opera"
,
"Chamber Music"
,
"Sonata"
,
"Symphony"
,
"Booty Bass"
,
"Primus"
,
"Porn Groove"
,
"Satire"
,
"Slow Jam"
,
"Club"
,
"Tango"
,
"Samba"
,
"Folklore"
,
"Ballad"
,
"Power Ballad"
,
"Rhythmic Soul"
,
"Freestyle"
,
"Duet"
,
"Punk Rock"
,
"Drum Solo"
,
"A Cappella"
,
"Euro-House"
,
"Dance Hall"
,
"Goa"
,
"Drum & Bass"
,
"Club-House"
,
"Hardcore"
,
"Terror"
,
"Indie"
,
"BritPop"
,
"Negerpunk"
,
"Polsk Punk"
,
"Beat"
,
"Christian Gangsta Rap"
,
"Heavy Metal"
,
"Black Metal"
,
"Crossover"
,
"Contemporary Christian"
,
"Christian Rock"
,
"Merengue"
,
"Salsa"
,
"Trash Metal"
,
"Anime"
,
"JPop"
,
"Synthpop"
,
"Unknown"
}
;
/*funciones privadas:*/
void
todobien
(
)
{
printf
(
"**todo bien**
\n
"
)
;
}
int
caracterimprimible
(
char
c
)
{
return
(
c
<
32
||
c
>
126
)
?
0
:
1
;
}
int
length
(
char
*
a
,
int
max
)
{
int
n
=
0
;
while
(
caracterimprimible
(
a
[
n
]
)
&&
n
<
max
)
n
++;
return
n
;
}
int
same
(
char
*
a
,
char
*
b
)
{
int
i
;
for
(
i
=
0
;;
i
++
)
{
if
(
(
a
[
i
]
==
0
)
&&
(
(
b
[
i
]
==
0
)
)
)
return
1
;
if
(
(
a
[
i
]
==
0
)
||
(
(
b
[
i
]
==
0
)
)
||
a
[
i
]
!=
b
[
i
]
)
return
0
;
}
}
/*funciones publicas*/
char
quecodigo
(
char
*
cadena
)
{
int
i
;
for
(
i
=
0
;
i
<
148
;
i
++
)
{
if
(
same
(
cadena
,
genres
[
i
]
)
)
return
i
;
}
return
148
;
}
char
*
quegenero
(
unsigned
char
genero
)
{
if
(
genero
<
148
)
return
genres
[
genero
]
;
else
return
genres
[
148
]
;
}
/*funciones privadas:*/
void
imprimirtags
(
tags_t
*
tags
)
{
char
c
;
int
i
;
printf
(
"Artista: ["
)
;
for
(
i
=
0
;
caracterimprimible
(
c
=
tags
->
Artista
[
i
]
)
&&
i
<
30
;
i
++
)
putchar
(
c
)
;
printf
(
"]
\n
"
)
;
printf
(
"Titulo de la cancion: ["
)
;
for
(
i
=
0
;
caracterimprimible
(
c
=
tags
->
Titulo
[
i
]
)
&&
i
<
30
;
i
++
)
putchar
(
c
)
;
printf
(
"]
\n
"
)
;
printf
(
"Nombre del Album: ["
)
;
for
(
i
=
0
;
caracterimprimible
(
c
=
tags
->
Album
[
i
]
)
&&
i
<
30
;
i
++
)
putchar
(
c
)
;
printf
(
"]
\n
"
)
;
if
(
tags
->
Ubyte
==
0
)
printf
(
"# Pista: %i
\n
"
,
(
int
)
tags
->
NPista
)
;
else
printf
(
"# Pista: []
\n
"
)
;
printf
(
"A%co en que salio: ["
,
164
)
;
for
(
i
=
0
;
caracterimprimible
(
c
=
tags
->
Year
[
i
]
)
&&
i
<
4
;
i
++
)
putchar
(
c
)
;
printf
(
"]
\n
"
)
;
printf
(
"Compositor: ["
)
;
for
(
i
=
0
;
caracterimprimible
(
c
=
tags
->
compositor
[
i
]
)
&&
i
<
28
;
i
++
)
putchar
(
c
)
;
printf
(
"]
\n
"
)
;
printf
(
"Genero: [%s]
\n
"
,
quegenero
(
tags
->
genero
)
)
;
printf
(
"Cod de genero: 0x%X
\n
"
,
tags
->
genero
)
;
}
void
error
(
char
*
s
)
{
printf
(
"error: %s"
,
s
)
;
//perror(s);
exit
(
-
1
)
;
}
int
volcar
(
tags_t
*
store
,
FILE
*
archivo
)
{
int
longcadena
;
char
cero
[
30
]
=
{
}
;
fseek
(
archivo
,-
125
,
SEEK_END
)
;
longcadena
=
length
(
store
->
Titulo
,
30
)
;
if
(
longcadena
==
0
)
fseek
(
archivo
,
30
,
SEEK_CUR
)
;
else
{
if
(
fwrite
(
store
->
Titulo
,
1
,
longcadena
,
archivo
)
<=
0
)
error
(
"fwritetitulo1"
)
;
if
(
longcadena
!=
30
)
if
(
fwrite
(
&
cero
,
1
,
30
-
longcadena
,
archivo
)
<=
0
)
error
(
"fwritetitulo2"
)
;
//fflush(archivo);
}
longcadena
=
length
(
store
->
Artista
,
30
)
;
if
(
longcadena
==
0
)
fseek
(
archivo
,
30
,
SEEK_CUR
)
;
else
{
if
(
fwrite
(
store
->
Artista
,
1
,
longcadena
,
archivo
)
<=
0
)
error
(
"fwriteartista1"
)
;
if
(
longcadena
!=
30
)
if
(
fwrite
(
&
cero
,
1
,
30
-
longcadena
,
archivo
)
<=
0
)
error
(
"fwriteartista2"
)
;
//fflush(archivo);
}
longcadena
=
length
(
store
->
Album
,
30
)
;
if
(
longcadena
==
0
)
fseek
(
archivo
,
30
,
SEEK_CUR
)
;
else
{
if
(
fwrite
(
store
->
Album
,
1
,
longcadena
,
archivo
)
<=
0
)
error
(
"fwritealbum1"
)
;
if
(
longcadena
!=
30
)
if
(
fwrite
(
&
cero
,
1
,
30
-
longcadena
,
archivo
)
<=
0
)
error
(
"fwritealbum2"
)
;
//fflush(archivo);
}
longcadena
=
length
(
store
->
Year
,
4
)
;
if
(
longcadena
==
0
)
fseek
(
archivo
,
4
,
SEEK_CUR
)
;
else
{
if
(
fwrite
(
store
->
Year
,
1
,
longcadena
,
archivo
)
<=
0
)
error
(
"fwriteyear1"
)
;
if
(
longcadena
!=
4
)
if
(
fwrite
(
&
cero
,
1
,
4
-
longcadena
,
archivo
)
<=
0
)
error
(
"fwriteyear2"
)
;
//fflush(archivo);
}
longcadena
=
length
(
store
->
compositor
,
28
)
;
if
(
longcadena
==
0
)
fseek
(
archivo
,
28
,
SEEK_CUR
)
;
else
{
if
(
fwrite
(
store
->
compositor
,
1
,
longcadena
,
archivo
)
<=
0
)
error
(
"fwrite1compositor"
)
;
if
(
longcadena
!=
28
)
if
(
fwrite
(
&
cero
,
1
,
28
-
longcadena
,
archivo
)
<=
0
)
error
(
"fwritecompositor2"
)
;
//fflush(archivo);
}
fputc
(
store
->
Ubyte
,
archivo
)
;
if
(
store
->
NPista
==
0
)
fseek
(
archivo
,
1
,
SEEK_CUR
)
;
else
fputc
(
store
->
NPista
,
archivo
)
;
if
(
store
->
genero
==
0
)
fseek
(
archivo
,
1
,
SEEK_CUR
)
;
else
fputc
(
store
->
genero
,
archivo
)
;
return
0
;
}
int
volcar2
(
tags_t
*
store
,
FILE
*
archivo
)
{
int
longcadena
;
char
cero
[
30
]
=
{
}
,
tag
[
3
]
=
{
'T'
,
'A'
,
'G'
}
;
fseek
(
archivo
,
0
,
SEEK_END
)
;
if
(
fwrite
(
tag
,
1
,
3
,
archivo
)
<=
0
)
error
(
"fwriteTAG"
)
;
longcadena
=
length
(
store
->
Titulo
,
30
)
;
if
(
longcadena
!=
0
)
if
(
fwrite
(
store
->
Titulo
,
1
,
longcadena
,
archivo
)
<=
0
)
error
(
"fwritetitulo1"
)
;
if
(
longcadena
!=
30
)
if
(
fwrite
(
&
cero
,
1
,
30
-
longcadena
,
archivo
)
<=
0
)
error
(
"fwritetitulo2"
)
;
//fflush(archivo);
longcadena
=
length
(
store
->
Artista
,
30
)
;
if
(
longcadena
!=
0
)
if
(
fwrite
(
store
->
Artista
,
1
,
longcadena
,
archivo
)
<=
0
)
error
(
"fwriteartista1"
)
;
if
(
longcadena
!=
30
)
if
(
fwrite
(
&
cero
,
1
,
30
-
longcadena
,
archivo
)
<=
0
)
error
(
"fwriteartista2"
)
;
//fflush(archivo);
longcadena
=
length
(
store
->
Album
,
30
)
;
if
(
longcadena
!=
0
)
if
(
fwrite
(
store
->
Album
,
1
,
longcadena
,
archivo
)
<=
0
)
error
(
"fwritealbum1"
)
;
if
(
longcadena
!=
30
)
if
(
fwrite
(
&
cero
,
1
,
30
-
longcadena
,
archivo
)
<=
0
)
error
(
"fwritealbum2"
)
;
//fflush(archivo);
longcadena
=
length
(
store
->
Year
,
4
)
;
if
(
longcadena
!=
0
)
if
(
fwrite
(
store
->
Year
,
1
,
longcadena
,
archivo
)
<=
0
)
error
(
"fwriteyear1"
)
;
if
(
longcadena
!=
4
)
if
(
fwrite
(
&
cero
,
1
,
4
-
longcadena
,
archivo
)
<=
0
)
error
(
"fwriteyear2"
)
;
//fflush(archivo);
longcadena
=
length
(
store
->
compositor
,
28
)
;
if
(
longcadena
!=
0
)
if
(
fwrite
(
store
->
compositor
,
1
,
longcadena
,
archivo
)
<=
0
)
error
(
"fwritecompositor1"
)
;
if
(
longcadena
!=
28
)
if
(
fwrite
(
&
cero
,
1
,
28
-
longcadena
,
archivo
)
<=
0
)
error
(
"fwritecompositor2"
)
;
//fflush(archivo);
fputc
(
store
->
Ubyte
,
archivo
)
;
fputc
(
store
->
NPista
,
archivo
)
;
fputc
(
store
->
genero
,
archivo
)
;
return
0
;
}
/*funcion writeTAGS (to file)*/
int
writeTAGS
(
tags_t
*
store
,
FILE
*
archivo
)
{
char
buf
[
3
]
,
tienetags
=
1
;
fseek
(
archivo
,
-
128
,
SEEK_END
)
;
fread
(
buf
,
1
,
3
,
archivo
)
;
if
(
buf
[
0
]
!=
'T'
||
buf
[
1
]
!=
'A'
||
buf
[
2
]
!=
'G'
)
tienetags
=
0
;
if
(
tienetags
)
{
if
(
volcar
(
store
,
archivo
)
<
0
)
return
-
1
;
}
else
if
(
volcar2
(
store
,
archivo
)
<
0
)
return
-
1
;
return
0
;
}
/*Escritura de los tags*/
int
writeartist
(
tags_t
*
store
,
char
*
cadena
)
{
int
i
,
j
;
for
(
i
=
0
;
i
<
30
&&
cadena
[
i
]
!=
0
;
i
++
)
store
->
Artista
[
i
]
=
cadena
[
i
]
;
for
(
j
=
i
;
j
<
(
30
-
i
)
;
j
++
)
store
->
Artista
[
j
]
=
0
;
return
0
;
}
int
writetitle
(
tags_t
*
store
,
char
*
cadena
)
{
int
i
,
j
;
for
(
i
=
0
;
i
<
30
&&
cadena
[
i
]
!=
0
;
i
++
)
store
->
Titulo
[
i
]
=
cadena
[
i
]
;
for
(
j
=
i
;
j
<
(
30
-
i
)
;
j
++
)
store
->
Titulo
[
j
]
=
0
;
return
0
;
}
int
writealbum
(
tags_t
*
store
,
char
*
cadena
)
{
int
i
,
j
;
for
(
i
=
0
;
i
<
30
&&
cadena
[
i
]
!=
0
;
i
++
)
store
->
Album
[
i
]
=
cadena
[
i
]
;
for
(
j
=
i
;
j
<
(
30
-
i
)
;
j
++
)
store
->
Album
[
j
]
=
0
;
return
0
;
}
int
writeyear
(
tags_t
*
store
,
char
*
cadena
)
{
int
i
,
j
;
for
(
i
=
0
;
i
<
4
&&
cadena
[
i
]
!=
0
;
i
++
)
store
->
Year
[
i
]
=
cadena
[
i
]
;
for
(
j
=
i
;
j
<
(
4
-
i
)
;
j
++
)
store
->
Year
[
j
]
=
0
;
return
0
;
}
int
writecoment
(
tags_t
*
store
,
char
*
cadena
)
{
int
i
,
j
;
for
(
i
=
0
;
i
<
28
&&
cadena
[
i
]
!=
0
;
i
++
)
store
->
compositor
[
i
]
=
cadena
[
i
]
;
for
(
j
=
i
;
j
<
(
28
-
i
)
;
j
++
)
store
->
compositor
[
j
]
=
0
;
return
0
;
}
int
writegenre
(
tags_t
*
store
,
char
cadena
)
{
store
->
genero
=
cadena
;
return
0
;
}
int
writetrack
(
tags_t
*
store
,
char
cadena
)
{
store
->
Ubyte
=
0
;
store
->
NPista
=
cadena
;
return
0
;
}
/* Lectura de los tags*/
int
readartist
(
tags_t
*
store
,
char
*
cadena
)
{
int
i
,
j
;
for
(
i
=
0
;
i
<
30
&&
caracterimprimible
(
store
->
Artista
[
i
]
)
;
i
++
)
cadena
[
i
]
=
store
->
Artista
[
i
]
;
for
(
j
=
i
;
j
<
(
31
-
i
)
;
j
++
)
cadena
[
i
]
=
0
;
return
0
;
}
int
readtitle
(
tags_t
*
store
,
char
*
cadena
)
{
int
i
,
j
;
for
(
i
=
0
;
i
<
30
&&
caracterimprimible
(
store
->
Titulo
[
i
]
)
;
i
++
)
cadena
[
i
]
=
store
->
Titulo
[
i
]
;
for
(
j
=
i
;
j
<
(
31
-
i
)
;
j
++
)
cadena
[
i
]
=
0
;
return
0
;
}
int
readalbum
(
tags_t
*
store
,
char
*
cadena
)
{
int
i
,
j
;
for
(
i
=
0
;
i
<
30
&&
caracterimprimible
(
store
->
Album
[
i
]
)
;
i
++
)
cadena
[
i
]
=
store
->
Album
[
i
]
;
for
(
j
=
i
;
j
<
(
31
-
i
)
;
j
++
)
cadena
[
i
]
=
0
;
return
0
;
}
int
readyear
(
tags_t
*
store
,
char
*
cadena
)
{
int
i
,
j
;
for
(
i
=
0
;
i
<
4
&&
caracterimprimible
(
store
->
Year
[
i
]
)
;
i
++
)
cadena
[
i
]
=
store
->
Year
[
i
]
;
for
(
j
=
i
;
j
<
(
5
-
i
)
;
j
++
)
cadena
[
i
]
=
0
;
return
0
;
}
int
readcoment
(
tags_t
*
store
,
char
*
cadena
)
{
int
i
,
j
;
for
(
i
=
0
;
i
<
28
&&
caracterimprimible
(
store
->
compositor
[
i
]
)
;
i
++
)
cadena
[
i
]
=
store
->
compositor
[
i
]
;
for
(
j
=
i
;
j
<
(
2
+-
i
)
;
j
++
)
cadena
[
i
]
=
0
;
return
0
;
}
int
readgenre
(
tags_t
*
store
,
char
*
c
)
{
*
c
=
store
->
genero
;
return
0
;
}
int
readtrack
(
tags_t
*
store
,
char
*
c
)
{
if
(
store
->
Ubyte
!=
0
)
*
c
=
store
->
NPista
;
else
*
c
=-
1
;
return
0
;
}
/*funcion readtags (from file)*/
int
readTAGS
(
tags_t
*
store
,
FILE
*
archivo
)
{
char
buf
[
3
]
;
fseek
(
archivo
,
-
128
,
SEEK_END
)
;
fread
(
buf
,
1
,
3
,
archivo
)
;
if
(
buf
[
0
]
!=
'T'
||
buf
[
1
]
!=
'A'
||
buf
[
2
]
!=
'G'
)
return
-
1
;
fread
(
store
,
1
,
125
,
archivo
)
;
return
0
;
}
/*
int eliminarTAGS(FILE *archivo)
{
char buf[3];
fseek(archivo, -128, SEEK_END);
fread(buf, 1, 3, archivo);
if (buf[0]!='T' || buf[1]!='A' || buf[2]!='G')
return -1;
return 0;
}*/
int
main
(
int
argc
,
char
**
argv
)
{
FILE
*
archivo
,
*
archivo2
;
int
a
;
char
*
filename
=
"aa.mp3"
,
path2
;
char
artista
[
1024
]
;
tags_t
*
tags
;
tags
=
malloc
(
sizeof
(
tags_t
)
)
;
if
(
(
archivo
=
fopen
(
filename
,
"rb+"
)
)
==
NULL
)
error
(
"fopen"
)
;
readTAGS
(
tags
,
archivo
)
;
imprimirtags
(
tags
)
;
readtitle
(
tags
,
artista
)
;
printf
(
"
\n
titulo:{%s}
\n
"
,
artista
)
;
if
(
(
a
=
fclose
(
archivo
)
)
!=
0
)
error
(
"fclose"
)
;
return
0
;
}
create a
new version
of this paste
RAW Paste Data
#include <stdio.h> #include <stdlib.h> /* Orden de los campos en ID3v1: Titulo (30) Artista (30) Album (30) Año (4) Compositor/Comentario (28) Byte en cero (1) Numero de pista (1) Byte con genero (1) Total: 125. + bytes 'T','A','G' ------- 128 */ /* Codigo de genero: 0 => 'Blues', 1 => 'Classic Rock', 2 => 'Country', 3 => 'Dance', 4 => 'Disco', 5 => 'Funk', 6 => 'Grunge', 7 => 'Hip-Hop', 8 => 'Jazz', 9 => 'Metal', 10 => 'New Age', 11 => 'Oldies', 12 => 'Other', 13 => 'Pop', 14 => 'R&B', 15 => 'Rap', 16 => 'Reggae', 17 => 'Rock', 18 => 'Techno', 19 => 'Industrial', 20 => 'Alternative', 21 => 'Ska', 22 => 'Death Metal', 23 => 'Pranks', 24 => 'Soundtrack', 25 => 'Euro-Techno', 26 => 'Ambient', 27 => 'Trip-Hop', 28 => 'Vocal', 29 => 'Jazz+Funk', 30 => 'Fusion', 31 => 'Trance', 32 => 'Classical', 33 => 'Instrumental', 34 => 'Acid', 35 => 'House', 36 => 'Game', 37 => 'Sound Clip', 38 => 'Gospel', 39 => 'Noise', 40 => 'Alt. Rock', 41 => 'Bass', 42 => 'Soul', 43 => 'Punk', 44 => 'Space', 45 => 'Meditative', 46 => 'Instrumental Pop', 47 => 'Instrumental Rock', 48 => 'Ethnic', 49 => 'Gothic', 50 => 'Darkwave', 51 => 'Techno-Industrial', 52 => 'Electronic', 53 => 'Pop-Folk', 54 => 'Eurodance', 55 => 'Dream', 56 => 'Southern Rock', 57 => 'Comedy', 58 => 'Cult', 59 => 'Gangsta Rap', 60 => 'Top 40', 61 => 'Christian Rap', 62 => 'Pop/Funk', 63 => 'Jungle', 64 => 'Native American', 65 => 'Cabaret', 66 => 'New Wave', 67 => 'Psychedelic', 68 => 'Rave', 69 => 'Showtunes', 70 => 'Trailer', 71 => 'Lo-Fi', 72 => 'Tribal', 73 => 'Acid Punk', 74 => 'Acid Jazz', 75 => 'Polka', 76 => 'Retro', 77 => 'Musical', 78 => 'Rock & Roll', 79 => 'Hard Rock', 80 => 'Folk', 81 => 'Folk/Rock', 82 => 'National Folk', 83 => 'Swing', 84 => 'Fast-Fusion', 85 => 'Bebob', 86 => 'Latin', 87 => 'Revival', 88 => 'Celtic', 89 => 'Bluegrass', 90 => 'Avantgarde', 91 => 'Gothic Rock', 92 => 'Progressive Rock', 93 => 'Psychedelic Rock', 94 => 'Symphonic Rock', 95 => 'Slow Rock', 96 => 'Big Band', 97 => 'Chorus', 98 => 'Easy Listening', 99 => 'Acoustic', 100 => 'Humour', 101 => 'Speech', 102 => 'Chanson', 103 => 'Opera', 104 => 'Chamber Music', 105 => 'Sonata', 106 => 'Symphony', 107 => 'Booty Bass', 108 => 'Primus', 109 => 'Porn Groove', 110 => 'Satire', 111 => 'Slow Jam', 112 => 'Club', 113 => 'Tango', 114 => 'Samba', 115 => 'Folklore', 116 => 'Ballad', 117 => 'Power Ballad', 118 => 'Rhythmic Soul', 119 => 'Freestyle', 120 => 'Duet', 121 => 'Punk Rock', 122 => 'Drum Solo', 123 => 'A Cappella', 124 => 'Euro-House', 125 => 'Dance Hall', 126 => 'Goa', 127 => 'Drum & Bass', 128 => 'Club-House', 129 => 'Hardcore', 130 => 'Terror', 131 => 'Indie', 132 => 'BritPop', 133 => 'Negerpunk', 134 => 'Polsk Punk', 135 => 'Beat', 136 => 'Christian Gangsta Rap', 137 => 'Heavy Metal', 138 => 'Black Metal', 139 => 'Crossover', 140 => 'Contemporary Christian', 141 => 'Christian Rock', 142 => 'Merengue', 143 => 'Salsa', 144 => 'Trash Metal', 145 => 'Anime', 146 => 'JPop', 147 => 'Synthpop', 255 => 'Unknown', */ /*publicar:*/ typedef struct tags_t{ char Titulo[30]; char Artista[30]; char Album[30]; char Year[4]; char compositor[28]; char Ubyte; char NPista; unsigned char genero; } tags_t; char* genres[149] = {"Blues","Classic Rock","Country","Dance","Disco","Funk","Grunge","Hip-Hop","Jazz","Metal","New Age","Oldies","Other","Pop","R&B","Rap","Reggae","Rock","Techno","Industrial","Alternative","Ska","Death Metal","Pranks","Soundtrack","Euro-Techno","Ambient","Trip-Hop","Vocal","Jazz+Funk","Fusion","Trance","Classical","Instrumental","Acid","House","Game","Sound Clip","Gospel","Noise","Alt. Rock","Bass","Soul","Punk","Space","Meditative","Instrumental Pop","Instrumental Rock","Ethnic","Gothic","Darkwave","Techno-Industrial","Electronic","Pop-Folk","Eurodance","Dream","Southern Rock","Comedy","Cult","Gangsta Rap","Top 40","Christian Rap","Pop/Funk","Jungle","Native American","Cabaret","New Wave","Psychedelic","Rave","Showtunes","Trailer","Lo-Fi","Tribal","Acid Punk","Acid Jazz","Polka","Retro","Musical","Rock & Roll","Hard Rock","Folk","Folk/Rock","National Folk","Swing","Fast-Fusion","Bebob","Latin","Revival","Celtic","Bluegrass","Avantgarde","Gothic Rock","Progressive Rock","Psychedelic Rock","Symphonic Rock","Slow Rock","Big Band","Chorus","Easy Listening","Acoustic","Humour","Speech","Chanson","Opera","Chamber Music","Sonata","Symphony","Booty Bass","Primus","Porn Groove","Satire","Slow Jam","Club","Tango","Samba","Folklore","Ballad","Power Ballad","Rhythmic Soul","Freestyle","Duet","Punk Rock","Drum Solo","A Cappella","Euro-House","Dance Hall","Goa","Drum & Bass","Club-House","Hardcore","Terror","Indie","BritPop","Negerpunk","Polsk Punk","Beat","Christian Gangsta Rap","Heavy Metal","Black Metal","Crossover","Contemporary Christian","Christian Rock","Merengue","Salsa","Trash Metal","Anime","JPop","Synthpop","Unknown"}; /*funciones privadas:*/ void todobien() { printf("**todo bien**\n"); } int caracterimprimible(char c) { return (c<32 || c>126)?0:1; } int length(char* a, int max) { int n=0; while (caracterimprimible(a[n]) && n<max) n++; return n; } int same(char* a, char* b) { int i; for (i=0;;i++) { if ((a[i]==0) && ((b[i]==0))) return 1; if ((a[i]==0) || ((b[i]==0)) || a[i]!=b[i]) return 0; } } /*funciones publicas*/ char quecodigo(char* cadena) { int i; for(i=0;i<148;i++) { if (same(cadena,genres[i])) return i; } return 148; } char* quegenero(unsigned char genero) { if (genero<148) return genres[genero]; else return genres[148]; } /*funciones privadas:*/ void imprimirtags(tags_t *tags) { char c; int i; printf("Artista: ["); for(i=0;caracterimprimible(c=tags->Artista[i])&&i<30;i++) putchar(c); printf("]\n"); printf("Titulo de la cancion: ["); for(i=0;caracterimprimible(c=tags->Titulo[i])&&i<30;i++) putchar(c); printf("]\n"); printf("Nombre del Album: ["); for(i=0;caracterimprimible(c=tags->Album[i])&&i<30;i++) putchar(c); printf("]\n"); if (tags->Ubyte==0) printf("# Pista: %i\n",(int) tags->NPista); else printf("# Pista: []\n"); printf("A%co en que salio: [",164); for(i=0;caracterimprimible(c=tags->Year[i])&&i<4;i++) putchar(c); printf("]\n"); printf("Compositor: ["); for(i=0;caracterimprimible(c=tags->compositor[i])&&i<28;i++) putchar(c); printf("]\n"); printf("Genero: [%s]\n",quegenero(tags->genero)); printf("Cod de genero: 0x%X\n",tags->genero); } void error(char *s) { printf("error: %s",s); //perror(s); exit(-1); } int volcar(tags_t *store, FILE *archivo) { int longcadena; char cero[30]={}; fseek(archivo,-125,SEEK_END); longcadena=length(store->Titulo,30); if (longcadena==0) fseek(archivo,30,SEEK_CUR); else { if(fwrite(store->Titulo, 1, longcadena, archivo)<=0) error("fwritetitulo1"); if (longcadena!=30) if(fwrite(&cero, 1, 30-longcadena, archivo)<=0) error("fwritetitulo2"); //fflush(archivo); } longcadena=length(store->Artista, 30); if (longcadena==0) fseek(archivo,30,SEEK_CUR); else { if(fwrite(store->Artista, 1, longcadena, archivo)<=0) error("fwriteartista1"); if (longcadena!=30) if(fwrite(&cero, 1, 30-longcadena, archivo)<=0) error("fwriteartista2"); //fflush(archivo); } longcadena=length(store->Album, 30); if (longcadena==0) fseek(archivo,30,SEEK_CUR); else { if(fwrite(store->Album, 1, longcadena, archivo)<=0) error("fwritealbum1"); if (longcadena!=30) if(fwrite(&cero, 1, 30-longcadena, archivo)<=0) error("fwritealbum2"); //fflush(archivo); } longcadena=length(store->Year, 4); if (longcadena==0) fseek(archivo,4,SEEK_CUR); else { if(fwrite(store->Year, 1, longcadena, archivo)<=0) error("fwriteyear1"); if (longcadena!=4) if(fwrite(&cero, 1, 4-longcadena, archivo)<=0) error("fwriteyear2"); //fflush(archivo); } longcadena=length(store->compositor, 28); if (longcadena==0) fseek(archivo,28,SEEK_CUR); else { if(fwrite(store->compositor, 1, longcadena, archivo)<=0) error("fwrite1compositor"); if (longcadena!=28) if(fwrite(&cero, 1, 28-longcadena, archivo)<=0) error("fwritecompositor2"); //fflush(archivo); } fputc(store->Ubyte,archivo); if (store->NPista==0) fseek(archivo,1,SEEK_CUR); else fputc(store->NPista,archivo); if (store->genero==0) fseek(archivo,1,SEEK_CUR); else fputc(store->genero,archivo); return 0; } int volcar2(tags_t *store, FILE *archivo) { int longcadena; char cero[30]={}, tag[3]={'T','A','G'}; fseek(archivo,0, SEEK_END); if(fwrite(tag,1,3,archivo)<=0) error("fwriteTAG"); longcadena=length(store->Titulo, 30); if (longcadena!=0) if(fwrite(store->Titulo, 1, longcadena, archivo)<=0) error("fwritetitulo1"); if (longcadena!=30) if(fwrite(&cero, 1, 30-longcadena, archivo)<=0) error("fwritetitulo2"); //fflush(archivo); longcadena=length(store->Artista, 30); if (longcadena!=0) if(fwrite(store->Artista, 1, longcadena, archivo)<=0) error("fwriteartista1"); if (longcadena!=30) if(fwrite(&cero, 1, 30-longcadena, archivo)<=0) error("fwriteartista2"); //fflush(archivo); longcadena=length(store->Album, 30); if (longcadena!=0) if(fwrite(store->Album, 1, longcadena, archivo)<=0) error("fwritealbum1"); if (longcadena!=30) if(fwrite(&cero, 1, 30-longcadena, archivo)<=0) error("fwritealbum2"); //fflush(archivo); longcadena=length(store->Year, 4); if (longcadena!=0) if(fwrite(store->Year, 1, longcadena, archivo)<=0) error("fwriteyear1"); if (longcadena!=4) if(fwrite(&cero, 1, 4-longcadena, archivo)<=0) error("fwriteyear2"); //fflush(archivo); longcadena=length(store->compositor, 28); if (longcadena!=0) if(fwrite(store->compositor, 1, longcadena, archivo)<=0) error("fwritecompositor1"); if (longcadena!=28) if(fwrite(&cero, 1, 28-longcadena, archivo)<=0) error("fwritecompositor2"); //fflush(archivo); fputc(store->Ubyte,archivo); fputc(store->NPista,archivo); fputc(store->genero,archivo); return 0; } /*funcion writeTAGS (to file)*/ int writeTAGS(tags_t *store, FILE *archivo) { char buf[3], tienetags=1; fseek(archivo, -128, SEEK_END); fread(buf, 1, 3, archivo); if (buf[0]!='T' || buf[1]!='A' || buf[2]!='G') tienetags=0; if (tienetags) { if(volcar(store, archivo)<0) return -1; } else if(volcar2(store,archivo)<0) return -1; return 0; } /*Escritura de los tags*/ int writeartist(tags_t *store, char *cadena) { int i, j; for(i=0; i<30 && cadena[i]!=0;i++ ) store->Artista[i]=cadena[i]; for(j=i;j<(30-i);j++) store->Artista[j]=0; return 0; } int writetitle(tags_t *store, char *cadena) { int i, j; for(i=0; i<30 && cadena[i]!=0;i++ ) store->Titulo[i]=cadena[i]; for(j=i;j<(30-i);j++) store->Titulo[j]=0; return 0; } int writealbum(tags_t *store, char *cadena) { int i, j; for(i=0; i<30 && cadena[i]!=0;i++ ) store->Album[i]=cadena[i]; for(j=i;j<(30-i);j++) store->Album[j]=0; return 0; } int writeyear(tags_t *store, char *cadena) { int i, j; for(i=0; i<4 && cadena[i]!=0;i++ ) store->Year[i]=cadena[i]; for(j=i;j<(4-i);j++) store->Year[j]=0; return 0; } int writecoment(tags_t *store, char *cadena) { int i, j; for(i=0; i<28 && cadena[i]!=0;i++ ) store->compositor[i]=cadena[i]; for(j=i;j<(28-i);j++) store->compositor[j]=0; return 0; } int writegenre(tags_t *store, char cadena) { store->genero=cadena; return 0; } int writetrack(tags_t *store, char cadena) { store->Ubyte=0; store->NPista=cadena; return 0; } /* Lectura de los tags*/ int readartist(tags_t *store, char *cadena) { int i, j; for(i=0; i<30 && caracterimprimible(store->Artista[i]);i++ ) cadena[i]=store->Artista[i]; for(j=i;j<(31-i);j++) cadena[i]=0; return 0; } int readtitle(tags_t *store, char *cadena) { int i, j; for(i=0; i<30 && caracterimprimible(store->Titulo[i]);i++ ) cadena[i]=store->Titulo[i]; for(j=i;j<(31-i);j++) cadena[i]=0; return 0; } int readalbum(tags_t *store, char *cadena) { int i, j; for(i=0; i<30 && caracterimprimible(store->Album[i]);i++ ) cadena[i]=store->Album[i]; for(j=i;j<(31-i);j++) cadena[i]=0; return 0; } int readyear(tags_t *store, char *cadena) { int i, j; for(i=0; i<4 && caracterimprimible(store->Year[i]);i++ ) cadena[i]=store->Year[i]; for(j=i;j<(5-i);j++) cadena[i]=0; return 0; } int readcoment(tags_t *store, char *cadena) { int i, j; for(i=0; i<28 && caracterimprimible(store->compositor[i]);i++ ) cadena[i]=store->compositor[i]; for(j=i;j<(2+-i);j++) cadena[i]=0; return 0; } int readgenre(tags_t *store, char *c) { *c=store->genero; return 0; } int readtrack(tags_t *store, char *c) { if (store->Ubyte!=0) *c=store->NPista; else *c=-1; return 0; } /*funcion readtags (from file)*/ int readTAGS(tags_t *store, FILE *archivo) { char buf[3]; fseek(archivo, -128, SEEK_END); fread(buf, 1, 3, archivo); if (buf[0]!='T' || buf[1]!='A' || buf[2]!='G') return -1; fread(store, 1, 125, archivo); return 0; } /* int eliminarTAGS(FILE *archivo) { char buf[3]; fseek(archivo, -128, SEEK_END); fread(buf, 1, 3, archivo); if (buf[0]!='T' || buf[1]!='A' || buf[2]!='G') return -1; return 0; }*/ int main(int argc, char** argv) { FILE *archivo, *archivo2; int a; char* filename="aa.mp3", path2; char artista[1024]; tags_t *tags; tags = malloc(sizeof(tags_t)); if ((archivo = fopen(filename,"rb+"))==NULL) error("fopen"); readTAGS(tags, archivo); imprimirtags(tags); readtitle(tags, artista); printf("\n titulo:{%s}\n", artista); if((a=fclose(archivo))!=0) error("fclose"); return 0; }