-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.c
195 lines (166 loc) · 4.62 KB
/
view.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include<stdio.h>
#include<string.h>
#include"view.h"
#include "types.h"
Status read_validate_argu(char *argv[],mp3Details *tagReader)
{
if(argv[2]==NULL)
{
return e_failure;
}
if(strstr(argv[2],".mp3")==NULL)
{
return e_failure;
}
strcpy(tagReader->mp3fname,argv[2]);
// printf("%s",tagReader->mp3fname);
}
Status f_open(mp3Details *tagReader)
{
tagReader->fptr_mp3=fopen(tagReader->mp3fname,"r" );
if (tagReader->fptr_mp3 == NULL)
{
perror("fopen");
fprintf(stderr,"ERROR: unable to open the file %s\n",tagReader->mp3fname);
return e_failure;
}
return e_success;
}
Status check_id3(mp3Details *tagReader)
{
char buffer[4];
fseek(tagReader->fptr_mp3,0,SEEK_SET);
fread(buffer,3,1,tagReader->fptr_mp3);
buffer[3]='\0';
if(strcmp(buffer,"ID3")!=0)
return e_failure;
char ch;
fread(&ch,1,1,tagReader->fptr_mp3);
if(ch!=0x03)
{
return e_failure;
}
}
Status view_validation(char *argv[],mp3Details *tagReader)
{
if(read_validate_argu(argv,tagReader)==e_failure)
{
printf("Validation of CML arguments is unsuccessful\n");
return e_failure;
}
if(f_open(tagReader)==e_failure)
{
printf("Opening a mp3failure is unsuccessful\n");
return e_failure;
}
if(check_id3(tagReader)==e_failure)
{
printf("ID3 tag or version is not matching\n");
return e_failure;
}
}
char read_size(mp3Details *tagReader,int *num)
{
fseek(tagReader->fptr_mp3,3,SEEK_CUR);
unsigned char ch;
fread(&ch,1,1,tagReader->fptr_mp3);
/* int base=1;
for(int i=0;i<8;i++)
{
*num = *num+(ch&(1<<i));
}
*/
fseek(tagReader->fptr_mp3,2,SEEK_CUR);
return ch;
}
Status tag_reader(mp3Details *tagReader)
{
int num=0;
char info[258];
char arr[6][5]={"TPE1","TIT2","TALB","TYER","TCON","COMM"};
char buffer[5];
fread(buffer,4,1,tagReader->fptr_mp3);
buffer[4]='\0';
// printf("%s\n",buffer);
for(int i=0;i<6;i++)
{
if(strcmp(buffer,arr[i])==0)
{
switch (i)
{
case 0:
num=read_size(tagReader,&num);
fread(info,num,1,tagReader->fptr_mp3);
printf("Artist Name : ");
for(int i=0;i<num;i++)
printf("%c",info[i]);
printf("\n");
printf("\n");
break;
case 1:
num=read_size(tagReader,&num);
fread(info,num,1,tagReader->fptr_mp3);
printf("Song Title : ");
for(int i=0;i<num;i++)
printf("%c",info[i]);
printf("\n");
printf("\n");
break;
case 2:
num= read_size(tagReader,&num);
fread(info,num,1,tagReader->fptr_mp3);
printf("Album : ");
for(int i=0;i<num;i++)
printf("%c",info[i]);
printf("\n");
printf("\n");
break;
case 3:
num= read_size(tagReader,&num);
fread(info,num,1,tagReader->fptr_mp3);
printf("Year : ");
for(int i=0;i<num;i++)
printf("%c",info[i]);
printf("\n");
printf("\n");
break;
case 4:
num= read_size(tagReader,&num);
fread(info,num,1,tagReader->fptr_mp3);
printf("Content type : ");
for(int i=0;i<num;i++)
printf("%c",info[i]);
printf("\n");
printf("\n");
break;
case 5:
num= read_size(tagReader,&num);
fread(info,num,1,tagReader->fptr_mp3);
printf("Comments : ");
for(int i=0;i<num;i++)
printf("%c",info[i]);
printf("\n");
printf("\n");
break;
}
break;
}
}
}
Status view(mp3Details *tagReader)
{
fseek(tagReader->fptr_mp3,10,SEEK_SET);
printf("---------------------------------------------===========--------------------------------------------------\n");
printf("---------------------------------------------MP3 DETAILS--------------------------------------------------\n");
printf("---------------------------------------------===========--------------------------------------------------\n");
printf("\n");
printf("-----------------------------------\n");
printf("MP3 TAG READER AND EDITOR FOR ID3V2 \n");
printf("-----------------------------------\n");
printf("\n");
for(int i=0;i<6;i++)
tag_reader(tagReader);
printf("--------------------------------------==============================--------------------------------------\n");
printf("--------------------------------------Details Displayed Successfully--------------------------------------\n");
printf("--------------------------------------==============================--------------------------------------\n");
}