/* this will print whatever mp3 song you're listening including the id3 tag * written by shudder */ #include #include #include #include #include #include #include #include #include #define PROC "/proc" void read_id3(char *); struct { char tag[3]; char title[30]; char artist[30]; char album[30]; char year[4]; char comment[30]; unsigned char genre; } id3; void read_id3(char *file) { int fd; if ((fd = open(file, O_RDONLY)) == -1) return; lseek(fd, -128, SEEK_END); read(fd, &id3, 128); printf("You are listening to: %s\n" "Title: %-30.30sArtist: %-30.30s\n" "Album: %-30.30sYear: %-4.4s\n" "Comment: %-28.28sTrack: %d\n", file, id3.title, id3.artist, id3.album, id3.year, id3.comment, id3.comment[29]); } int main(int argc, char *argv[]) { int l; char buffer[1024]; DIR *dp, *dp_fd; struct dirent *de, *de_fd; struct stat s; if (!(dp = opendir(PROC))) { fprintf(stderr, "%s: unable to open: %s\n", argv[0], PROC); return 1; } while ((de = readdir(dp))) { if (!atoi(de->d_name) || getpid() == atoi(de->d_name)) continue; sprintf(buffer, "%s/%d/fd", PROC, atoi(de->d_name)); if (!(dp_fd = opendir(buffer))) continue; chdir(buffer); while ((de_fd = readdir(dp_fd))) { lstat(de_fd->d_name, &s); if (S_ISLNK(s.st_mode)) { memset(buffer, 0, 1024); readlink(de_fd->d_name, buffer, 1024); /* check for .mp3 extension */ if ((l = strlen(buffer)) >= 5 && buffer[l-1] == '3' && tolower(buffer[l-2]) == 'p' && tolower(buffer[l-3]) == 'm' && buffer[l-4] == '.') read_id3(buffer); } } closedir(dp_fd); } closedir(dp); return 0; }