1 --- mp3rename-0.6/mp3rename.c
2 +++ mp3rename-0.6/mp3rename.c 2007-05-17 05:20:02.000000000 +0200
5 void buildtag(char *buf, char *title, char *artist, char *album, char *year, char *comment, char *genre);
6 void set_filename(int argc,char *argv[]);
7 +void rtrim(char* astring);
9 int main(int argc, char *argv[])
12 - int verbose = 0, forced = 0, burn = 0, info = 0, all = 0;
13 - unsigned char sig[2];
14 + int verbose = 0, forced = 0, burn = 0, info = 0, all = 0, padtrack = 0;
15 + unsigned char sig[3];
21 if (argc < 2 ) /* If nothing is given */
23 - fprintf(stderr,"Mp3rename\n\nusage: [-vfhsbia] [file ...]\n\n");
24 + fprintf(stderr,"Mp3rename\n\nusage: [-vfhsbia] [file ...]\n\nUse 'mp3rename -h' for a usage summary\n\n");
29 /* Lets checkout the options */
31 - while ((ch = getopt(argc, argv, "vfhsbia")) != -1)
32 + while ((ch = getopt(argc, argv, "vfhsbiap")) != -1)
35 case 'v': /* Verbose mode */
37 case 'a': /* Ask everything */
43 default: /* If wrong option is given */
44 - fprintf(stderr,"Mp3rename\n\nusage: [-vfh] [file ...]\n\n");
45 + fprintf(stderr,"Mp3rename\n\nusage: [-vfhsbia] [file ...]\n\nUse 'mp3rename -h' for a usage summary\n\n");
50 strcat(filenamelook,".mp3"); /* add .mp3 so that the filename will be complete */
53 - char title[31]="", artist[31]="", album[31]="", year[5]="", comment[31]="", fbuf[4], newfilename[160]="",nieuw[150]="",dir[150]="",dirsource[200],fullline[228]="", burnname[29]="";
54 + char title[31]="", artist[31]="", album[31]="", year[5]="", comment[31]="", fbuf[4], newfilename[160]="",nieuw[150]="",dir[150]="",dirsource[200],fullline[228]="", burnname[29]="", track;
57 if ( !( fp=fopen(*argv,"rb+") ) ) /* If the file doesn exist */
59 /* Lets check if we have a real mp3 file */
61 fread(sig,sizeof(sig),1,fp);
63 + if(sig[0]!='I' || sig[1]!='D' || sig[2]!='3'){
66 if(!((sig[0] == 0xff) && (sig[1] == 0xf0)))
75 /* Lets go to the beginning of the tag */
76 if ( fseek(fp, -128, SEEK_END ))
78 fread(artist,1,30,fp); artist[30] = '\0';
79 fread(album,1,30,fp); album[30] = '\0';
80 fread(year,1,4,fp); year[4] = '\0';
81 - fread(comment,1,30,fp); comment[30] = '\0';
82 + fread(comment,1,30,fp);
83 + if (comment[28] == '\0' && comment[29] != '\0') {
84 + /* ID3v1.1 - specify track number in the last byte of comment field*/
85 + track = comment[29];
91 fseek(fp, -128, SEEK_END); /* back to the beginning of the tag */
95 printf("Artist : %s\n",artist);
96 printf("Title : %s\n",title);
99 + if(track < 10 && padtrack == 1)
101 + printf("Track : 0%i\n",track);
105 + printf("Track : %i\n",track);
108 printf("Album : %s\n",album);
109 printf("Year : %s\n\n",year);
111 @@ -297,31 +323,10 @@
114 /* Remove trailing spaces */
115 - i=strlen(artist)-1;
116 - while (i && artist[i]==' ')
123 - while (i && title[i]==' ')
129 - while (i && album[i]==' ')
135 - while (i && year[i]==' ')
140 + rtrim((char*)&artist);
141 + rtrim((char*)&title);
142 + rtrim((char*)&album);
143 + rtrim((char*)&year);
145 /* We go through the filenamelook until we find a &x combination
146 then we replace the &x with album/title/year/artis */
148 strcpy(newfilename,tmp);
152 + if(track < 10 && padtrack == 1)
154 + sprintf(tmp,"%s0%d",newfilename,track);
158 + sprintf(tmp,"%s%d",newfilename,track);
160 + strcpy(newfilename,tmp);
164 printf("Illegal char in config file please use the option '-s help' for more information\n");
168 /* Build the new tag from the new names */
170 - buildtag(fullline,title,artist,album,year,comment,genre);
171 - fwrite(fullline,1,128,fp);
173 + if ((forced) || (all))
175 + buildtag(fullline,title,artist,album,year,comment,genre);
176 + fwrite(fullline,1,128,fp);
180 /* Lets catch illegal characters */
185 +void rtrim(char* astring){
188 + i=strlen(astring)-1;
189 + while (i && astring[i]==' ')
196 void buildtag(char *buf, char *title, char *artist, char *album, char *year, char *comment, char *genre)
200 strncat(buf,album,30);
205 strncat(buf,comment,30);
206 strncat(buf,genre,1);
209 printf("\t-h\t Display this help message.\n");
210 printf("\t-b\t Limit the file size to 32 chars.\n");
211 printf("\t-i\t Only show the id3tags.\n");
212 + printf("\t-p\t Pad the track number with a leading zero when less than 10.\n");
213 printf("\t-a\t Ask everything for the id3tag.\n\n");
214 printf("\t-s\t Set the default filename look.\n");
215 printf("\t \t for more help on this option: -s help\n\n");
217 printf("Mp3rename 0.6\n\n");
218 printf(" Use this option to set the default look of the file\n");
219 printf(" The information is saved in ~/.mp3rename\n");
220 - printf(" You can use &t title, &b album, &y year and &a artist\n\n");
221 + printf(" You can use &t title, &b album, &y year, &k track and &a artist\n\n");
222 printf(" Example : mp3rename -s '(&a)-&t-&b'\n");
223 printf(" for (artist)-title-album.mp3\n\n");
225 --- mp3rename-0.6.orig/Makefile 2000-05-06 12:36:10.000000000 +0200
226 +++ mp3rename-0.6/Makefile 2007-05-17 04:29:18.000000000 +0200
231 +INSTALL = /bin/install
236 $(RM) -f $(OBJS) $(PROG) *~ *core
239 - $(INSTALL) -c mp3rename $(PREFIX)/bin/mp3rename
240 - $(INSTALL) -c mp3rename.1.gz $(PREFIX)/man/man1/
242 \ Kein Zeilenumbruch am Dateiende.
243 + $(INSTALL) -D mp3rename.1.gz $(PREFIX)/usr/share/man/man1/mp3rename.1.gz
244 + $(INSTALL) -D mp3rename $(PREFIX)/usr/bin/mp3rename
245 --- mp3rename-0.6.orig/mp3rename.1 1970-01-01 01:00:00.000000000 +0100
246 +++ mp3rename-0.6/mp3rename.1 2007-05-17 04:46:24.000000000 +0200
248 +.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.35.
249 +.TH MP3RENAME "1" "September 2005" "Debian GNU/Linux" "User Commands"
251 +Mp3rename \- Rename mp3 files based on id3tags
257 +Force non id3 rename.
263 +Display this help message.
266 +Limit the file size to 32 chars.
269 +Only show the id3tags.
272 +Pad the track number with a leading zero when less than 10.
275 +Ask everything for the id3tag.
278 +Set the default filename look.
279 +for more help on this option: \fB\-s\fR help
281 +Sander Janssen <janssen@rendo.dekooi.nl>
283 +Use this option to set the default look of the file
284 +The information is saved in ~/.mp3rename
285 +You can use &t title, &b album, &y year, &k track and &a artist
287 +Example : mp3rename \fB\-s\fR '(&a)\-&t\-&b'
288 +for (artist)\-title\-album.mp3