Plan 9 from Bell Labs’s /usr/web/sources/contrib/axel/music/mp3tag/lib.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include "mp3tag.h"

char* genres[] = {
	"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",
	"Alternative 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",
	"Top 40",
	"Christian Rap",
	"Pop/Funk",
	"Jungle",
	"Native US",
	"Cabaret",
	"New Wave",
	"Psychadelic",
	"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",
	"Rhytmic Soul",
	"Freestyle",
	"Duet",
	"Punk Rock",
	"Drum Solo",
	"Acapella",
	"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",
};

char*
readidv1(char* file, Idv1* idv1)
{
	int fd;
	char* err;

	fd = open(file, OREAD);
	if(fd < 0)
		return "open";
//	else
//		fprint(2, "mp3tag: opened %q\n", file);
	err = freadidv1(fd, idv1);
	close(fd);
	return err;
}

char*
freadidv1(int fd, Idv1* idv1)
{
	char buf[128];
	char* p;

	if(seek(fd, -128, 2) < 0) {
		print("seek: %r\n");
		return "seek";
	}

	if(read(fd, buf, 128) != 128)
		return "read";

	if(strncmp(buf, "TAG", 3) != 0)
		return "no tag";

	p = buf + strlen("TAG");

	memset(idv1, 0, sizeof (Idv1));
	memmove(idv1->title, p, 30);
	p += 30;
	memmove(idv1->artist, p, 30);
	p += 30;
	memmove(idv1->album, p, 30);
	p += 30;
	memmove(idv1->year, p, 4);
	p += 4;
	memmove(idv1->comment, p, 30);
	p += 30;
	idv1->genreid = (uint)*p;

	if(idv1->genreid >= 0 && idv1->genreid < nelem(genres))
		idv1->genre = genres[idv1->genreid];
	else
		idv1->genre = "";

	if(idv1->comment[28] == '\0' && idv1->comment[29] != '\0')
		idv1->track = (uint)idv1->comment[29];
	else
		idv1->track = -1;

	return nil;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.